【发布时间】:2014-08-20 20:29:20
【问题描述】:
我有一个视图,其中我有一个带有 p:commandButton 的表单,并且一切正常,因为我正在使用 forward,这就是我需要的:
<h:form id="formularioAltas">
// More code
<p:commandButton value="Guardar" action="#{altasBean.agregarRefaccion()}" update="cboAlmacen cboEstado cboCategoria" />
</h:form>
agregarRefaccion() 方法是 void 因此不会更改页面,我认为forward 发生在该操作之后,因为它始终具有相同的 url。没关系,因为这是我需要的。
在同一个视图中,我对h:commandButton 有疑问。
<h:form id="myForm" enctype="multipart/form-data" prependId="false">
// More code
<h:commandButton id="button" style="background-color: black; color: aliceblue" value="Guardar imagen para #{altasBean.refaccion.idRefaccion}" action="#{altasBean.subirImagen()}" />
</h:form>
subirImagen() 方法也是 void 所以我认为在那个动作之后会发生前锋......但事实并非如此。页面更新并且 url 发生变化,这意味着重定向做到了。
我永远需要一个前锋。不管是p:commandButton还是h:commandButton。
我认为与 PrimeFaces 以及 p:commandButton 与 JSF h:commandButton 的差异有关。
所以我需要一个前锋 h:commandButton。
编辑
我总是有这样的网址 blabla/AlmacenGM/
但是当h:commandButton 出现时,网址是:blabla/AlmacenGM/faces/altas.xhtml
网址更改。我试图将字符串 "altas" 返回到方法 subirImagen() 中,因此应该进行转发,但它仍然会更改 url。
有什么想法吗?
【问题讨论】:
-
当您单击
p:commandButton时看到的不是“转发”,它只是一个 AJAX 更新,您在update-属性中指定的所有组件都会以这种方式更新。h:commandButton不支持 AJAX,p:commandButton那里有什么问题? -
@user1983983,
h:commandButton不像 primefaces 那样被“ajaxified”,但是,它确实支持 ajax,只要你在其中使用f:ajax标签。
标签: jsf primefaces commandbutton