问题
-xhtml File
I cannot accsses the passed Parameter
<ui:insert>
<ui:include src="#{PopUpBean.includeUrl}">
<ui:param name="includeParam" id="includeParam" value="HalloWert!" />
</ui:include>
</ui:insert>
Thats the way i tried to accses the parameters, i have lookedup every variable with help of the debugger, but it seems as if the ui:param value isn't passed:
private void init () {
FacesContext ctx = FacesContext.getCurrentInstance();
ExternalContext ectx = ctx.getExternalContext();
Object o = ectx.getRequestParameterMap().get("includeParam");
Object request = ectx.getRequest();
}
@PostConstruct
public void postContruction () {
this.init();
}
Thank you for help!
回答1:
Found a Solution;
HtmlOutputLabel ob = (HtmlOutputLabel) UiTreeWalker.findComponent(FacesContext.getCurrentInstance().getViewRoot(), "hiddenValue");
ValueExpression vb = ob.getValueExpression("value");
Object value = vb.getValue(FacesContext.getCurrentInstance().getELContext());
Hidden Value is a outputLabel with rendered = false
The idea behind this is that you can put the parameter in a hidden value on your JSF page, and then you can access that parameter from this java snippet.
回答2:
I found another way to send information, from UI:Include to Bean in JSF 2.2. By setting a hidden value and reference a method in the bean. for instance:
<ui:include src="/toInclude.xhtml">
<ui:param name="idValue"
value="#{masterBean.idValue}" />
</ui:include>
Don't needed to use: at the intitial line in this file. This hidden parameter will be put at first, that will be setting in the bean in order. And in the toInclude.xhtml will be:
<h:inputHidden id="idValue"
value="#{toIncludeBean.putIdValue(idValue)}" />
in the Bean:
@Named(value = "toIncludeBean")
@Scope("view")
public class ToIncludeBean {
private String value;
public void putIdValue(String idValue) {
//This is in my bean
this.setValue(idValue);
}
}
来源:https://stackoverflow.com/questions/5394304/passing-values-with-uiparam-and-access-them-in-backing-bean