在操作(命令按钮)之前触发preRenderView-Event [英] preRenderView-Event triggered before an action (commandbutton)
问题描述
我的preRenderView-Event有点麻烦.我的页面还使用CommandButton提交数据,但不幸的是,总是在调用button动作之前调用preRenderView-Event.
I am in a little bit of trouble with my preRenderView-Event. My page also uses a commandbutton to submit data but unfortunately the preRenderView-Event is always called before the buttons action is invoked.
preRenderView-Event负责从服务加载数据.由于页面很简单,不需要存储任何数据,因此我不需要任何Session或ViewScoped-Beans.
The preRenderView-Event is responsible for loading data from a service. Since the page is simple and doesnt have to store any data I dont need any Session or ViewScoped-Beans.
据我了解,该事件是在渲染-响应-阶段"中调用的,并且按钮中的操作应该更早发生.
As far as I understood the event is called in the Render-Response-Phase and the action in the button should happen somewhat earlier.
<h:body>
<f:metadata>
<f:viewParam name="id" value="#{bean.id}" converter="converter.SetOfLongConverter"/>
<f:event type="preRenderView" listener="#{bean.initializeData}" />
</f:metadata>
<ui:composition template="/META-INF/templates/myTemplate.xhtml">
<ui:param name="title" value="#{bean.title}"/>
<ui:define name="content">
<h:outputText value="#{bean.description}" />
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Model" for="model" />
<h:inputText id="model" value="#{bean.model}" />
<h:outputLabel value="Manufacturer" for="manufacturer" />
<h:inputText id="manufacturer"
value="#{bean.manufacturer}" />
<h:outputLabel value="Year" for="year" />
<h:inputText id="year" value="#{bean.year}" />
</h:panelGrid>
<h:commandButton value="Create" type="submit" action="#{bean.create}" rendered="#{bean.createMode}"/>
<h:commandButton value="Save" type="submit" action="#{bean.save}" rendered="#{!bean.createMode}" />
</h:form>
</ui:define>
</ui:composition>
</h:body>
我添加了一些控制台消息,以验证何时调用Bean中的方法以及何时拥有preRenderView事件,该事件永远不会发生.
I added some Console-Messages to verify when the method in the bean is called and when I have the preRenderView-event it never happens.
任何建议我在这里做错了吗?
Any advice what I am doing wrong here?
推荐答案
<f:metadata>
必须放在<ui:composition>
的<ui:define>
内部.
另请参见 <f:metadata>
标记文档(重点是我的):
See also <f:metadata>
tag documentation (emphasis mine):
声明此视图的元数据构面.这必须是
<f:view>
的子级. 此标记必须驻留在给定viewId的顶级XHTML文件中,或者驻留在模板客户端中,但不能驻留在模板中.实现必须确保构面的直接子级是UIPanel,甚至如果该方面只有一个孩子.实现必须将UIPanel的ID设置为UIViewRoot.METADATA_FACET_NAME
符号常量的值.
Declare the metadata facet for this view. This must be a child of the
<f:view>
. This tag must reside within the top level XHTML file for the given viewId, or in a template client, but not in a template. The implementation must insure that the direct child of the facet is a UIPanel, even if there is only one child of the facet. The implementation must set the id of the UIPanel to be the value of theUIViewRoot.METADATA_FACET_NAME
symbolic constant.
简单的原因是因为元数据应该是特定于视图的,而不是特定于模板的.
The simple reason is because the metadata is supposed to be view-specific, not template-specific.
更新:事实证明根本没有调用该操作方法.您在命令按钮上有一个rendered
属性,该属性似乎根据症状取决于基于请求的变量而不是基于视图的变量.将托管bean放入视图范围应该可以解决此问题.另请参见 commandButton/commandLink/ajax action/listener方法未调用或输入值未更新
Update: it turns out that the action method is not invoked at all. You've there a rendered
attribute on the command button which seems according the symptoms to be dependent on a request based variable instead of a view based variable. Putting the managed bean in the view scope should fix this problem. See also commandButton/commandLink/ajax action/listener method not invoked or input value not updated
这篇关于在操作(命令按钮)之前触发preRenderView-Event的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!