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

JSF Java Discussion :

Important probleme dans l'utilisation des commandLink


Sujet :

JSF Java

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Août 2007
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 3
    Points : 2
    Points
    2
    Par défaut Important probleme dans l'utilisation des commandLink
    Je suis debutante au niveau java server faces
    J'ai créé une appli avec les frameworks spring, hibernate et java server faces à l'aide de netbeans 6.
    Les librairies utilisées sont les suivantes :
    spring et java server faces : utilisation des librairie intégrées dans netbeans
    Hibernate : import manuel des librairies.

    Ma page JSP liste un ensemble de categories et doit permettre de basculer vers la page d'édition d'une categorie
    Voici le code pour la 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
     
    <h:dataTable value="#{CategoryBean.categories}" var="category">
                        <h:column>
    				<f:facet name="header">
    					<h:outputText value="Title" />
    				</f:facet>
    				<h:outputText value="#{category.categoryid}" />
    			</h:column>
    			<h:column>
    				<f:facet name="header">
    					<h:outputText value="Body" />
    				</f:facet>
    				<h:outputText value="#{category.categoryname}" />
    			</h:column>
    			<h:column>
    				<f:facet name="header">
    					<h:outputText value="Update" />
    				</f:facet>
                             <h:commandLink action="#{category.doPrepapareEditCategory}">
                                    <h:outputText value="Edit"/>
                                <f:param value="#{category.categoryid}" name="categoryId"  />
                            </h:commandLink>
                                    <%--<h:outputLink value="editCategory.jsf">
     
    					<h:outputText value="Edit" />
    					<f:param value="#{category.categoryid}" name="categoryId"  />
    				</h:outputLink >
                                    --%>
    			</h:column>
    			<h:column>
    				<f:facet name="header">
    					<h:outputText value="Delete" />
    				</f:facet>
    				<h:outputLink  value="showcategories.jsf">
    					<h:outputText value="Delete" />
    					<f:param  value="#{category.categoryid}" name="categoryId" />
    				</h:outputLink >
    			</h:column>
                    </h:dataTable>
    Le code du backin bean est :
    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
    public class CategoryBean extends BaseBean {
        //list of all the product backing beans
    	private List categories=null;
    	private Category category;
            private BusinessEntityService commonService;
     
        public CategoryBean() {
            this.logger.debug("Category Bean is created");
            category=new Category();
        }
     
        public Category getCategory() {
            return this.category;
        }
     
        // permet de rechercher toutes les catégroies
        public String dofindCategories(){
            if (categories == null) {
                try {
     
                    this.logger.debug("############# categories null --> commonService.getAllCategories");
                    categories = commonService.getAllCategories();
                } catch (BusinessEntityException ex) {
                    Logger.getLogger("global").log(Level.SEVERE, null, ex);
                     return NavigationResults.FAILURE;
                }
     
            }
             //return  NavigationResults.CATEGORY_LIST;
            return NavigationResults.CATEGORY_LIST;
        }
     
       public String doPrepapareEditCategory(){
            try {
                category = commonService.getCategory(getParamId("categoryId"));
     
                //return  NavigationResults.CATEGORY_LIST;
     
            } catch (BusinessEntityException ex) {
                Logger.getLogger("global").log(Level.SEVERE, null, ex);
                return NavigationResults.FAILURE;
            }
            return NavigationResults.EDIT_CATEGORY;
        }
     
     
         public String doUpdateCategory(){
             this.logger.debug("#DDD############ updateToDoAction()");
            try {
     
                this.commonService.updateCategory(this.category);
                this.logger.debug("#DDD############ updateCategoryAction->success");
     
               } catch (BusinessEntityException ex) {
                Logger.getLogger("global").log(Level.SEVERE, null, ex);
                 return NavigationResults.FAILURE;
            }
              return NavigationResults.EDIT_CATEGORY;
         }
     
     
         public String deleteCategoryAction(){
            try {
                this.commonService.deleteCategory(this.category);
                this.logger.debug("#DDD############ deleteCategoryAction->success");
            } catch (BusinessEntityException ex) {
                Logger.getLogger("global").log(Level.SEVERE, null, ex);
                return NavigationResults.FAILURE;
            }
             return NavigationResults.SUCCESS;
     
         }
     
        public List getCategories(){
     
            return categories;
        }
     
       /* public BusinessEntityService getCommonService() {
            this.logger.debug("############# getting BusinessEntityService");
            return commonService;
        }*/
     
        public void setCommonService(BusinessEntityService commonService) {
            this.commonService = commonService;
        }
     
     
    }

    Le code de la classe Category est ( hibernate)
    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
    public class Category {
        //private int categoryid;
        private Integer categoryid;
        private String categoryname;
     
        public Category() {
        }
     
        public Integer getCategoryid() {
            return categoryid;
        }
     
        // private car generé par le conteneur
        private void setCategoryid(Integer categoryid) {
            this.categoryid = categoryid;
        }
     
        public String getCategoryname() {
            return categoryname;
        }
     
        public void setCategoryname(String categoryname) {
            this.categoryname = categoryname;
        }
     
    }
    Voici l'erreur :
    -------------------------------------------------------------
    ------------------------------------------------------------
    When loadin the jsf page i have the following errors messages :

    2 août 2007 20:10:07 org.apache.catalina.core.StandardWrapperValve invoke
    GRAVE: "Servlet.service()" pour la servlet Faces Servlet a généré une exception
    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
    at com.sun.rave.web.ui.appbase.renderer.CommandLinkRenderer.encodeBegin(CommandLinkRenderer.java:214)
    at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:785)
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:269)
    at com.sun.faces.renderkit.html_basic.TableRenderer.encodeChildren(TableRenderer.java:307)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:809)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:809)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
    at com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:244)
    at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:175)
    at com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.renderView(ViewHandlerImpl.java:298)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:619)
    --------------------------------------------------------------
    Apparemment commandLink ne sait pas convertir Integer en String.
    Comment résoudre ce problème?
    L'implémentation JSf est celle de sun

    manifest du jsf-api.jar :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.6.5
    Created-By: 1.5.0_04-b05 (Sun Microsystems Inc.)
    Specification-Title: JavaServer Faces
    Specification-Version: 1.2MR1
    Implementation-Title: Sun Microsystems JavaServer Faces Implementation
    Implementation-Version: 1.2_04-b10-p01
    Implementation-Vendor: Sun Microsystems, Inc.
    Implementation-Vendor-Id: com.sun
    Extension-Name: javax.faces
    Manifest du jsf-impl.jar :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Manifest-Version: 1.0
    Ant-Version: Apache Ant 1.6.5
    Created-By: 1.5.0_04-b05 (Sun Microsystems Inc.)
    Specification-Title: JavaServer Faces
    Specification-Version: 1.2MR1
    Implementation-Title: Sun Microsystems JavaServer Faces Implementation
    Implementation-Version: 1.2_04-b10-p01
    Implementation-Vendor: Sun Microsystems, Inc.
    Implementation-Vendor-Id: com.sun
    Extension-Name: com.sun.faces
    J'utilise Tomcat 6.0.13

  2. #2
    Membre averti Avatar de Philcmoi
    Homme Profil pro
    Inscrit en
    Juillet 2006
    Messages
    632
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Juillet 2006
    Messages : 632
    Points : 405
    Points
    405
    Par défaut
    Je crois que l'erreure n'est pas dans le code que tu as donner.
    l'erreure est signaler par "java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String"

    tu a du faire String qqchose = (String) autrechose qui est un Integer.

    Il faut que tu fasses :
    String qqchose = autrechose.toString();

    voila, mais pourquoi tu dis que tu est débutante tu te débrouille mieux que moi dans les DataTable et leur code. Si tu as un tutorial à me proposer sur les composants jsf, je suis preneur. Merci.

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Août 2007
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2007
    Messages : 3
    Points : 2
    Points
    2
    Par défaut
    dans la ligne suivante :
    <f:param value="#{category.categoryid}" name="categoryId" />

    je récupère getCategoryId() du pojo Category.
    Or getCategoryId() retourne un integer.
    Mon POJO est sensé mapper une table dans laquelle categoryId est un Integer ( c'est la clé primaire de ma table category.

    Je ne veux pas modifier mon POJO.

    Autre indication : si
    je fais cecie je n'ai pas d'erreur au chargement de ma page, l'erreur survient seulement quand je manipule un commandLink :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    <h:outputLink value="editCategory.jsf">
     
    					<h:outputText value="Edit" />
    					<f:param value="#{category.categoryid}" name="categoryId"  />
    				</h:outputLink >

    Autres informations:
    je suis vraiment débutante. J'apprend toute seule les JSF à raison de quelqes heurs chaque soir depuis le début juillet.
    Je me sert de docs sur le net tels que :
    - le site roseindia
    - l'article "put jsf to work"
    - le tutorial JSF de sun

Discussions similaires

  1. Réponses: 2
    Dernier message: 08/06/2010, 22h40
  2. [FPDF] Probleme dans l'utilisation de la classe FPDF et les tableaux
    Par mathieu77186 dans le forum Bibliothèques et frameworks
    Réponses: 3
    Dernier message: 24/04/2008, 22h03
  3. probleme dans le recuperation des carectres speciaux : é,è à
    Par abdou.sahraoui dans le forum Oracle
    Réponses: 20
    Dernier message: 28/10/2005, 16h59
  4. [HTML][FORMULAIRE] Probleme dans la récupération des données
    Par baddounet dans le forum Balisage (X)HTML et validation W3C
    Réponses: 6
    Dernier message: 15/08/2005, 18h51
  5. [TP]Problème dans la gestion des touches d'un tetris
    Par Guile0 dans le forum Turbo Pascal
    Réponses: 18
    Dernier message: 31/01/2005, 22h40

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