salut à vous tous,
Vraiment en besoin d'aide je souffre avec une erreur depuis 2 jours. je suis en train de développer ma premiére application JEE avec JSF2.2 Hibernate 5.2.9 Spring3
je veux remplir dynamiquement un selectOneMenu à partir d'une base de données.
dans ma page JSF addUtilisateur.xhtml
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
                              <tr>
				<td><h:outputLabel for="groupe" value="Groupe : "  effect="fade" /></td> 
					<td><h:selectOneMenu  value="#{utilisateurMB.groupe}" id="groupe" converter="com.it4all.giep.core.controller.GroupeConverter">
					    <f:selectItem itemLabel="" itemValue=""></f:selectItem>
					    <f:selectItems value="#{groupeMB.groupeList}" var="groupe" itemLabel="#{groupe.libelle}" itemValue="#{groupe}"
                                             </f:selectItems>
						<p:ajax event="blur" update="groupeMsg" />
					         <p:message id="groupeMsg" for="groupe" display="icon" />
					</h:selectOneMenu></td>
			     </tr>

la classe du converter GroupeConverter

Code ava : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@FacesConverter("com.it4all.giep.core.controller.GroupeConverter")
public class GroupeConverter implements Converter {
    @Resource
    private IGroupeService groupeService;
	@Override
	public Object getAsObject(FacesContext context, UIComponent component,String value) {
		 String str[] = value.split(",", 2);
 
		    if (value != null && !value.trim().isEmpty()){
		         // Instanciation du model
		        Groupes groupe = new Groupes();
		       // System.out.println(str[1]);
		        System.out.println(value);
		       // Va chercher l'objet en base qui correspond à cet id
 
		      groupe = groupeService.getGroupeById( Integer.parseInt(str[0]));
 
 
		        return groupe;
		    }
		    else {
		        FacesMessage message = new FacesMessage("Veuillez sélectionner un groupe");
		        message.setSeverity(FacesMessage.SEVERITY_ERROR);
		        return null;
		    }
	}
 
	@Override
	public String getAsString(FacesContext context, UIComponent component,
            Object value) {
		return value.toString();
    }
}

méthode equals je l'ai générée automatiquement dans la classe Groupes

Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Groupes other = (Groupes) obj;
		if (idgroupe != other.idgroupe)
			return false;
		if (libelle == null) {
			if (other.libelle != null)
				return false;
		} else if (!libelle.equals(other.libelle))
			return false;
		return true;
	}
}

la groupeList dans le GroupeManagedbean

Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
public List<Groupes> getGroupeList() {
 
		groupeList = new ArrayList<Groupes>();
		groupeList.addAll(getGroupeService().findAll());
		return groupeList;
	}
 
}

quant j'execute je récupére ma liste de la base de données mais quand je choisit un Groupe de la liste déroulante JSF utilise leGroupeConverter avec getAsObject il me renvoie mon message on console avec la valeure "1,admin" puis j'ai cette érreur NullPointerException
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
 
Hibernate: select groupes0_.IDGROUPE as IDGROUPE1_9_, groupes0_.DESCRIPTION as DESCRIPT2_9_, groupes0_.LIBELLE as LIBELLE3_9_ from groupes groupes0_
1,admin
avr. 17, 2017 9:42:31 PM com.sun.faces.context.PartialViewContextImpl processPartial
INFOS: java.lang.NullPointerException
java.lang.NullPointerException
	at com.it4all.giep.core.controller.GroupeConverter.getAsObject(GroupeConverter.java:33)
	at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(Unknown Source)
	at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(Unknown Source)
	at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(Unknown Source)
	at javax.faces.component.UIInput.getConvertedValue(Unknown Source)
	at javax.faces.component.UIInput.validate(Unknown Source)
	at javax.faces.component.UIInput.executeValidate(Unknown Source)
	at javax.faces.component.UIInput.processValidators(Unknown Source)
	at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(Unknown Source)
	at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(Unknown Source)
	at javax.faces.component.UIComponent.visitTree(Unknown Source)
	at javax.faces.component.UIComponent.visitTree(Unknown Source)
	at javax.faces.component.UIForm.visitTree(Unknown Source)
	at javax.faces.component.UIComponent.visitTree(Unknown Source)
	at javax.faces.component.UIComponent.visitTree(Unknown Source)
	at com.sun.faces.context.PartialViewContextImpl.processComponents(Unknown Source)
	at com.sun.faces.context.PartialViewContextImpl.processPartial(Unknown Source)
	at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
	at javax.faces.component.UIViewRoot.processValidators(Unknown Source)
	at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(Unknown Source)
	at com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
	at com.sun.faces.lifecycle.LifecycleImpl.execute(Unknown Source)
	at javax.faces.webapp.FacesServlet.service(Unknown Source)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1083)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:640)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
 
