24205

Getting properties/parameters from page level

Question:

I wonder if I can get the parameters and/or properties of an xpage or custom control programmatically.

<xp:view xmlns:xp="http://www.ibm.com/xsp/core" id="layout"> <xp:this.properties> <xp:parameter name="testcc.xsp" value="Test 1"></xp:parameter> <xp:parameter name="index.xsp" value="Main"></xp:parameter> </xp:this.properties> ...

How can I access this parameter list to use it e.g. in a repeat control?

<strong>EDIT</strong> You both are right, thank you! But this works only on a page, not in a custom control.

<strong>EDIT</strong>

You both are great :-)

BUT: I should revise my question: I have a custom control where I defined the properties. Within the SAMe custom control I want to access these properties in a repeat control.

Both your answers seem to assume that the access to these properties is from the view (page) level, right?

I tested Svens way - this works if I access the props in the CC from the page level.

<strong>EDIT</strong>

So this is the code of the CC:

<?xml version="1.0" encoding="UTF-8"?> <xp:view xmlns:xp="http://www.ibm.com/xsp/core"> <xp:this.properties> <xp:parameter name="param" value="val"></xp:parameter> </xp:this.properties> <xp:label value="#{javascript:facesContext.getProperty('param')}" id="label1"> </xp:label> </xp:view>

As you can see I just want to access the property within the CC itselt, not from the page level.

Answer1:

You can get the properties by accessing <em>facesContext</em>:

facesContext.getProperty("index.xsp")

<strong>EDIT:</strong>

If you set the properties in a custom control, the properties are not added to the view root. The are set as attributes of the custom control (<em>com.ibm.xsp.component.UIIncludeComposite</em>).

To access them you first have to give your CC an Id:

<xc:ccProp id="myId" />

This allows you to access the custom control like a component with the <em>getComponent()</em> method and retrieve the attribute <em>properties</em> which contains the properties:

<xp:label id="labelProperty"> <xp:this.value><![CDATA[#{javascript: var cc:com.ibm.xsp.component.UIIncludeComposite = getComponent("myId"); var arrList:java.util.ArrayList = cc.getAttributes().get("properties"); arrList.get(0).getName()}]]> </xp:this.value> </xp:label>

<strong>EDIT 2:</strong>

You can access the CC (which is the parent of the label in this example) this way if you don't want to give your CC an ID:

<em>Code of the custom control:</em>

<?xml version="1.0" encoding="UTF-8"?> <xp:view xmlns:xp="http://www.ibm.com/xsp/core"> <xp:this.properties> <xp:parameter name="param" value="val"></xp:parameter> </xp:this.properties> <xp:label id="label1"> <xp:this.value><![CDATA[#{javascript: this.parent.getAttributes().get("properties").get(0).getName() }]]></xp:this.value> </xp:label> <xp:label id="label2"> <xp:this.value><![CDATA[#{javascript: this.parent.getAttributes().get("properties").get(0).getValue() }]]></xp:this.value> </xp:label> </xp:view>

Hope this helps to clarify the issue.

Answer2:

To get the property list you can use the view.getProperties(). It returns an object of java.util.List which you can use to loop through individual properties (which are objects of com.ibm.xsp.complex.Parameter). Below is the snippet.

var allProperties:java.util.List = view.getProperties(); for (var i=0 ; i<allProperties.size() ; i++) { var property:com.ibm.xsp.complex.Parameter = allProperties.get(i); // property.getName(); // property.getValue(); }

If you want to put it in a repeat then you can bind it to view.getProperties() and then get its individual values. You code would then look something like this:

<xp:repeat rows="30" value="#{javascript:view.getProperties()}" var="property"> <xp:text escape="true"> <xp:this.value><![CDATA[#{javascript:property.getName() + " - " + property.getValue();}]]></xp:this.value> </xp:text> <xp:br></xp:br> </xp:repeat>

Answer3:

If you've got values that you want to use on the various parts of an Xpage, whether directly on the page, in a custom control, or in a repeat, I would recommend that you put the values into sessionScope variables. This allows you to change them easily as the user enters information on the Xpage.

For example, sessionScope.PODocUNID = poDoc.getDocument().getUniversalID(); would put the UNID of the purchase order document that I'm working with into a sessionScope variable named PODocUNID. Then, you can pull up the value any time you want by simply referencing sessionScope.PODocUNID in your code.

Alternatively, you could use Russ Maher's current favorite toy, the Managed Bean (see his three-part video on Notes in 9, starting at: <a href="http://notesin9.com/index.php/2012/11/02/notesin9-084-sharing-managed-beans-in-xpages/" rel="nofollow">http://notesin9.com/index.php/2012/11/02/notesin9-084-sharing-managed-beans-in-xpages/</a> )

Recommend

  • Why number of Threads is more than 1 in C#
  • JSF 2 dynamic form and bean validation JSR 303
  • ExtendedDataTable in RichFaces 4: DataModel handling
  • FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()) returns null
  • PrimeFaces input components are not highlighted on validation error
  • Setting a path when creating a new File in Java
  • How to compare same PropertyInfo with different ReflectedType values?
  • Getting the new line character without System.getProperty(“line.separator”)?
  • Change Font Style (bold, Italic, bold italic) in C# [duplicate]
  • Using SQL stored function gives invalid SQL statement
  • Property file in java
  • How to prevent cross domain issues by proxying in IIS?
  • Performance difference between accessing local and class member variables
  • Access PCF DEV from external machine on same network as host
  • Monotouch crashes with NullReferenceException on non nullable object
  • how to solve invalid conversion specifier warning in iphone app
  • using html data-attributes as css-variable (i.e. text-shadow)
  • How to retrieve information from antrun back to maven?
  • Getting error 'Cannot read property 'document' of undefined' while importing exp
  • Hide HTML elements without javascript, only CSS
  • xcode don't localize specific strings
  • Not able to aggregate on nested fields in elasticsearch
  • ViewController With Transparent Background Entering Current ViewController With Push Transition
  • how to save the state in userdefaults of accessory checkmark-iphone
  • Swift: Switch statement fallthrough behavior
  • Database structure design with variable amounts of fields
  • java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder on below Lollipop versions
  • Fetching methods from BroadcastReceiver to update UI
  • How do I fake an specific browser client when using Java's Net library?
  • HTML download movie download link
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • How to get a value (ex: baseURL) in every Karate feature?
  • Updating server-side rendering client-side
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Symfony2: How to get request parameter
  • GridView Sorting works once only
  • WPF Applying a trigger on binding failure
  • How to set the response of a form post action to a iframe source?
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • Checking variable from a different class in C#