【发布时间】:2013-01-05 18:14:23
【问题描述】:
我正在将参数p1 传递到另一个页面page.xhtml:
<ui:include src="page.xhtml">
<ui:param name="p1" value="#{someObject}"/>
</ui:include>
这是否可以在 page.xhtml 的支持 bean 的 @PostConstruct 方法内评估 #{p1}?使用以下代码,#{p1} 无法解析:
FacesContext currentInstance = FacesContext.getCurrentInstance();
currentInstance.getApplication().evaluateExpressionGet(currentInstance, "#{p1}", String.class);
我为什么需要这个?
我使用 xhtml 文件(比如 component.xhtml)作为自定义 UI 组件。这个文件有一个支持 bean,我应该从中获取组件数据。由于我在我的主 JSF 页面中包含此 xhtml 文件两次或更多次,因此我想将不同的对象传递给每个 component.xhtml,以便我的组件每次都使用我的自定义数据。
【问题讨论】:
-
这段代码位于哪个backing bean方法中?
-
更新了我的问题:@PostConstruct 方法。
-
这可能是个问题。 @PostConstruct 方法可以在页面构建之前执行。尝试为
preRenderView定义f:event,看看是否解决。 -
听起来很奇怪! preRenderView/preRenderComponent 监听器未在包含页面中调用。
-
似乎
preRenderView在包含的页面中不起作用。见:stackoverflow.com/questions/12543405/…
标签: jsf-2 parameters el