验证ViewParam和a4j:commandButton [英] Validation of ViewParam and a4j:commandButton

查看:67
本文介绍了验证ViewParam和a4j:commandButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我遇到了@ViewScopeda4j:commandButton的错误.

I think i came across a bug of @ViewScoped with a4j:commandButton.

我有一个非常复杂的表格,其中所有需要使用a4j的动作,除了那些需要上传数据的动作. 并且,根据命令的顺序,viewParam的验证也会中断.

I have a very complex form where all actions use a4j, except those that need to upload data. And depending on the order of the commands the validation of the viewParam breaks.

这是工作代码:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:a4j="http://richfaces.org/a4j" >

  <f:metadata>
    <f:viewParam id="viewParam" name="viewParam" value="#{bean.viewParam}" required="true" />
  </f:metadata>
  <h:head>
    <title>Test View Param</title>
  </h:head>
  <h:body>
    <h:message for="viewParam" />
    <hr/>
    <h:form>
      #{bean.viewParam}<br/>
      <h:commandButton value="cmdButton" />
      <a4j:commandButton value="a4jBtn" execute="@this" render="@form" />
    </h:form>  
  </h:body>
</html>

只需单击a4jBtn,然后单击cmdButton即可查看问题. 您会看到该参数仍然存在!但是验证失败.

just click on the a4jBtn and then on the cmdButton to see the problem. you will see that the parameter is still there! but that the validation fails.

<t:saveState>没有帮助, <rich:message>也不是更好,但是

<t:saveState> does not help, <rich:message> is also not better, but

<h:commandButton value="ajaxBtn" ><f:ajax execute="@this" render="@form" /></h:commandButton>

代替

<a4j:commandButton value="a4jBtn" execute="@this" render="@form" />

工作正常!

在Tomcat 6.0.18和jboss-el 2.0.0.GA上使用myFaces 2.0.15和richFaces 4.2.3.Final.

Using myFaces 2.0.15 and richFaces 4.2.3.Final on Tomcat 6.0.18 and jboss-el 2.0.0.GA.

我可以通过使用f:ajax而不是a4j:commandButton解决问题,但是也许您有更好的主意,或者您可以向我解释出了什么问题?

i could workaround my problem by using f:ajax instead of a4j:commandButton, but maybe you have a better idea, or you could just explain to me what is going wrong?

推荐答案

您基本上需要在同步回发中保留视图参数.在使用OmniFaces时,可以为此使用 <o:form> .

You basically need to retain the view parameters on synchronous postbacks. As you're using OmniFaces, you could use <o:form> for that.

<o:form includeViewParams="true">

或者因为您已经在使用视图作用域的bean,所以仅在非回发时触发验证.

Or as you're already using a view scoped bean, trigger the validation only on non-postbacks.

<f:viewParam ... required="#{not facesContext.postback}" />

或者,当您使用OmniFaces时,可以使用 <o:viewParam> 来代替验证/转换/更新回发.

Or, as you're using OmniFaces, you could use <o:viewParam> instead which skips the validation/conversion/update on postbacks.

<o:viewParam ... />

这篇关于验证ViewParam和a4j:commandButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