1 pièce(s) jointe(s)
Comment résoudre l'erreur java.lang.NumberFormatException: null
Salut tout le monde
j'ai un ptit soucis avec mon application web ( j'utilise JEE JSF)
j'ai reussi a crèe la methode Afficher et ajouter mais j'arrive pas a faire modifier ca me retourne cette erreur :
Code:
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
|
null
- Stack Trace
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:542)
at java.lang.Integer.parseInt(Integer.java:615)
at com.intervention.jsf.beans.intervenant.update(intervenant.java:139)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at javax.el.ELUtil.invokeMethod(ELUtil.java:332)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:537)
at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
at com.sun.el.parser.AstValue.invoke(AstValue.java:283)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:147)
at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:814)
at javax.faces.component.UICommand.broadcast(UICommand.java:300)
at javax.faces.component.UIData.broadcast(UIData.java:1108)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:745) |
et les methode afficher ajouter et modifier sont dans cette classe :
Code:
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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
package com.intervention.jsf.beans;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.hibernate.service.ServiceRegistry;
import com.intervention.jsf.dao.LoginDAO;
import com.intervention.jsf.util.DataConnect;
@ManagedBean
@SessionScoped
public class intervenant implements Serializable {
private int id_intervenant;
private String login;
private String password;
private String type;
public int getId_intervenant() {
return id_intervenant;
}
boolean editable;
public boolean isEditable() {
return editable;
}
public void setEditable(boolean editable) {
this.editable = editable;
}
public void setId_intervenant(int id_intervenant) {
this.id_intervenant = id_intervenant;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public intervenant(int id_intervenant, String login, String password, String type) {
super();
this.id_intervenant = id_intervenant;
this.login = login;
this.password = password;
this.type = type;
}
public intervenant() {
super();
// TODO Auto-generated constructor stub
}
public String validateUsernamePassword() throws SQLException {
String test=null;
String valid = LoginDAO.validate(login, password);
if (valid.equals("admin")) {
test="admin";
} else if (valid.equals("intervenant")) {
test= "intervenant";
}
else if(valid.equals("false")) {
test= "aucun_intervenant";
}
return test;
}
public ArrayList<intervenant> lister() throws Exception {
ArrayList<intervenant> list_intervenant = new ArrayList<>();
PreparedStatement rst;
String str="SELECT id_intervenant, login,password,type FROM intervenant";
Connection con =DataConnect.getConnection();
rst=con.prepareStatement(str);
ResultSet rs=rst.executeQuery();
while(rs.next()){
intervenant intervenant= new intervenant();
intervenant.setId_intervenant(rs.getInt("Id_intervenant"));
intervenant.setLogin(rs.getString("login"));
intervenant.setPassword(rs.getString("password"));
intervenant.setType(rs.getString("type"));
list_intervenant.add(intervenant);
}
return list_intervenant;
}
public void ajouter() throws Exception {
// Connection con =DataConnect.getConnection();
PreparedStatement rst;
String str="insert into intervenant ( login, password,type) values(?,?,?)";
Connection con =DataConnect.getConnection();
rst=con.prepareStatement(str);
rst.setString(1,this.getLogin());
rst.setString(2,this.getPassword());
rst.setString(3,this.getType());
int execute= rst.executeUpdate();
if(execute>0){
System.out.println("update OKAy");
}
}
public void update() throws Exception {
PreparedStatement rst;
String str="Update intervenant set loqin=?,password=?,type=? where id_intervenant=? ";
Connection con =DataConnect.getConnection();
rst=con.prepareStatement(str);
HttpServletRequest request =getRequest();
int id=Integer.parseInt(request.getParameter("id_intervenant"));
rst.setString(1,this.getLogin());
rst.setString(2,this.getPassword());
rst.setString(3,this.getType());
rst.setInt(4,id);
int execute= rst.executeUpdate();
if(execute>0){
System.out.println("update OKAy");
}
}
public ArrayList<intervenant> getlist() throws Exception{
return lister();
}
public String saveAction() throws Exception{
for(intervenant list: lister()){
list.setEditable(false);
}
return null;
}
public void modifier() throws Exception {
// Connection con =DataConnect.getConnection();
int id_intervenant;
// Reclamation reclamation_changer= new Reclamation();
ArrayList<intervenant> intervenant_modi=lister();
//FacesContext fac= FacesContext.getCurrentInstance();
//Map<String,String> Mapparam= fac.getExternalContext().getInitParameterMap();
HttpServletRequest request =getRequest();
id_intervenant=Integer.parseInt(request.getParameter("id_intervenant"));
for(intervenant inter: intervenant_modi){
if(inter.getId_intervenant()==id_intervenant){
this.setId_intervenant(inter.getId_intervenant());
this.setLogin(inter.getLogin());
this.setPassword(inter.getPassword());
this.setType(inter.getType());
}
}
}
public static HttpServletRequest getRequest() {
return (HttpServletRequest) FacesContext.getCurrentInstance()
.getExternalContext().getRequest();
}
//logout event, invalidate session
public static HttpSession getSession() {
return (HttpSession) FacesContext.getCurrentInstance()
.getExternalContext().getSession(false);
}
public String logout() {
HttpSession session = getSession();
session.invalidate();
return "login";
}
public String editAction(intervenant inter) {
inter.setEditable(true);
return null;
}
} |
et puis les fichier xhtml pour afficher ajouter et modifier
Code:
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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title> Hello #{intervenant.login} </title>
<link rel="stylesheet" href="css/succes.css" />
</h:head>
<h:body>
<h:form>
<p>Welcome #{intervenant.login}</p>
<h:commandLink action="#{intervenant.logout}" value="Logout"></h:commandLink>
<center>
<h:dataTable var="list" value="#{intervenant.lister()}" border="1">
<h:column>
<f:facet name="header">INTERVENANT ID</f:facet>
<h:inputText value="#{list.id_intervenant}"/>
</h:column>
<h:column>
<f:facet name="header">LOGIN</f:facet>
<h:inputText value="#{list.login}"/>
</h:column>
<h:column>
<f:facet name="header">Password</f:facet>
<h:inputText value="#{list.password}"/>
</h:column>
<h:column>
<f:facet name="header">TYPE</f:facet>
<h:inputText value="#{list.type}"/>
</h:column>
<h:column>
<f:facet name="header">EDIT</f:facet>
<h:commandLink action="modifierIntervenant" actionListener="#{intervenant.update()}" value="Edit" ></h:commandLink>
<f:param name="id" value="#{list.id}"/>
</h:column>
<h:column>
<f:facet name="header">DELETE</f:facet>
<h:commandLink action="ajouterIntervenant" actionListener="#{intervenant.modifier()}" value="Delete" ></h:commandLink>
</h:column>
</h:dataTable>
</center>
<h:commandLink action="ajouterIntervenant" value="Create Intervenant"/>
</h:form>
</h:body>
</html> |
ajouter
Code:
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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<h:body>
<center>
<f:view>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Intervenant ID"/>
<h:inputText value="#{intervenant.id_intervenant}" required="true" requiredMessage="le champs et aubligatoire"/>
<h:outputLabel value="LOGIN"/>
<h:inputText value="#{intervenant.login}" required="true" requiredMessage="le champs et aubligatoire"/>
<h:outputLabel value="PASSOWRD"/>
<h:inputText value="#{intervenant.password}" required="true" requiredMessage="le champs et aubligatoire"/>
<h:outputLabel value="TYPE"/>
<h:inputText value="#{intervenant.type}" required="true" requiredMessage="le champs et aubligatoire"/>
<h:commandLink value="Update" action="afficherintervenant" actionListener="#{intervenant.ajouter()}"></h:commandLink>
</h:panelGrid>
</h:form>
</f:view>
</center>
</h:body>
</h:head>
</html> |
et enfin Modifier :
Code:
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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<h:body>
<center>
<f:view>
<h:form>
<h:panelGrid columns="2">
<!-- <h:outputLabel value="Intervenant ID"/> -->
<!-- <h:inputText value="#{intervenant.id_intervenant}" required="true" requiredMessage="le champs et aubligatoire"/> -->
<h:outputLabel value="LOGIN"/>
<h:inputText value="#{intervenant.login}" required="true" requiredMessage="le champs et aubligatoire"/>
<h:outputLabel value="PASSOWRD"/>
<h:inputText value="#{intervenant.password}" required="true" requiredMessage="le champs et aubligatoire"/>
<h:outputLabel value="TYPE"/>
<h:inputText value="#{intervenant.type}" required="true" requiredMessage="le champs et aubligatoire"/>
<h:commandLink value="Update" action="afficherintervenant" actionListener="#{intervenant.update()}"></h:commandLink>
</h:panelGrid>
</h:form>
</f:view>
</center>
</h:body>
</h:head>
</html> |
voici ma base de donnèe
Pièce jointe 211491