【发布时间】:2013-04-15 18:43:34
【问题描述】:
我已经设法让代码按照我的意图进行,但我不明白为什么它有效的特定方面。我正在使用 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>
...
backing bean 只是一个简单的 POJO,其中包含三个属性的 getter 和 setter。 (myRadioButton, rowCountPredefined, rowCountSpecified)
这是我得到的:(正确的结果)
radio button example http://katzekat.de/Bilder/radio2.png
radio button example http://katzekat.de/Bilder/radio.png
这是我的想法:
将 ajaxSingle 设置为 true 意味着服务器上只会处理单选按钮。它旁边的下拉列表不需要验证 - 它始终包含正确的值。我添加了 process="myDropdown" 以便将值持久保存到支持 bean 中,否则当我将单选按钮切换到位置 2 时,下拉菜单将恢复为原始值。 (我意识到这只是装饰性的!)我已经用调试器检查了这个,它确实在支持 bean 中设置了属性,并且一切都按预期工作。
一旦单选按钮切换到位置 2,就可以在文本框中输入一个值并进行验证。这非常有效,当我将单选按钮切换回位置 1 时,如果该字段处于错误状态,验证错误将被清除。大概是因为错误信息只存在于请求范围内。
当单选按钮位于位置 2 并在文本字段中输入有效值时再次启动调试器,显示切换回位置 1 时支持 bean 没有更新。我也预料到了这一点,因为我只告诉无线电和要在服务器上处理的下拉列表。这是我不明白的一点 - 文本字段中的值 is 在回发时仍然存在。 (请参阅上面的第二个链接)如果不在支持 bean 中,此文本字段的此值保存在哪里?
【问题讨论】:
-
如果图像没有消失,这个问题可能会更有用! :)
-
他们回来了 - 正在更换主机 :-)
-
澳洲新闻网!我在研究 JSF 生命周期问题时发现了您的问题。我想问题/答案对我帮助不大,但这是一个写得很好的问题。 FWIW,我发现这个 ooold 页面非常有用:balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html您可能已经找到它,或者现在可能已经非常了解 JSF 生命周期,但它对我帮助很大。