我想通过 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>
我怎样才能实现这个目标?
最佳答案
URL 仅在同步请求时更改。仅可在 GET 请求中将查询字符串添加到 URL。在 POST 之后发送重定向是创建同步 GET 请求的一种方法。
public String simular() {
// ...
return "page.xhtml?foo=42&faces-redirect=true";
}
这将重定向到 /context/page.xhtml?foo=42
。
如果您实际上不需要在基于回发的操作方法中执行任何业务逻辑,那么您也可以只使用普通按钮而不是命令按钮。
<h:button value="Simular" outcome="page.xhtml">
<f:param name="foo" value="42" />
</h:button>
关于jsf - 通过 post 在 url 中设置参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16149532/