avr. 17, 2017 9:42:31 PM com.sun.faces.lifecycle.ProcessValidationsPhase execute
AVERTISSEMENT: java.lang.NullPointerException
javax.faces.FacesException: java.lang.NullPointerException
	at com.sun.faces.context.PartialViewContextImpl.processPartial(Unknown Source)
	at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
	at javax.faces.component.UIViewRoot.processValidators(Unknown Source)
	at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(Unknown Source)
	at com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
	at com.sun.faces.lifecycle.LifecycleImpl.execute(Unknown Source)
	at javax.faces.webapp.FacesServlet.service(Unknown Source)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1083)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:640)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
	at com.it4all.giep.core.controller.GroupeConverter.getAsObject(GroupeConverter.java:33)
	at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(Unknown Source)
	at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(Unknown Source)
	at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(Unknown Source)
	at javax.faces.component.UIInput.getConvertedValue(Unknown Source)
	at javax.faces.component.UIInput.validate(Unknown Source)
	at javax.faces.component.UIInput.executeValidate(Unknown Source)
	at javax.faces.component.UIInput.processValidators(Unknown Source)
	at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(Unknown Source)
	at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(Unknown Source)
	at javax.faces.component.UIComponent.visitTree(Unknown Source)
	at javax.faces.component.UIComponent.visitTree(Unknown Source)
	at javax.faces.component.UIForm.visitTree(Unknown Source)
	at javax.faces.component.UIComponent.visitTree(Unknown Source)
	at javax.faces.component.UIComponent.visitTree(Unknown Source)
	at com.sun.faces.context.PartialViewContextImpl.processComponents(Unknown Source)
	... 27 more
 
avr. 17, 2017 9:42:31 PM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError
GRAVE: java.lang.NullPointerException
	at com.it4all.giep.core.controller.GroupeConverter.getAsObject(GroupeConverter.java:33)
	at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(Unknown Source)
	at com.sun.faces.renderkit.html_basic.MenuRenderer.convertSelectOneValue(Unknown Source)
	at com.sun.faces.renderkit.html_basic.MenuRenderer.getConvertedValue(Unknown Source)
	at javax.faces.component.UIInput.getConvertedValue(Unknown Source)
	at javax.faces.component.UIInput.validate(Unknown Source)
	at javax.faces.component.UIInput.executeValidate(Unknown Source)
	at javax.faces.component.UIInput.processValidators(Unknown Source)
	at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(Unknown Source)
	at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(Unknown Source)
	at javax.faces.component.UIComponent.visitTree(Unknown Source)
	at javax.faces.component.UIComponent.visitTree(Unknown Source)
	at javax.faces.component.UIForm.visitTree(Unknown Source)
	at javax.faces.component.UIComponent.visitTree(Unknown Source)
	at javax.faces.component.UIComponent.visitTree(Unknown Source)
	at com.sun.faces.context.PartialViewContextImpl.processComponents(Unknown Source)
	at com.sun.faces.context.PartialViewContextImpl.processPartial(Unknown Source)
	at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
	at javax.faces.component.UIViewRoot.processValidators(Unknown Source)
	at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(Unknown Source)
	at com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
	at com.sun.faces.lifecycle.LifecycleImpl.execute(Unknown Source)
	at javax.faces.webapp.FacesServlet.service(Unknown Source)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1083)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:640)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
J'attends votre aide.