从页面级别获取属性/参数 [英] Getting properties/parameters from page level
问题描述
我想知道是否可以通过编程方式获取 xpage 或自定义控件的参数和/或属性.
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?
编辑两位说的都对,谢谢!但这仅适用于页面,不适用于自定义控件.
EDIT You both are right, thank you! But this works only on a page, not in a custom control.
编辑
你们都很棒:-)
但是:我应该修改我的问题:我有一个自定义控件,我在其中定义了属性.在 SAMe 自定义控件中,我想在重复控件中访问这些属性.
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?
我测试了 Svens 方式 - 如果我从页面级别访问 CC 中的道具,这会起作用.
I tested Svens way - this works if I access the props in the CC from the page level.
编辑
这是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>
如您所见,我只想访问 CC 本身中的属性,而不是从页面级别访问.
As you can see I just want to access the property within the CC itselt, not from the page level.
推荐答案
您可以通过访问 facesContext 来获取属性:
You can get the properties by accessing facesContext:
facesContext.getProperty("index.xsp")
如果您在自定义控件中设置属性,则属性不会添加到视图根中.它们被设置为自定义控件 (com.ibm.xsp.component.UIIncludeComposite) 的属性.
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 (com.ibm.xsp.component.UIIncludeComposite).
要访问它们,您首先必须给您的 CC 一个 ID:
To access them you first have to give your CC an Id:
<xc:ccProp id="myId" />
这允许您像使用 getComponent() 方法的组件一样访问自定义控件,并检索包含属性的 properties 属性:
This allows you to access the custom control like a component with the getComponent() method and retrieve the attribute properties 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>
编辑 2:
如果您不想给您的 CC 一个 ID,您可以通过这种方式访问 CC(在本例中是标签的父级):
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:
自定义控件代码:
<?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.
这篇关于从页面级别获取属性/参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!