【发布时间】:2013-08-31 16:48:17
【问题描述】:
PF 3.5.10、Mojarra 2.1.21、Omnifaces 1.5
如何在加载 .xhtml JSF 页面之前调用某些 (CDI)SessionScoped bean 的特殊 init() 方法?如果用户从站点菜单中选择页面(使用p:menutitem),现在我调用 init()。但是如果用户使用浏览器地址行直接输入url怎么办?
编辑:my.xhtml:
<ui:define template="/mytemp.xhtml">
<f:event type="preRenderView" listener="#{mybean.init()}" />
<h:form>
<p:commandButton update="@form" ... />
</h:form>
</ui:define>
如果我这样做,init() 将在每次更新时调用(即每次回发到服务器时),例如每次单击命令按钮时。所以我不能使用你的提议。
编辑 2:谢谢 Luiggi Mendoza 和 BalusC! 除了 Luiggi Mendoza 的解决方案,正如 cmets 所述,Omnifaces 1.6 也将具有 ViewScope。
【问题讨论】: