[英]Passing values with ui:param and access them in Backing bean
<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: 那就是我尝试访问参数的方式,我已经在调试器的帮助下查找了每个变量,但是好像ui:param值未传递:
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! 谢谢你的帮助!
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 隐藏值是带有render = false的outputLabel
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. 其背后的想法是,您可以将参数放在JSF页面上的隐藏值中,然后可以从此Java代码段访问该参数。
I found another way to send information, from UI:Include to Bean in JSF 2.2. 我发现了另一种从UI:Include向JSF 2.2中的Bean发送信息的方法。 By setting a hidden value and reference a method in the bean.
通过设置一个隐藏值并在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.
该隐藏参数将首先放置,将按顺序在Bean中进行设置。 And in the toInclude.xhtml will be:
并且在toInclude.xhtml中将是:
<h:inputHidden id="idValue"
value="#{toIncludeBean.putIdValue(idValue)}" />
in the Bean: 在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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.