0

i'm really new to jsf. I need to enable,disable, render or not render some buttons on a page depending on the logged user privileges. The page is bound to a request scoped managed bean , i bind the rendered or disabled attribute of the commandbutton to a "visible" property of the managed bean, and an actionlistener to a managedbean method which has the only purpose to navigate to another page. If i bind one of the above properties to the visibile property, the navigation method doesn't get called, and the same page gets rerendered with the button disabled or not rendered. The more urget need is the answer to "how do i disable or hide the button?" of course, But , since i guess the problem is due to jsf page life cycle and the bean scope, i'd like also to be direct to some tutorial a bit more advanced than the hello world that can be found around.

below are part of the code. Thank you in advance for any help

the xhtml page

    <ui:define name="content">      
    <p:layoutUnit position="center" header="Dettaglio Pratica" scrollable="true">
        <h:form id="formDettaglioPratica">
        <!-- i've used javascript to redirect -->
        <p:commandButton styleClass="commandButton" value="Modifica pratica" ajax="false"
             rendered="#{praticaCtrl.visible}" onclick="navigateToChange();return false;"/>
        <p:commandButton id="backButton" styleClass="commandButton" value="Torna alla lista" 
        onclick="navigateToHome();return false;"></p:commandButton>
        <!-- never redirect to page defined in method checkIn -->
         <p:commandButton id="checkinButton" styleClass="commandButton" value="Rilascia pratica" ajax="false" 
           actionListener="#{praticaCtrl.checkIn}" disabled="#{praticaCtrl.visible}"></p:commandButton>

            <!-- printing output values -->

        <h:inputHidden id="idPratica" value="#{praticaCtrl.idPratica}"></h:inputHidden>
        <h:inputHidden id="idBox" value="#{praticaCtrl.box}"></h:inputHidden>
        </h:form>
    </p:layoutUnit>
</ui:define>

the relevant part of the managed bean

    public boolean isVisible() {
    return isVisible;
}

public void setVisible(boolean isVisible) {
    this.isVisible = isVisible;
}

public void setUser(IUserProvider user) {
    try{
    if(pratica.getUtenteCheckOut() == null
    || (pratica.getUtenteCheckOut().getMatricola().equalsIgnoreCase(user.getUser().getMatricola()))     
    )
        setVisible(true);   
    else
        setVisible(false);

    this.user = user;
    }
    catch(Exception ex)
    {log.error(ex);}
}

public void checkIn(ActionEvent event)
{
    try{
    log.info(String.format("modifica della pratica %s", idPratica));
    ajaxRedirect(String.format("../Box/ListaRichieste.xhtml?box=%s",box));
    }
    catch(Exception ex)
    {
        log.error(ex.getMessage(),ex);
    }
}

this is the ajaxRedirect method,we don't use the navigation rules neither methods return string

protected void ajaxRedirect(String url) throws IOException {
    FacesContext.getCurrentInstance().getExternalContext()
    .redirect(url);     
}

1 Answers1

0

the answer for the described behaviour can be found at : http://forum.primefaces.org/viewtopic.php?f=3&t=13269&p=39996 ,which refers a BalusC answer on a similar question on stackoverflow : commandButton/commandLink/ajax action/listener method not invoked or input value not updated

Community
  • 1
  • 1