PickList always points to NullPointerException

UI Components for JSF
Post Reply
sdguna
Posts: 41
Joined: 06 May 2010, 17:42

26 Jun 2010, 12:51

Hello,

I am using the picklist, the backingbean returns correctly the values but somewhere everything goes wrong and I get nullPointerException. Please help me, I am trying to debug this problem for a while without result.

Here is the code:

Code: Select all

        <h:form>
              <div id="footerPrice1" style="background:url('../attachments/img04.jpg'); background-repeat:repeat-x;">

                          <h1><h:outputText value="Create/Edit"/></h1>
                          <h:panelGrid columns="2">
                              <h:outputLabel value="Semaine:" for="semaine" />
                              <h:inputText id="semaine" value="#{planningchauffeurController.newSemaine}" title="Semaine" required="true" requiredMessage="The Semaine field is required."/>
                              <h:outputLabel value="ShiftPool:" for="shiftPool" />
                              <h:selectOneMenu id="shiftPool" value="#{planningchauffeurController.newShiftPool}" title="ShiftPool" required="true" requiredMessage="The ShiftPool field is required.">
                                  <f:selectItems value="#{shiftController.itemsAvailableSelectOne}"/>
                              </h:selectOneMenu>
                              <h:outputLabel value="Drivers:" for="drivers" />
                                    <h:selectManyListbox id="drivers"  value="#{planningchauffeurController.driversList}" title="Drivers" required="true" requiredMessage="The Drivers field is required.">
                                        <f:selectItems value="#{planningchauffeurController.availableDrivers}"/>
                                    </h:selectManyListbox>
                           </h:panelGrid>
                           <p:pickList value="#{planningchauffeurController.pickDrivers}" var="pickDrivers"
                                itemLabel="#{pickDrivers.nameDriver}" itemValue="#{pickDrivers}"
                                converter="Drivers" />
                   </div>
                    <div id="footer" style="background:url('../attachments/footerbg.gif'); background-repeat:repeat-x;">
                      <div id="button"  align="RIGHT" style="height:22px; width:100%; margin-top:5PX;">
                         <h:commandButton id="Enregistrer" action="#{purchaseorderController.submitPurchaseorder}"   image="../icon/save1.png"/>
                      </div>
                   </div>
                </h:form>
Here is my backing bean:

Code: Select all

@ManagedBean (name="planningchauffeurController")
@SessionScoped
public class PlanningchauffeurController {

    private Planningchauffeur current;
    private DataModel items = null;
    @EJB private Planning_jpa.PlanningchauffeurFacade ejbFacade;
    private PaginationHelper pagination;
    private int selectedItemIndex;
    private Integer newSemaine;
    private DualListModel<Drivers> pickDrivers;
    private List<Drivers> availableDrivers;
    private List<Drivers> driversList;
    private Shift newShiftPool;

    public PlanningchauffeurController() {
        
    }

    public void submitPlanningchauffeur() {

        Iterator i = driversList.iterator();
        while(i.hasNext()){
            Drivers drivers = (Drivers) i.next();
            try{
                ejbFacade.createPlanningchauffeur(newSemaine,drivers,newShiftPool);
                this.newSemaine = null;
                this.newSemaine = null;

            }catch (EJBException e) {
                    e.getMessage();
            }
        }


    }

    public List<Drivers> getAvailableDrivers() {
        availableDrivers = ejbFacade.getAvailableDrivers();
        return(availableDrivers);

    }
.........................................
....................................
................................

    public DualListModel<Drivers> getPickDrivers() {
        pickDrivers = new DualListModel<Drivers>(availableDrivers, driversList);
        return pickDrivers;
    }

    public void setPickDrivers(DualListModel<Drivers> pickDrivers) {
        this.pickDrivers = pickDrivers;
    }
Here is the Converter

Code: Select all

    @FacesConverter(value = "Drivers", forClass=Drivers.class)
    public static class DriversControllerConverter implements Converter {

        @Override
        public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
            if (value == null || value.length() == 0) {
                return null;
            }
            DriversController controller = (DriversController)facesContext.getApplication().getELResolver().
                    getValue(facesContext.getELContext(), null, "driversController");
            return controller.ejbFacade.find(getKey(value));
        }

        java.lang.Integer getKey(String value) {
            java.lang.Integer key;
            key = Integer.valueOf(value);
            return key;
        }

        String getStringKey(java.lang.Integer value) {
            StringBuffer sb = new StringBuffer();
            sb.append(value);
            return sb.toString();
        }

        @Override
        public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
            if (object == null) {
                return null;
            }
            if (object instanceof Drivers) {
                Drivers o = (Drivers) object;
                return getStringKey(o.getIdDriver());
            } else {
                throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: "+DriversController.class.getName());
            }
        }
I am sure the problem is not a big one. As said the devil is in the detail. I need to figure out that devile, please help me!!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 63 guests