wrs*_*der 7 validation ajax jsf
我有一个h:commandLink调用方法来改变绑定到无线电输入的属性.
我还在同一个表单上有一个文本输入,带有一些验证(required = true).
如果我离开了文本输入栏,并点击h:commandLink同execute="@this,从模型属性如预期,因为文字输入从未处理和验证永远不会触发单选按钮更新.
但是,如果一开始我点击一个不同的h:commandLink与execute="@form",然后与链接execute="@this",确认消息消失,但单选按钮值也不会离即使UIInput单选按钮从未处于无效状态的模型更新.
我发现它的execute="@this"行为方式有所不同,这取决于我以前做过的事情,当我的意图@this是迫使所有内容从模型更新并忽略组件中提交的任何值时.
我怀疑发生的事情是这样的:
@form,单选按钮和文本都被处理.localValue设置localValue保持设置状态并且不会被清除或传播到valueresetValue()或重新处理有问题的组件(例如,execute="@this radio")以清除localValue然后允许从bean刷新.我的问题是:
感觉这可能只是这个问题的另一个例子
在验证错误发生后,如何使用PrimeFaces AJAX填充文本字段?
不幸的是,我觉得我最近发现了很多这些.:-(
代码示例如下:
<h:form>
<h:messages/>
Radio =
<h:selectOneRadio value="#{testBean.radioValue}" id="radio" binding="#{radio}">
<f:selectItem itemValue="foo" itemLabel="Foo"/>
<f:selectItem itemValue="bar" itemLabel="Bar"/>
</h:selectOneRadio>
<br></br>
radio bean value = <h:outputText value="#{testBean.radioValue}"/>
<br></br>
radio UIInput localValue = <h:outputText value="#{radio.localValue}"/>
<br></br>
radio UIInput value = <h:outputText value="#{radio.value}"/>
<br></br>
String w/validation = <h:inputText value="#{testBean.stringValue}" required="true" />
<br></br>
<ul>
<li>
<h:commandLink actionListener="#{testBean.changeRadioValue}" value="execute = @form">
<f:ajax render="@form" execute="@form"/>
</h:commandLink>
</li>
<li>
<h:commandLink actionListener="#{testBean.changeRadioValue}" value="execute = @this">
<f:ajax render="@form" execute="@this"/>
</h:commandLink>
</li>
<li>
<h:commandLink actionListener="#{testBean.changeRadioValue}" value="execute = @this radio">
<f:ajax render="@form" execute="@this radio"/>
</h:commandLink>
</li>
</ul>
</h:form>
Run Code Online (Sandbox Code Playgroud)
这豆子:
@ManagedBean
@ViewScoped
public class TestBean {
private String radioValue = "foo";
private String stringValue;
public void changeRadioValue() {
radioValue = "bar";
}
// + getters/setters
}
Run Code Online (Sandbox Code Playgroud)
我对生命周期的理解是否正确?
是.
我做错了什么,或者这是关于JSF的烦人设计事情之一?
这是JSF的"烦人的设计之物"之一.正如我在该相关问题的答案中所述:
回到具体问题,我想这是JSF2规范中的一个疏忽.当JSF规范强制要求时,JSF开发人员会更有意义:
- 当JSF需要通过ajax请求更新/重新呈现输入组件,并且该输入组件未包含在ajax请求的进程/执行中时,JSF应该重置输入组件的值.
如果我曾经针对JSF规范报告这个问题,我就不会再记得了.编辑:我报告了它:JSF规范问题1060.