【问题标题】:JSF action never triggered on h:commandButton (with f:ajax) [duplicate]JSF 操作从未​​在 h:commandButton 上触发(使用 f:ajax)[重复]
【发布时间】:2013-06-08 04:16:57
【问题描述】:

我阅读了很多关于 f:ajax 与其他 jsf 或 html 标签一起工作的内容,但似乎还不够!

我的页面中有一个带有(必要的?)f:ajax 标记的命令按钮,并且该操作从未触发。这是代码。

<html>
  <h:head>
  </h:head>

  <h:body>
    <h:form>
      <h:commandButton action="#{bean.myFirstFunction}" value="Submit">
        <f:ajax render=":wrap" />
      </h:commandButton>
    </h:form>

    <h:panelGroup id="wrap">
      <h:panelGroup id="content" rendered="#{bean.myVariable != null}">

       <h:form>
         <h:commandButton action="#{bean.mySecondFunction}" value="Submit">
           <f:ajax render=":wrap" />
         </h:commandButton>
       </h:form>

      </h:panelGroup>
    </panelGroup>
  <h:body>
</html>

所以像上面一样,我有两个按钮,第一个外包装工作,它必须显示一开始隐藏的包装面板。第二个已经结束,必须启动一个完全不同的动作。 (包装必须保持显示)

这是豆子。

@ManagedBean(name = "bean")
@ViewScoped
public class myBean {
  private Object myVariable;

  public void setMyVariable(Object o) { ... }
  public Object getMyVariable() { ... }

  @PostConstruct
  public void init() {
    this.myVariable = null;
  }

  public void myFirstFonction() {
    this.myVariable = new Object();
  }

  public void mySecondAction() {
    System.out.println("here");
  }
}

当我启动时,我看到了第一个按钮。我点击它,第二个出现。 (所以第一个函数被调用,对象被实例化,并使用 ajax 标记呈现包装。 然而,当第二个按钮被点击时,什么都没有发生。

我只写了一部分代码,希望是这里的错误。

我认为是关于面板组的渲染选项,但我无法准确定位。

谢谢

【问题讨论】:

    标签: jsf render commandbutton


    【解决方案1】:

    根据commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated 的第 9 点,您是JSF spec issue 790 的受害者。当您对某些内容进行 ajax 更新时,这些内容又包含表单,它将失去其视图状态。作为一种快速解决方法,只需为要更新的表单提供一个 ID,并在 &lt;f:ajax render&gt; 中明确引用它。

      <h:body>
        <h:form>
          <h:commandButton action="#{bean.myFirstFunction}" value="Submit">
            <f:ajax render=":wrap :wrapForm" />
          </h:commandButton>
        </h:form>
    
        <h:panelGroup id="wrap">
          <h:panelGroup id="content" rendered="#{bean.myVariable != null}">
    
           <h:form id="wrapForm">
             <h:commandButton action="#{bean.mySecondFunction}" value="Submit">
               <f:ajax render=":wrap" />
             </h:commandButton>
           </h:form>
    
          </h:panelGroup>
        </panelGroup>
      <h:body>
    

    【讨论】:

    【解决方案2】:

    我决定做一些更简单的事情。事实上,我的页面中并不需要 ajax,因为我的 bean 在 ViewScope 中。所以页面可以重新加载,这不是一个真正的问题。所以我摆脱了我的 f:ajax 标签,一切都很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-18
      • 1970-01-01
      • 1970-01-01
      • 2012-11-16
      • 2019-06-24
      • 2011-04-17
      • 1970-01-01
      相关资源
      最近更新 更多