我构建了一个复合组件,它接受一个输入ID并生成一个表。然后,我做它接受使用<f:viewParam>
GET参数的网页喜欢这样的:如何将GET参数传递给复合组件?
<f:metadata>
<f:viewParam name="id" value="#{aBean.id}" />
</f:metadata>
<util:aCompositeComponent inputId="#{aBean.id}" />
的复合材料部件的标记是:
<cc:interface componentType="compositeComponentBacking">
<cc:attribute name="inputId" type="java.lang.Integer" />
</cc:interface>
<cc:implementation>
/**
Use #{cc.result} to build a HTML table to present a result
**/
</cc:implementation>
和复合组件的支持bean是:
@FacesComponent("compositeComponentBacking")
public class CompositeComponentBacking extends UINamingContainer {
private Integer inputId;
public List<Result> getResult() {
//Use inputId to query service to return result
return result;
}
public Integer getInputId() {
return inputId;
}
public void getInputId(Integer inputId) {
this.inputId = inputId;
}
}
GET参数可以绑定到#{aBean.id}
,但#{aBean.id}
不能传递到复合组件,并且它始终在第e复合组件。我如何将GET参数传递给复合组件?
更新:
我终于解决.I发现,使用复合材料部件时,如果输入属性为恒定(例如<util:aCompositeComponent inputId="1"/>
),这个常数可以设置为CompositeComponentBacking
的问题inputId
字段。但如果我使用输入属性的复合是一个EL表达式(例如<util:aCompositeComponent inputId="#{aBean.id}"/>
,EL表达式的值不能设置为CompositeComponentBacking
的inputId
字段。我必须通过在CompositeComponentBacking
内部通过计算#{cc.attrs.inputId}
来获得该值。正常的行为?
当您在页面(组件外部)输出'#{aBean.id}'时,是否设置了值? – mabi
是的。 #{aBean.id}正确显示,如果我把它放在组件旁边,但在组合组件内部,它是空的。 –
显然你在合成内部访问/显示它是错误的。很难说,如果你没有在问题中表现出这一部分。 – BalusC