0

i am working on a simple project in JSF 2.2 but i have some problem navigating between some pages. In the project i have a general template and all the views are template clients of that general template.

this is the view that i have troubles with:

<h:body>

    <ui:composition template="./LayoutGeneral.xhtml">

        <ui:define name="content">
            <p:commandButton value="Registrar Comunidad" action="#{comunidadBean.irRegisterView}"/>
        </ui:define>

    </ui:composition>

</h:body>

In the action of the commandButton i call a method from the managed bean (Thar managed bean have other method that i call to change the page and they work fine, but this method doesnt):

(Managed Bean)

@ManagedBean
@SessionScoped
public class ComunidadBean {    
    private String idComunidad;
    private String idPresidente;
    private String calle;
    private int numero;
    private int nVecinos;

    @EJB
    private ComunidadDAO ejb;

    public String register(){
        if(ejb.realizaRegistro(this)){
            return "principalView";
        } else{
            FacesMessage fm = new FacesMessage ("No se pudo registrar");
            FacesContext.getCurrentInstance().addMessage("msg", fm);
            return null;
        }
    }

    public String irRegisterView(){
        return "registroCView";
    }

}

So the method "register" works fine and the page change but the method "irRegisterView" doesnt navigate to "registroCView" page.

Does someone has any idea of what it is happening?

Thanks!

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Megan..
  • 25
  • 6

1 Answers1

1

I can' comment, so I write this as an answer.

  • I see that your bean is SessionScoped. You need to implement Serializable because a SessionScoped bean is passivating after a time.
  • do you have a form in LayoutGeneral.xhtml? If not, this code will never works because a commandButton needs be within a form.
  • why you call the method as a property? In JSF 2.2 and EL 2.3, you can call methods like this: #{comunidadBean.isRegisterView()}.
  • Is some exception thrown when click the button? If do, paste the stack trace.
  • 1
    Thank you so much!! The problem was that the commandButton wasnt inside a form! I didnt know that it has to be like that! – Megan.. Mar 19 '16 at 16:12