Jsf 如何使用h:commandButton转发

Jsf 如何使用h:commandButton转发,jsf,primefaces,commandbutton,Jsf,Primefaces,Commandbutton,我有一个视图,其中我有一个带有p:commandButton的表单,一切都很好,因为我使用的是forward,这就是我需要的: <h:form id="formularioAltas"> // More code <p:commandButton value="Guardar" action="#{altasBean.agregarRefaccion()}" update="cboAlmacen cboEstado cboCategoria" /> <

我有一个视图,其中我有一个带有
p:commandButton
的表单,一切都很好,因为我使用的是
forward
,这就是我需要的:

<h:form id="formularioAltas">
    // More code
    <p:commandButton value="Guardar" action="#{altasBean.agregarRefaccion()}" update="cboAlmacen cboEstado cboCategoria" />
</h:form>
subirImagen()
方法也是void,因此我认为在该操作之后会发生一次转发。。。但事实并非如此。页面会更新,url也会更改,这意味着重定向完成了这一操作

我永远需要一个前锋。无论是
p:commandButton
还是
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>
我认为这与PrimeFaces有关,与JSF
h:commandButton
的区别在于
p: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>
所以我需要一个向前的
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>
编辑

我总是有这样一个urlblabla/AlmacenGM/

但是当
h:commandButton
启动时,url是:blabla/AlmacenGM/faces/altas.xhtml

url将更改。我已尝试在方法
subirImagen()
中返回字符串
“altas”
,因此应该进行转发,但它仍在更改url


有什么想法吗?

使用
p:commandButton
没有转发功能。它实际上是一个ajax请求,您正在生成它,因为这是它的默认行为

但是,标准的JSF
h:commandButton
执行一个转发请求,只要您在操作方法中返回一个带有导航大小写的
字符串。如果您看到重定向发生在那里,那么您必须在bean端强制重定向

另请参见:


当您单击
p:commandButton
时看到的不是“转发”,它只是一个AJAX更新,您在
update
-属性中指定的所有组件都会以这种方式更新
h:commandButton
不支持AJAX,p:commandButton
有什么问题?@user1983983,
h:commandButton
不像primefaces那样是“ajaxified”,但是,它确实支持AJAX,只要在其中使用
f:AJAX
标记。您必须在其中嵌入
f:AJAX
标记。请参阅相关链接。问题是我有两个表单。当我指明@form时,选择哪一个?我还需要更新表单本身。我这样写:
但有时有效,但有些无效。@KazMiller
@form
是当前的表单选择器<代码>将处理当前表单并进行渲染。然而,当两种形式在JSF2.x分支中使用时,会出现一些已知的问题,这两种形式计划在2.3中修复。看一看。如果您只想呈现当前表单,这不应该影响您。