0 Replies Latest reply on Feb 3, 2009 1:07 PM by Matteo Matassoni

    NullpointerException modalpanel

    Matteo Matassoni Newbie

      Hi I have a problem.
      I must populate a modal panel from a backing bean.
      But this bean is null beacause I set it after rendering the panel and before show it.

      this is my code.


      update.jsp wrote:
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
      <%@ taglib prefix="a4j" uri="http://richfaces.org/a4j"%>
      <%@ taglib prefix="rich" uri="http://richfaces.org/rich"%>

      <f:subview id="createpopup">
      <rich:modalPanel id="createpanel" moveable="true" autosized="true">
      <f:facet name="header">
      <h:panelGroup>
      <h:outputText value="Modifica"></h:outputText>
      </h:panelGroup>
      </f:facet>
      <f:facet name="controls">
      <h:panelGroup>
      <h:graphicImage value="/css/images/close.png" styleClass="hidelink" id="hidelink"/>
      <rich:componentControl for="createpanel" attachTo="hidelink" operation="hide" event="onclick"/>
      </h:panelGroup>
      </f:facet>
      <h:messages globalOnly="true" layout="table" style="color: red"/>
      <h:outputText value="UserID:"/>
      <h:inputText id="userid" value="#{visit.currentUser.username}" required="true" />
      <h:message for="userid" style="color: red"/>

      <h:outputText value="Nome:"/>
      <h:inputText id="nome" value="#{visit.currentUser.nome}" required="true" />
      <h:message for="nome" style="color: red"/>

      <h:outputText value="Cognome:"/>
      <h:inputText id="cognome" value="#{visit.currentUser.cognome}" required="true" />
      <h:message for="cognome" style="color: red"/>

      <h:outputText value="Password:"/>
      <h:inputText id="password" value="#{visit.currentUser.password}" required="true" />
      <h:message for="password" style="color: red"/>

      <h:outputText value="Ruolo"/>
      <h:selectOneMenu id="ruolo" value="#{visit.currentUser.ruolo}" required="true">
      <f:selectItems value="#{selectRolesBean.roleList}" />
      </h:selectOneMenu>
      <h:message for="ruolo" style="color: red"/>

      <h:outputText value="Pin:"/>
      <h:inputText id="pin" value="#{visit.currentUser.pin}" />
      <h:message for="pin" style="color: red"/>

      <h:outputText value="Cancellato" />
      <h:selectBooleanCheckbox id="delete" value="#{visit.currentUser.deleted}" />
      <h:message for="delete" style="color: red"/>
      <h:panelGroup>
      <h:panelGrid columns="2" rowClasses="center">
      <rich:componentControl for="createpanel" operation="hide" event="onclick">
      <h:commandButton value="Aggiungi" action="#{createUserBean.add}" />
      <h:commandButton value="Annulla" action="#{createUserBean.cancel}" immediate="true"/>
      </rich:componentControl>
      </h:panelGrid>
      </h:panelGroup>
      </rich:modalPanel>
      <a4j:commandLink action="#{selectUserBean.update}" id="link" reRender="userid">
      <h:graphicImage value="/css/images/edit.png" id="edit"/>
      <rich:componentControl for="createpanel" attachTo="link" operation="show" event="onclick" disableDefault="true" />
      </a4j:commandLink>
      </f:subview>


      selectUserBean wrote:
      public class SelectUserBean extends BaseBean {
      private UIData userTable;

      public UIData getUserTable() {
      return userTable;
      }

      public void setUserTable(UIData userTable) {
      this.userTable = userTable;
      }

      public String update() {
      return getUser();
      }

      public String delete() {
      return getUser();
      }

      public List getAllUsers() throws DataStoreException {
      try {
      return getUserCoordinator().getUsers();
      } catch (ObjectNotFoundException ex) {
      return new ArrayList(0);
      }
      }

      public String getUser() {
      FacesContext facesContext = getFacesContext();

      User utente = (User) userTable.getRowData();
      try {
      utente = getUserCoordinator().getUser(utente.getUsername());
      } catch (ObjectNotFoundException ex) {
      facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "L'utente selezionato non è stato trovato", "L'utente non è più memorizzato."));
      return "failure";
      } catch (DataStoreException ex) {
      facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Errore database", "Errore nel caricare l'utente."));
      return "error";
      }
      getVisit().setCurrentUser(utente);
      return "success";
      }
      }


      updateUserBean wrote:
      public class UpdateUserBean extends BaseBean {

      public UpdateUserBean() {}

      public String update() {
      FacesContext facesContext = getFacesContext();

      User utente = getVisit().getCurrentUser();
      try {
      getUserCoordinator().updateUser(utente);
      } catch (ObjectNotFoundException e) {
      facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "L'utente selezionato non è stato trovato", "L'utente non è più memorizzato"));
      return "failure";
      } catch (DataStoreException e) {
      facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Errore database", "Errore aggiornamento utente"));
      return "error";
      }
      return "success";
      }

      public String delete() {
      FacesContext facesContext = getFacesContext();

      User utente = getVisit().getCurrentUser();
      try {
      getUserCoordinator().deleteUser(utente);
      } catch (ObjectNotFoundException e) {
      facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "L'utente selezionato non è stato trovato", "L'utente non è più memorizzato"));
      return "failure";
      } catch (DataStoreException e) {
      facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Errore database", "Errore cancellazione utente"));
      return "error";
      }
      return "success";
      }
      }