【问题标题】:error with h:commandButton and ajaxh:commandButton 和 ajax 出错
【发布时间】:2013-11-28 21:45:44
【问题描述】:

我的页面上有:

<h:form id="qw">
    <h:panelGrid columns="3" >
           <h:outputLabel for="username" value="Login:"/>
           <h:inputText id="username" value="#{userManager.userName}" required="true">
              <f:ajax event="blur" render="usernameMessage"/>
           </h:inputText>
           <h:message id="usernameMessage" for="username" />

           <h:outputLabel for="password" value="#{msg.password}"/>
           <h:inputSecret id="password" value="#{userManager.password}" required="true">
              <f:ajax event="blur" render="passwordMessage" />
            </h:inputSecret>
            <h:message id="passwordMessage" for="password" />

           <h:commandButton value="#{msg.login}" action="#{userManager.login}">
              <f:ajax execute="@form" render=" @form qw usernameMessage passwordMessage messages"/>
           </h:commandButton> 
       </h:panelGrid>
   </h:form>

   <h:messages id="messages" globalOnly="true"/>

当我运行应用程序并单击“登录”按钮时,我收到此错误:

Error Message: Request failed with status 0 and reason 

--------------------------------------------------------
Calling function:myfaces._impl.xhrCore._AjaxRequest
Error Name: httpError

这是什么意思?怎么了?我不能在 Ajax 中使用 h:commandButton?

【问题讨论】:

    标签: ajax jsf jsf-2 commandbutton


    【解决方案1】:

    使用 JSF2 时 xhtml 看起来不错。您打开一个表单,使用输入字段、消息和一个 ajaxified commandButton。您可以跳过重新渲染 qwusernameMessagepasswordMessage - 它们已经是 @form 的一部分。

    h:messages 在表格之外,应该没有任何伤害。可能这是 myFaces 实现的一个特殊问题,或者你只是以某种方式失去了连接 - JSF 明智的你应该是安全的。

    【讨论】:

      【解决方案2】:

      阅读 L-Ray 的答案后,我意识到 h:messages 在表格之外,所以我必须在名称 messages 之前添加 :。应该是:

          <h:commandButton value="#{msg.login}" action="#{userManager.login}">
              <f:ajax execute="@form" render=" @form :messages"/>
          </h:commandButton> 
      

      有关它的更多信息,请阅读: http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#AjaxRenderingOfContentOutsideForm

      【讨论】:

      • 那么,如果 L-Ray 对你有用,你为什么不直接接受 L-Ray 的回答呢?
      猜你喜欢
      • 1970-01-01
      • 2013-07-18
      • 2014-10-02
      • 2014-03-01
      • 2013-08-22
      • 1970-01-01
      • 2012-10-15
      • 1970-01-01
      相关资源
      最近更新 更多