简体   繁体   English

有条件地要求以a4j格式进行jsf验证

[英]Conditionally required jsf validation in a4j form

I'm having a little problem with using conditionally evaluated expression in jsf/a4j 我在jsf / a4j中使用条件评估表达式有一个小问题

Here's my code 这是我的代码

<a4j:form>
         <h:inputText id="id1" value="#{mybean.myvalue}" size="1"
                   required="#{not mybean.condition}"
                   rendered="#{not mybean.condition}"
                   requiredMessage="Put a number in here" />

           <h:selectBooleanCheckbox value="#{mybean.condition}">
                <a4j:support event="onclick" reRender="id1"/>
            </h:selectBooleanCheckbox>

<a4j:commandButton action="#{mybean.myaction}" value="Do something" />

 </a4j:form>

The boolean checkbox conditionally enable/disable the validation. 布尔复选框有条件地启用/禁用验证。

This doesn't work: the a4j:commandButton simply skip the validation. 这不起作用:a4j:commandButton只是跳过了验证。

Thanks. 谢谢。

If the inputText fails validation (Process Validations phase), then the value mybean.condition will not be updated (Process Updates phase). 如果inputText验证失败(“过程验证”阶段),则不会更新值mybean.condition (“过程更新”阶段)。 Since the text field uses the required attribute, this is quite likely. 由于文本字段使用必填属性,因此很有可能。

Lifecycle from the RichFaces doc: RichFaces文档的生命周期:

替代文字
(source: jboss.org ) (来源: jboss.org

If any JSF phase fails, the lifecycle skips to Render Response to avoid operating on invalid input. 如果任何JSF阶段失败,则生命周期将跳至“渲染响应”,以避免对无效输入进行操作。 You can use the h:message and h:messages tags to view reported errors (though because you're using AJAX, you'll have to put them in something that will get re-rendered. 您可以使用h:messageh:messages标记来查看报告的错误(尽管由于使用的是AJAX,所以必须将它们放在可以重新呈现的内容中)。

I am guessing that if you set the ajaxSingle attribute on the aj4:support tag, you would get the behaviour you want. 我猜想,如果在aj4:support标记上设置ajaxSingle属性,您将获得想要的行为。 The documentation says that this will only submit the value for the control, so the text field will not be involved in the Apply Request Values/Process Validations/Process Updates phases. 该文档说,这将仅提交控件的值,因此该文本字段将不涉及“应用请求值/过程验证/过程更新”阶段。

What is the scope of mybean? 大豆的范围是多少? If it's request scope then its value will be reset when you click the button and the input field might be processed at all (if rendered resolves to 'false'). 如果是请求范围,则在您单击按钮时将重置其值,并且可能完全处理了输入字段(如果渲染解析为“ false”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM