【问题标题】:<a4j:commandButton> not invoking the action<a4j:commandButton> 不调用动作
【发布时间】:2013-05-25 13:36:33
【问题描述】:

我正在尝试使用&lt;a4j:commandButton&gt; 在 bean 中调用一个简单的操作方法。但是当我使用 rendereddisabled 属性(也从操作方法评估)时,它不起作用。

这是我的代码 sn-p:

<a4j:region block="true" >
    <a4j:form id="download_form">
        <a4j:commandButton id="download_button"
          action="#{studentInfo.actionDownload}"
          onclick="#{rich:component('download_progress')}.show(); setPopupPosition('#{rich:clientId('download_progress')}');"
          reRender="dlod_msg_grd"
          oncomplete="#{rich:component('download_progress')}.hide();
          value="Download a student" 
          rendered="#{studentInfo.validForDownload}"
          />
    </a4j:form>
</a4j:region>

如果我使用rendered="#{studentInfo.validForDownload}" 作为rendered="#{true}" 一切正常,bean 的操作方法被调用。但是我现在用的方式不行

studentInfo.validForDownload 正在评估为 true,因此 a4j:commandButton 正在正确呈现。

【问题讨论】:

  • studentInfo 托管 bean 的范围是什么?
  • @LuiggiMendoza,它在请求范围内
  • 看起来您的 studentInfo.validForDownload 字段具有默认值 false。尝试在 studentInfo 类定义上添加 @KeepAlive 注释,例如@KeepAlive public class StudentIfo { ... }.
  • @LuiggiMendoza,也尝试过,但没有成功
  • 尝试使用 &lt;h:messages&gt; 并删除 ajax 行为,以便您的页面可以进行刷新并显示其他问题,例如转换问题或其他问题。

标签: ajax jsf richfaces jsf-1.2


【解决方案1】:

由于您的 studentInfo 托管 bean 属于请求范围,正如您在对 Luiggi 的回复中所说,rendered="#{studentInfo.validForDownload}" 将始终评估为默认值。正如 Luiggi 所提到的,您必须使用 a4j:keepAlive 才能获得所需的行为,但您的代码需要稍作改动:

<a4j:keepAlive beanName = "studentInfo"/>
<h:form id="download_form">  
  <a4j:region block="true" >
    <a4j:commandButton id="download_button"
      action="#{studentInfo.actionDownload}"
      onclick="#{rich:component('download_progress')}.show(); setPopupPosition('#{rich:clientId('download_progress')}');"
      reRender="dlod_msg_grd"
      oncomplete="#{rich:component('download_progress')}.hide();
      value="Download a student" 
      rendered="#{studentInfo.validForDownload}"/>
  </a4j:region>
</h:form>

我不知道a4j:form 是否有效果,但可以肯定h:form 会起作用

【讨论】:

  • 试过那个但得到这个错误。 必须是文字
  • 啊,很抱歉,请尝试:
  • 那也没用。获取 NotSerializable 异常。有没有办法让我将值设置为默认值。
  • 是的,我做到了,现在得到一个 - 原因:javax.el.E​​LException:无法将类型为 $Proxy119 的 StudentInformationBackingBean@5db2381b 转换为 StudentInformationBackingBean 类
  • 您的 bean 中是否有任何不可序列化的成员?如果是,则尝试使它们可序列化或将它们标记为transient
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-16
  • 1970-01-01
  • 1970-01-01
  • 2012-04-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多