IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

Problème affichage avec select option


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    136
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 136
    Par défaut Problème affichage avec select option
    bonjour

    j' ai un problème pour affiche le catégorie dans une liste de roulante merci
    pour votre aide

    voici le message d' erreur
    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
     
     java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'category' available as request attribute
    	at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
    	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:178)
    	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:198)
    	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:164)
    	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:151)
    	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:142)
    	at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:126)
    	at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421)
    	at org.springframework.web.servlet.tags.form.SelectTag.writeTagContent(SelectTag.java:199)
    	at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
    	at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
    	at org.apache.jsp.WEB_002dINF.views.categorylist_jsp._jspService(categorylist_jsp.java:137)
    	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
    	at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
    	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
    	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
    	at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:262)
    	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1180)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:147)
    	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
     
    nov. 09, 2013 2:20:18 PM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet [dispatcher] in context with path [] threw exception [An exception occurred processing JSP page /WEB-INF/views/categorylist.jsp at line 29
     
    26: 				<tr>
    27: 					<td> Category:</td>
    28: 					 <td> 
    29: 	                       <form:select path="name">
    30: 						        <c:forEach var="category" items="${categoryList}">   									        
    31: 					            	<form:option value="${category.id}">${category.name}</form:option>      
    32: 					            </c:forEach>
     
     
    Stacktrace:] with root cause
    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'category' available as request attribute
    	at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
    voici le fichier jsp

    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
     
     <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
    <%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
     
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Insert title here</title>
    </head>
    <body>
       <c:choose>
    			<c:when test="${category.id==null}">
    				Création 
    			</c:when>
    			<c:otherwise>
    				<title>Edit Category:${category.name}</title>
    			</c:otherwise>
    		</c:choose>
     <form:form commandName="category" method="post" action='<%=response.encodeUrl("/category/categorylist")%>'>
     
    		<fieldset>
    			<table>
    				<tr>
    					<td> Category:</td>
    					 <td> 
    	                       <form:select path="name">
    						        <c:forEach var="category" items="${categoryList}">   									        
    					            	<form:option value="${category.id}">${category.name}</form:option>      
    					            </c:forEach>
    		            	  </form:select>
    		            </td>
     
    				</tr>
     
    				<tr>
    				  <td><input type="submit"  value="<c:choose><c:when test="${category.id==null}">Add </c:when><c:otherwise>Edit Category</c:otherwise></c:choose>"/></td>
     
    				</tr>
    			</table>
    		</fieldset>
    		<a href="<c:url value='/'/>">home page</a><br/>
     
    </form:form>
    </body>
    </html>
    voici le contrôleur

    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
     
    package com.bbstore.controller;
     
    import java.util.List;
     
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;
     
    import com.bbstore.model.Category;
    import com.bbstore.repository.CategoryRepository;
     
    @Controller
    public class CategoryListController {
        @Autowired
        CategoryRepository categoryRepository;
     
        @RequestMapping("/categorylist")
        public ModelAndView categoryList() {
            ModelAndView mv = new ModelAndView("categorylist");
            List<Category> list = categoryRepository.findAll();
            mv.addObject("categoryList", list);
            return mv;
     
        }
     
    }
    voici la classe category
    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
     
    package com.bbstore.model;
     
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
     
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
    import javax.persistence.OrderBy;
     
    @Entity
    public class Category implements Serializable {
     
        /**
           */
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long Id;
        private String name;
        private String description;
     
     
        @OneToMany(mappedBy = "category",fetch = FetchType.LAZY)
        private List<Product> product = new ArrayList<Product>();
     
        public Category() {
            super();
        }
     
        public Category(String name, String description, List<Product> product) {
            super();
            this.name = name;
            this.description = description;
            this.product = product;
        }
     
        public Long getId() {
            return Id;
        }
     
        public void setId(Long id) {
            Id = id;
        }
     
        public String getName() {
            return name;
        }
     
        public void setName(String name) {
            this.name = name;
        }
     
        public String getDescription() {
            return description;
        }
     
        public void setDescription(String description) {
            this.description = description;
        }
     
        public List<Product> getProduct() {
            return product;
        }
     
        public void setProduct(List<Product> product) {
            this.product = product;
        }
     
    }

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Bonjour,

    Code jsp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <c:forEach var="category" items="${categoryList}">
               <c:choose>
    			<c:when test="${category.id==null}">
    				Création 
    			</c:when>
    			<c:otherwise>
    				<title>Edit Category:${category.name}</title>
    			</c:otherwise>
    		</c:choose>
    </forEach>

    A+.

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    136
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 136
    Par défaut for servlet [dispatcher] in context with path [] threw exception [An exception occurred processing JSP page /W
    Citation Envoyé par andry.aime Voir le message
    Bonjour,

    Code jsp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <c:forEach var="category" items="${categoryList}">
               <c:choose>
    			<c:when test="${category.id==null}">
    				Création 
    			</c:when>
    			<c:otherwise>
    				<title>Edit Category:${category.name}</title>
    			</c:otherwise>
    		</c:choose>
    </forEach>

    A+.
    merci pour ton aide mais le problème viens pas de là

    voici le message d 'erreur

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/categorylist.jsp at line 22
     
    19: 				<tr>
    20: 					<td> Category:</td>
    21: 					 <td> 
    22: 	                       <form:select path="category.name">
    23: 						        <c:forEach var="category" items="${categoryList}">   									        
    24: 					            	<form:option value="${category.id}">${category.name}</form:option>      
    25: 					            </c:forEach>
    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
     
    <form:form commandName="category" method="post" action='<%=response.encodeUrl("/category/categorylist")%>'>
     
    		<fieldset>
    			<table>
    				<tr>
    					<td> Category:</td>
    					 <td> 
    	                       <form:select path="name">
    						        <c:forEach var="category" items="${categoryList}">   									        
    					            	<form:option value="${category.id}">${category.name}</form:option>      
    					            </c:forEach>
    		            	  </form:select>
    		            </td>
     
    				</tr>
     
    				<tr>
    				  <td><input type="submit"  value="<c:choose><c:when test="${category.id==null}">Add </c:when><c:otherwise>Edit Category</c:otherwise></c:choose>"/></td>
     
    				</tr>
    			</table>
    		</fieldset>
    		<a href="<c:url value='/'/>">home page</a><br/>
     
    </form:form>

  4. #4
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    Bonjour,

    J'ai mal lu ton code quand tu l'as posté sans les balises.
    En revenant sur les premiers codes postés, tu n'as pas ajouté d'attribut "categorie" dans ton ModelAndView. Donc c'est pas connu à cette ligne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <c:when test="${category.id==null}">
    Il faut faire attention aussi au NullPointerException.

    A+.

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    136
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 136
    Par défaut Neither BindingResult nor plain target object for bean name 'category' available as request attribute
    Citation Envoyé par andry.aime Voir le message
    Bonjour,

    J'ai mal lu ton code quand tu l'as posté sans les balises.
    En revenant sur les premiers codes postés, tu n'as pas ajouté d'attribut "categorie" dans ton ModelAndView. Donc c'est pas connu à cette ligne:

    Il faut faire attention aussi au NullPointerException.

    A+.
    Bonjour
    l'erreur viens pas là c'est à la ligne 21 voici le code après modification

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/categorylist.jsp at line 21
     
    18: 			
    19: 	<table border="1" cellspacing="1">
    20: 	   <tr>
    21: 	    <form:select path="name">
    22: 		     <c:forEach var="category" items="${categoryList}">   									        
    23: 			    <form:option value="${category.id}">${category.name}</form:option>      
    24: 			</c:forEach>
    message d'erreur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    cause mère
     
    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'category' available as request attribute
    	org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
    	org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:178)
    	org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:198)
    	org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:164)
    	org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:151)
    	org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:142)
    	org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:126)
    	org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:421)
    	org.springframework.web.servlet.tags.form.SelectTag.writeTagContent(SelectTag.java:199)

  6. #6
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Par défaut
    J'ai du mal à suivre ton code que tu modifies à chaque post:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    <form:select path="category.name"> <!-- la variable category n'est pas encore accessible sur cette ligne, d'où l'erreur, parce que tu n'as pas l'attribut categorie dans ton ModelAndView -->
      <c:forEach var="category" items="${categoryList}"> <!-- Une variable local category est créée ici qui ne sera visible que dans la boucle forEach -->
    J’espère que tu comprends maintenant pourquoi tu as l'erreur.

    A+.

Discussions similaires

  1. Réponses: 3
    Dernier message: 20/05/2011, 12h51
  2. Problème avec select-options
    Par donjuan dans le forum SAP
    Réponses: 8
    Dernier message: 07/03/2011, 17h47
  3. Problème affichage avec ATI Mobility FireGL v3200
    Par MoDDiB dans le forum NxEngine
    Réponses: 2
    Dernier message: 25/06/2007, 09h33
  4. Problème affichage avec MSN
    Par CLion dans le forum Messagerie instantanée
    Réponses: 4
    Dernier message: 11/12/2006, 16h45
  5. [PHP-JS] Problème affichage avec structure if
    Par kitty2006 dans le forum Langage
    Réponses: 31
    Dernier message: 07/09/2006, 18h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo