Richfaces和JSF / AJAX生命周期(Richfaces and JSF/AJAX Lifecycles)

编程入门 行业动态 更新时间:2024-10-19 19:46:10
Richfaces和JSF / AJAX生命周期(Richfaces and JSF/AJAX Lifecycles)

我设法让代码按照我的意图去做,但我不明白为什么这样做有特定的方面。 我使用Richfaces 3.3.3运行Seam 2.2.2。

以下是xhtml页面中的代码:

... <h:form id="radiobuttontestform"> <fieldset> <h:panelGrid columns="3"> <h:selectOneRadio layout="pageDirection" id="myRadio" value="#{actionBean.myRadioButton}"> <f:selectItem itemLabel="First" itemValue="0" /> <f:selectItem itemLabel="Second" itemValue="1" /> <a4j:support event="onclick" ajaxSingle="true" process="myDropdown" reRender="myDropdown,myCount,test" /> </h:selectOneRadio> <h:panelGrid columns="1" border="0"> <h:selectOneListbox size="1" id="myDropdown" value="#{actionBean.rowCountPredefined}" disabled="#{actionBean.myRadioButton != '0'}"> <f:selectItem itemLabel="10" itemValue="10" /> <f:selectItem itemLabel="20" itemValue="20" /> <f:selectItem itemLabel="30" itemValue="30" /> </h:selectOneListbox> <h:inputText id="myCount" maxlength="5" value="#{actionBean.rowCountSpecified}" disabled="#{actionBean.myRadioButton != '1'}" required="true"> <f:validateLongRange minimum="1" maximum="1000" /> <rich:ajaxValidator event="onkeyup" for="myCount" /> </h:inputText> <rich:message id="errorMessage" for="myCount" ajaxRendered="true" showDetail="false" showSummary="true"> <f:facet name="errorMarker">ERROR:</f:facet> </rich:message> </h:panelGrid> </h:panelGrid> </fieldset> <h:outputLabel id="test" value="RadioValue: #{actionBean.myRadioButton}" /> <a4j:commandButton id="show" value="Show Values in Log" action="#{actionBean.showValues}" /> <a4j:commandButton id="done" value="Save and end conversation" action="#{actionBean.apply}" /> </h:form> ...

支持bean只是一个简单的POJO,其中包含三个属性的getter和setter。 (myRadioButton,rowCountPredefined,rowCountSpecified)

这就是我得到的:(正确的结果)

单选按钮示例http://katzekat.de/Bilder/radio2.png

单选按钮示例http://katzekat.de/Bilder/radio.png

这是我的想法:

将ajaxSingle设置为true意味着只在服务器上处理单选按钮。 它旁边的下拉列表不需要验证 - 它将始终包含正确的值。 我添加了process =“myDropdown”以便将值保存到backing bean中,否则当我将单选按钮切换到位置2时,下拉列表将恢复为其原始值。 (我意识到这只是化妆品!)我已经用调试器检查了它,它确实在支持bean中设置了属性,一切都按预期工作。

单选按钮切换到位置2后,可以在文本框中输入值并进行验证。 这非常有效,当我将单选按钮切换回位置1时,如果此字段处于错误状态,则清除验证错误。 大概是因为错误消息仅出现在请求范围中。

当单选按钮位于位置2并在文本字段中输入有效值时再次启动调试器,当切换回位置1时,后备bean上没有更新。我也期望这是因为我只告诉收音机和下拉到服务器上的进程。 这是我不明白的一点 - 文本字段中的值保留在回发上。 (请参阅上面的第二个链接)如果不在辅助bean中,此文本字段的值保存在何处?

I´ve managed to get the code to do what I intended, but I do not understand a particular aspect of why this works. I´m running Seam 2.2.2 with Richfaces 3.3.3.

Here is the code from the xhtml page:

... <h:form id="radiobuttontestform"> <fieldset> <h:panelGrid columns="3"> <h:selectOneRadio layout="pageDirection" id="myRadio" value="#{actionBean.myRadioButton}"> <f:selectItem itemLabel="First" itemValue="0" /> <f:selectItem itemLabel="Second" itemValue="1" /> <a4j:support event="onclick" ajaxSingle="true" process="myDropdown" reRender="myDropdown,myCount,test" /> </h:selectOneRadio> <h:panelGrid columns="1" border="0"> <h:selectOneListbox size="1" id="myDropdown" value="#{actionBean.rowCountPredefined}" disabled="#{actionBean.myRadioButton != '0'}"> <f:selectItem itemLabel="10" itemValue="10" /> <f:selectItem itemLabel="20" itemValue="20" /> <f:selectItem itemLabel="30" itemValue="30" /> </h:selectOneListbox> <h:inputText id="myCount" maxlength="5" value="#{actionBean.rowCountSpecified}" disabled="#{actionBean.myRadioButton != '1'}" required="true"> <f:validateLongRange minimum="1" maximum="1000" /> <rich:ajaxValidator event="onkeyup" for="myCount" /> </h:inputText> <rich:message id="errorMessage" for="myCount" ajaxRendered="true" showDetail="false" showSummary="true"> <f:facet name="errorMarker">ERROR:</f:facet> </rich:message> </h:panelGrid> </h:panelGrid> </fieldset> <h:outputLabel id="test" value="RadioValue: #{actionBean.myRadioButton}" /> <a4j:commandButton id="show" value="Show Values in Log" action="#{actionBean.showValues}" /> <a4j:commandButton id="done" value="Save and end conversation" action="#{actionBean.apply}" /> </h:form> ...

The backing bean is just a simple POJO with getters and setters for the three properties here. (myRadioButton, rowCountPredefined, rowCountSpecified)

This is what I get: (the correct result)

radio button example http://katzekat.de/Bilder/radio2.png

radio button example http://katzekat.de/Bilder/radio.png

Here is my thinking:

Setting ajaxSingle to true means that only the radio button will be processed on the server. The dropdown next to it doesn´t need validation - it will always contain a correct value. I´ve added the process="myDropdown" in order to persist the value into the backing bean, otherwise when I switch the radio button to position 2 the dropdown reverts to its original value. (I realise this is only cosmetic!) I´ve checked this with a debugger and it does indeed set the property in the backing bean and everything is working as expected.

Once the radio button is switched into position 2 a value can be entered in the textbox and will be validated. This works perfectly, and when I switch the radio button back to position 1, the validation error is cleared if this field is in an error state. Presumably because the error message is only present in the request scope.

Firing up the debugger again when the radio button is in position 2 and entering a valid value in the text field reveals no update on the backing bean when switching back to position 1. I also expected this as I´m telling only the radio and the dropdown to process on the server. This is the bit I don´t understand though - the value in the textfield is persisted on postback. (See 2nd link above) Where is this value for this textfield saved if not in the backing bean ?

最满意答案

提交的表单值存储在“ Apply Request Values阶段的组件中。

例如,在您的情况下, javax.faces.component.html.HtmlInputText#decode javax.faces.component.UIInput#setSubmittedValue方法调用javax.faces.component.UIInput#setSubmittedValue 。 提交的值未设置为bean(如您所期望的那样),因为未包含该组件以execute part。 然后inputText的渲染器重新显示(写入响应)提交的值。

验证失败时,它的工作原理基本相同。 提交的值存储在“ Apply Request Values阶段,然后由于验证失败,提交的值未设置为Bean(跳过Update Model Values阶段),然后重新显示提交的值。

Submitted form values are stored in component on Apply Request Values phase.

For example in your case javax.faces.component.html.HtmlInputText#decode method of the textfield calls javax.faces.component.UIInput#setSubmittedValue. The submitted values are not set to the bean (as you expected) as the component is not included to execute part. Then inputText's renderer re-displays (writes to the response) the submitted values.

It works pretty the same when validation fails. Submitted values are stored on Apply Request Values phase, and then because of failed validation the submitted values are not set to beans (Update Model Values phase is skipped), then the submitted values are re-displayed.

更多推荐

value,bean,radio,电脑培训,计算机培训,IT培训"/> <meta name="description&

本文发布于:2023-07-31 01:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340511.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:生命周期   JSF   Richfaces   Lifecycles   AJAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!