2012-12-06 78 views
1

triggred在我.xhtml的网页我有2个h:commandButton元素:JSF命令按钮行动刷新

<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> 

当我刷新我的网页中最后一个按钮被点击再次triggred是我的问题是,并在行动托管bean被执行。

我不希望刷新页面时触发操作。 (仅当按钮被点击时才被触发)。

我需要改变一些东西吗?我需要做什么在页面刷新没有触发按钮操作?

感谢提前。

回答

3

发生这种情况是由于表单重新提交。将这一行添加到方法的末尾。

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

current_page是您当前页面的名称。

+0

谢谢,作品加油! – user590586