【问题标题】:jsf command button action triggred in refresh刷新时触发的jsf命令按钮动作
【发布时间】:2012-12-06 19:06:23
【问题描述】:

在我的 .xhtml 页面中,我有 2 个 h:commandButton 元素:

 <h:commandButton immediate="true" lang="en" class="msbutton"  action="#{user.changeLanguage()}" value="Test1">
 </h:commandButton>
 <h:commandButton immediate="true" lang="en" class="msbutton"  action="#{user.test()}"   value="Test2">
 </h:commandButton>

我的问题是,当我刷新页面时,再次触发最后一次单击的按钮,并执行托管 bean 中的操作。

我不希望在页面刷新时触发该操作。 (仅在单击按钮时触发)。

我需要改变什么吗?我需要做什么才能在不触发按钮操作的情况下刷新页面?

提前致谢。

【问题讨论】:

    标签: jsf jsf-2


    【解决方案1】:

    这是由于重新提交表单而发生的。在方法的末尾添加这一行。

    public void test() {
      .......
      FacesContext.getCurrentInstance().getExternalContext().redirect("current_page.jsf");
    }
    

    current_page 是您当前页面的名称。

    【讨论】:

      猜你喜欢
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      • 2017-03-27
      • 2014-04-03
      • 1970-01-01
      • 2011-07-09
      • 2014-01-06
      • 2015-10-17
      相关资源
      最近更新 更多