本文介绍了JSF AJAX验证:执行=" @这个"渲染=" @形式QUOT;不一致根据之前的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 H:。commandLink 的调用方法更改绑定到无线输入属性方法

我也有同样的窗体上的文本输入一些验证(需要= TRUE)。

如果我离开了文字输入栏,然后点击 H:commandLink 执行=@这个,从模型属性的单选按钮更新如预期,因为文字输入从未处理和验证永远不会触发。

不过,如果一开始我点击一个不同的 H:commandLink 执行=@表然后的与执行=@这个,验证消息消失,但单选按钮值做的没有的更新从模型即使UIInput单选按钮从来没有在无效状态。

我发现它烦人的执行=@这个的行为不同,这取决于我做了什么previously,当我的意图与 @this 是迫使一切从模型进行更新,而忽略从组件的任何提交的值。

我怀疑发生的事情是这样的:

  • @form ,单选按钮和文本都被处理。
  • 单选按钮是否有效,以便 localValue 设置
  • 工艺验证阶段失败的整体,因为无效的文本输入,因此 localValue 保持置没有得到清除或传播到
  • 的唯一出路,这是显式调用 resetValue()或重新处理有问题的部件(例如,执行= @this电台)来清除 localValue ,然后允许豆刷新。

我的问题是:

  • 是我的生命周期是否正确?
  • 的理解
  • 在我做得不对,或者是这个恼人的,设计的东西关于JSF?

这感觉就像这可能只是这个问题的另一个例子

How我可以填充使用primefaces文本字段阿贾克斯之后发生的验证错误?

不幸的是我觉得我找到很多那些最近。 : - (

低于code例如:

 < H:形式GT;
< H:邮件/>

无线电=
< H:selectOneRadio值=#{testBean.radioValue}ID =无线电绑定=#{}电台>
    < F:选择信息itemValue =富itemLabel =富/>
    < F:选择信息itemValue =酒吧itemLabel =酒吧/>
< / H:selectOneRadio>

< BR>< / BR>
无线电豆值=< H:的outputText值=#{testBean.radioValue}/>
< BR>< / BR>
无线电UIInput localValue =< H:的outputText值=#{radio.localValue}/>
< BR>< / BR>
UIInput广播值=< H:的outputText值=#{radio.value}/>

< BR>< / BR>

字符串瓦特/验证=< H:inputText的值=#{testBean.stringValue}要求=真/>

< BR>< / BR>

< UL>
<李>
< H:commandLink的ActionListener =#{testBean.changeRadioValue}值=执行= @form>
    < F:AJAX渲染=@表执行=@形式/>
< / H:commandLink>
< /李>

<李>
< H:commandLink的ActionListener =#{testBean.changeRadioValue}值=执行= @this>
    < F:AJAX渲染=@表执行=@这个/>
< / H:commandLink>
< /李>

    <李>
< H:commandLink的ActionListener =#{testBean.changeRadioValue}值=执行= @this电台>
    < F:AJAX渲染=@表执行=@这个电台/>
< / H:commandLink>
< /李>
< / UL>

< /小时:形式GT;
 

和这个bean:

  @ManagedBean
@ViewScoped
公共类testBean这个{

私人字符串radioValue =富;
私人字符串stringValue的;

公共无效changeRadioValue(){
    radioValue =酒吧;
}
 // + getter / setter方法
 }
 

解决方案

是的。


这是的恼人被设计的东西JSF之一。作为上相关的问题陈述我的回答是:

我只是不记得了,如果我曾经这样报道对JSF规范。编辑:我报道它: JSF规范问题1060

I have an h:commandLink that calls a method that changes a property bound to a radio input.

I also have a text input on the same form with some validation (required=true).

If I leave the text input blank, and click on h:commandLink with execute="@this, the radio button updates from the model property as expected, because the text input is never processed and validation never fires.

However, if first I click on a different h:commandLink with execute="@form", then the link with execute="@this", the validation messages go away but the radio button value does not update from the model even though the UIInput for the radio button was never in an invalid state.

I'm finding it annoying that the execute="@this" behaves differently depending on what I had done previously, when my intent with @this was to force everything to update from the model and ignore any submitted values from the components.

I suspect what's happening is something like this:

  • with @form, radio button and text are both processed.
  • Radio button is valid so localValue is set
  • Process validations phase fails overall because of invalid text input, so localValue remains set and does not get cleared or propagate to value
  • the only way out of this is to explicitly call resetValue() or to re-process the component in question (e.g., execute="@this radio") to clear out localValue and then allow refreshing from bean.

My questions are:

  • is my understanding of the lifecycle correct?
  • Am I doing something wrong, or is this one of the annoying-by design things about JSF?

It feels like this may just be another example of this question

How can I populate a text field using primefaces ajax after validation errors occur?

Unfortunately I feel like I'm finding lots of those lately. :-(

Code example below:

<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>

And this bean:

@ManagedBean
@ViewScoped
public class TestBean {

private String radioValue = "foo";
private String stringValue;

public void changeRadioValue() {
    radioValue = "bar";
}
 // + getters/setters
 }
解决方案

Yes.


It's one of the "annoying by-design things" of JSF. As stated in my answer on that related question:

I only don't remember anymore if I have ever reported this against JSF spec. Edit: I reported it: JSF spec issue 1060.

这篇关于JSF AJAX验证:执行=&QUOT; @这个&QUOT;渲染=&QUOT; @形式QUOT;不一致根据之前的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 02:31