1

i got this issue : i have a dataTable containing a list of object of Type Test class , and i have a column named "Assigned to" in which i wanna display the name of the user that the test shown in the row is assigned to so i wrote a method to do this :

<p:column headerText="Assigned to">  
    <h:outputText value="#{projectCampaignManagementMB.initAssignedToData(test)}" />
</p:column>

I'm getting this error: nov. 04, 2012 4:42:06 PM com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback visit Grave: javax.el.ELException: /campaingManagement.xhtml @2388,132 value="#{projectCampaignManagementMB.initAssignedToData(test)}": java.lang.NullPointerException

Here's all the code :

<p:dataTable var="test" value="#{projectCampaignManagementMB.campaignTestList}" >  
    <p:column headerText="User">  
    </p:column>  

    <p:column headerText="Assigned to">  
        <h:outputText value="#{projectCampaignManagementMB.initAssignedToData(test)}" />
    </p:column>

</dataTable>

the method :

public String initAssignedToData(Test pTest){

    int assigendID = currentCampaign.getAssignedUserID(pTest);

    User pUser = (User) userByID.get(new Integer(assigendID));

    System.out.println("User assigned is = " + pUser + " , assigendID = " + assigendID);

    return(((User) userByID.get(new Integer(assigendID))).getLoginFromModel()); // TO CHANGE

}

So is there another way to implement this. Many thanks

Amira
  • 3,184
  • 13
  • 60
  • 95
  • Your code is fine. What do you mean by "it is considered as an error". If your IDE complains about it and it works as expected may be your IDE is wrong. – Kerem Baydoğan Nov 04 '12 at 15:36
  • @KeremBaydoğan sorry i try to run it another time and i'm getting this error : you can see Edit – Amira Nov 04 '12 at 15:45
  • @AmiraGL if userByID is a map add containsKey check before `userByID.get...` if it not contains return null (for example)... (in general add contains check before trying to use the `get`) – Daniel Nov 04 '12 at 15:48
  • @Daniel i tried it but the problem is in the El expression which's not validated by eclipse it's underlined with red – Amira Nov 04 '12 at 16:42

1 Answers1

2

Check that your projectCampaignManagementMB bean is @ViewScoped at least and all the elements inside the initAssignedToData method aren't null by debugging or using log systems.

It would be better (for performance) to load this String into an attribute of your Test object before calling the datatable (you have the bean constructor and the @PostConstruct public void init()). Otherwise, this initAssignedToData could be called more than once by the JSF framework. More info about this:

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332