JSF a4j:设置'disabled'时commandButton不工作 [英] JSF a4j:commandButton not working when 'disabled' is set

查看:144
本文介绍了JSF a4j:设置'disabled'时commandButton不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在a4j:commandButton上包含'disabled'属性时,不会执行按钮的操作。取消禁用属性会使其正常工作。我没有做任何特殊验证(我知道)并且没有看到任何验证错误消息。

When I include a 'disabled' attribute on an a4j:commandButton, the button's action is not performed. Taking the 'disabled' attribute out causes it to work properly. I am not doing any special validation (that I'm aware of) and am not seeing any validation error messages.

这是我页面的一部分:

<t:dataTable id="myTable"
             var="region"
             value="#{MyPageBackingBean.regions}"
             width="100%">

...

<a4j:commandButton value="Update"
                   action="#{region.doUpdate}"
                   oncomplete="alert('done');"
                   disabled="#{!empty region && region.messageEmpty}"
                   immediate="true"/>

...

</t:dataTable>

任何想法?谢谢!

修改:

我尝试设置preserveDataModel =trueon t:dataTable无济于事。

I tried setting preserveDataModel="true" on the t:dataTable to no avail.

我还做了一个测试,有一个a4j:commandButton和没有数据表的文本框,但支持bean动作仍然没有解雇:

I also made a test having an a4j:commandButton and text box with no data table, but the backing bean action is still not being fired:

      <h:form>
     <a4j:region>
        <a4j:outputPanel id="testregion">
        <h:messages id="messages"/>

                          <a4j:status>
                             <f:facet name="start">
                                <h:graphicImage value="/images/progress_indicator.gif"/>
                             </f:facet>
                          </a4j:status>

                       <h:inputTextarea
                             rows="5"
                             value="#{MyPageBackingBean.myValue}"
                             style="width:100%; border: 1px solid #99CCFF;">
                          <a4j:support event="onkeyup"
                                       reRender="testregion"
                                       eventsQueue="messageModificationQueue"
                                       ignoreDupResponses="true"
                                       requestDelay="500"/>
                       </h:inputTextarea>

                       <a4j:commandButton id="doDelete"
                                          value="Delete"
                                          action="#{MyPageBackingBean.dummy}"
                                          reRender="testregion"
                                          disabled="#{empty MyPageBackingBean.myValue}"/>
                    <h:outputText value="#{MyPageBackingBean.myValue}"/>
        </a4j:outputPanel>
     </a4j:region>
  </h:form>

以下是用于测试的新支持bean代码:

Here is the new backing bean code used for testing:

private String m_myValue = null;
   public String getMyValue()
   {
      return m_myValue;
   }
   public void setMyValue(String value)
   {
      m_myValue = value;
   }
   private String mystr2 = null;
   public String dummy()
   {
      mystr2 = "hello";
      return null;
   }

谢谢!

推荐答案

在HTML世界中,已禁用属性会导致名称 - value 任何HTML输入元素的属性对(输入选择 textarea 按钮)未发送到服务器端。

In HTML world, the disabled attribute causes the name-value attribute pair of any HTML input element (input, select, textarea and button) not being sent to the server side.

在JSF世界中, name 属性的存在用于标识要在以下位置调用的bean操作服务器端。但是,在表单提交JSF的应用请求值阶段,还会检查组件的已禁用(和呈现)attribtue是否进行评估采取任何行动之前 true

In JSF world, the presense of the name attribute is been used to identify the bean action to be invoked at the server side. However, during apply request values phase of the form submit JSF also checks if the component's disabled (and rendered) attribtue evaluates true before taking any actions.

#{region} 这里是#{MyPageBackingBean.regions} 的迭代表行对象,默认情况下返回 isMessageEmpty() getter 。在表单提交的新请求中,#{MyPageBackingBean.regions} 显然是空的,这有效地使按钮禁用 。然后JSF不会调用相关的操作。

The #{region} is here an iterated table row object of #{MyPageBackingBean.regions} whose isMessageEmpty() getter by default returns true. In the new request of the form submit the #{MyPageBackingBean.regions} is apparently empty which effectlively makes the button disabled. JSF won't invoke the associated action then.

为此,你需要确保#{MyPageBackingBean.regions} 在后续请求中返回完全相同的datamodel。最简单的修复方法是将 MyPageBackingBean bean放在会话范围内,这样它就不会在后续请求中重新初始化,但这也有更多的负面影响。另一个修复是重新排列数据模型加载,以便它在bean构造函数中发生。由于您已经在使用Tomahawk的< t:dataTable> ,因此您需要将 preserveDataModel 属性设置为。有关使用数据表的更多提示,您可能会发现本文也很有用:使用数据表

To the point, you need to make sure that #{MyPageBackingBean.regions} returns exactly the same datamodel in the subsequent request. Easiest fix is to place the MyPageBackingBean bean in session scope so that it don't get reinitialized in the subsequent request, but that has more negative side effects as well. Another fix is to rearrange the datamodel loading so that it happens in the bean constructor. As you're already using Tomahawk's <t:dataTable>, you need to set its preserveDataModel attribute to true. For more hints about using datatables, you may find this article useful as well: Using Datatables.

这篇关于JSF a4j:设置'disabled'时commandButton不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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