1

I have a view where I have a form with p:commandButton and everything works fine beacuse I'm using forward and that's what I need:

<h:form id="formularioAltas">
    // More code
    <p:commandButton value="Guardar" action="#{altasBean.agregarRefaccion()}" update="cboAlmacen cboEstado cboCategoria" />
</h:form>

The method agregarRefaccion() is void so does not changes the page, I think a forward takes place after that action because it always has the same url. That is Ok beacuse that is what I need.

In the same view a have another form where I have a problem with 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>

The subirImagen() method is void too so I thought a forward would take place after that action... but it doesn't. The page updates and the url changes so that means a redirect did that.

I will always need a forward. No matter if it is a p:commandButton or a h:commandButton.

I think has something to be with PrimeFaces and the differences of p:commandButton with JSF h:commandButton.

So I need a forward in that h:commandButton.

Edit

I always have an url like this blabla/AlmacenGM/

but when h:commandButton goes the url is: blabla/AlmacenGM/faces/altas.xhtml

The url changes. I have tried to return the string "altas" int the method subirImagen() so a forward should take place but it still changing the url.

Any ideas?

Kaz Miller
  • 949
  • 3
  • 22
  • 40
  • What you see when you click on the `p:commandButton` is no "forward", it's just an AJAX-update, and all the components you specify in the `update`-attribute get updated that way. `h:commandButton` does not support AJAX, what is the problem with a `p:commandButton` there? – user1983983 Jun 30 '14 at 13:15
  • @user1983983, `h:commandButton` is not 'ajaxified' like the primefaces' one, however, it does support ajax, as long as you use the `f:ajax` tag into it. – Aritz Jun 30 '14 at 13:20

1 Answers1

2

There's no forward with p:commandButton. It's actually an ajax request what you're peforming, because it's its default behaviour.

However, the standard JSF h:commandButton performs a forward request, as long as you return a String with the navigation case in your action method. If you see a redirection taking place there, you must be forcing it in your bean side.

See also:

Community
  • 1
  • 1
Aritz
  • 30,971
  • 16
  • 136
  • 217
  • 2
    You have to embed a `f:ajax` tag into it. See the related link – Aritz Jun 30 '14 at 13:36
  • Hey the problem is that I have two forms. When I indicate @form which of them is being selected? I also need to update the form itself. I put something like this: `` but sometimes works but some not. – Kaz Miller Jun 30 '14 at 16:23
  • 1
    @KazMiller `@form` is a current form selector. `` will process your current form and render it. There are however known issues when two forms come to play in JSF 2.x branches, which are planned to be fixed for 2.3. Take a look to [this](http://stackoverflow.com/questions/7807334/rendering-other-form-by-ajax-causes-its-view-state-to-be-lost-how-do-i-add-this). This shouldn't affect you if you just want to render your current form. – Aritz Jul 02 '14 at 13:26