PF 3.5.10、Mojarra 2.1.21、Omnifaces 1.5
在加载 .xhtml JSF 页面之前,如何调用某些 (CDI)SessionScoped bean 的特殊 init() 方法?现在,如果用户从站点菜单(使用 )中选择页面,我会调用 init( p:menutitem
)。但是如果用户使用浏览器地址行直接输入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 的解决方案,正如评论中所说,Omnifaces 1.6 也将具有 ViewScope。