我想通过post在url中设置一个参数,但是这个页面只执行一个方法并用h:commandButton更新页面。
<h:commandButton value="Simular"
action="#{simulador.simular()}"
style="margin:0 4px 0 0;"
immediate="true">
<f:ajax render="@form" immediate="true"/>
</h:commandButton>
我怎样才能做到这一点?
答案 0 :(得分:1)
仅在同步请求中更改URL。只有GET请求才能将查询字符串添加到URL。 POST后发送重定向是创建同步GET请求的一种方法。
public String simular() {
// ...
return "page.xhtml?foo=42&faces-redirect=true";
}
这将重定向到/context/page.xhtml?foo=42
。
如果您实际上不需要基于回发在action方法中执行任何业务逻辑,那么您也可以使用普通按钮而不是命令按钮。
<h:button value="Simular" outcome="page.xhtml">
<f:param name="foo" value="42" />
</h:button>