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

Taglibs Java Discussion :

Attribut n'interprete pas l'EL [Custom Tags 2.0]


Sujet :

Taglibs Java

  1. #21
    Membre éprouvé Avatar de raOOn
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    100
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Décembre 2006
    Messages : 100
    Par défaut
    arg ! Merci quand meme ! Je galère je comprends vraiment pas pourquoi ca marche pas... grr grr grr ! J'ai manqué un truc mais quoi... :'(

  2. #22
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Bon, finalement, j'ai refait un petit projet de test et... ça fonctionne...
    Il y a quand même un petit bémol, il faut utiliser le caractère EL '$' au lieu de '#'

    L'exemple est over basic MAIS il fonctionne
    La page 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
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="/WEB-INF/demo.tld" prefix="d"%>
    
    <f:loadBundle var="Message" basename="demo.Messages" />
    
    <html>
        <head>
            <title>Hello!</title>
        </head>
    
        <body>
            <f:view>
                <h3>
                    <h:outputText value="#{Message.hello_message}" />,
                    <h:outputText value="#{user.name}" />!
                </h3>
                
                <div>
                    <d:hello nom="${user.name}"/>                
                </div>
            </f:view>
        </body>
    </html>
    La TLD
    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
     
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <taglib xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee">
        <tlib-version>1.0</tlib-version>
         <short-name>layout</short-name>
         <uri>/WEB-INF/demo.tld</uri>
     <tag>
      <name>hello</name>
      <tag-class>demo.HelloTag</tag-class>
      <body-content>empty</body-content>
      <attribute>
       <name>nom</name>
       <required>true</required>
       <rtexprvalue>true</rtexprvalue>
      </attribute>
     </tag>
    </taglib>
    Le TAG
    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
     
    package demo;
     
    import javax.servlet.jsp.JspException;
    import javax.servlet.jsp.tagext.TagSupport;
     
    public class HelloTag extends TagSupport
    {
        private static final long serialVersionUID = 1;
        private String nom;
     
        public String getNom()
        {
            return nom;
        }
     
        public void setNom(String text)
        {
            this.nom = text;
        }
     
        @Override
        public int doEndTag() throws JspException
        {
            try
            {
                pageContext.getOut().write("Bonjour <b>" + getNom() + "</b>");
            }
            catch (Exception e)
            {
                System.out.println("ERROR : " + e.toString());
            }
            return EVAL_PAGE;
        }    
    }
    Si ça peut t'aider...
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  3. #23
    Membre éprouvé Avatar de raOOn
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    100
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Décembre 2006
    Messages : 100
    Par défaut
    Merci d'avoir repris du temps pour moi.

    Ou est ce que tu as déclaré ton user.name?

  4. #24
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Avec ça, tu as tout ce qu'il faut je pense...

    face-config.xml
    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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xi="http://www.w3.org/2001/XInclude"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
     <managed-bean>
      <description>User Name Bean</description>
      <managed-bean-name>user</managed-bean-name>
      <managed-bean-class>demo.User</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
      <managed-property>
       <property-name>name</property-name>
       <property-class>java.lang.String</property-class>
       <value/>
      </managed-property>
     </managed-bean>
     <navigation-rule>
      <from-view-id>/pages/inputUserName.jsp</from-view-id>
      <navigation-case>
       <from-outcome>hello</from-outcome>
       <to-view-id>/pages/hello.jsp</to-view-id>
      </navigation-case>
     </navigation-rule>
     <application>
      <locale-config/>
     </application>
     <factory/>
     <lifecycle/>
    </faces-config>
    web.xml
    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
     
    <?xml version="1.0"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
     <display-name>Jsf1</display-name>
     <context-param>
      <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
      <param-value>server</param-value>
     </context-param>
     <listener>
      <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
     </listener>
     <!-- Faces Servlet -->
     <servlet>
      <servlet-name>Faces Servlet</servlet-name>
      <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
     </servlet>
     <!-- Faces Servlet Mapping -->
     <servlet-mapping>
      <servlet-name>Faces Servlet</servlet-name>
      <url-pattern>*.jsf</url-pattern>
     </servlet-mapping>
     <login-config>
      <auth-method>BASIC</auth-method>
     </login-config>
    </web-app>
    User.java (un peu complexe, je te l'accorde )
    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
     
    /*******************************************************************************
     * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
     * Distributed under license by Red Hat, Inc. All rights reserved.
     * This program is made available under the terms of the
     * Eclipse Public License v1.0 which accompanies this distribution,
     * and is available at http://www.eclipse.org/legal/epl-v10.html
     *
     * Contributors:
     *     Exadel, Inc. and Red Hat, Inc. - initial API and implementation
     ******************************************************************************/ 
    package demo;
     
    /**
     * Created by JBoss Developer Studio
     */
    public class User {
     
        private String name;
     
        /**
         * @return User Name
         */
        public String getName() {
            return name;
        }
     
        /**
         * @param User Name
         */
        public void setName(String name) {
            this.name = name;
        }
    }
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  5. #25
    Membre éprouvé Avatar de raOOn
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    100
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Décembre 2006
    Messages : 100
    Par défaut
    Bonjour,

    Je suis en train de refaire un projet test, je me dis qu'en repartant de zéro ca sera peut etre mieux...

    Par contre dans ton exemple, tu utilises un session scope, du coup ta variable ne doit pas etre traité de la meme manière nan?

    Merci en tout cas ! Je posterai mon avancement !

    Bonne journée

  6. #26
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    Non, session ou request, ça fonctionnera de la même manière...
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  7. #27
    Membre éprouvé Avatar de raOOn
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    100
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Décembre 2006
    Messages : 100
    Par défaut
    ok

  8. #28
    Membre éprouvé Avatar de raOOn
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    100
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Décembre 2006
    Messages : 100
    Par défaut
    Bon bin j'ai réussi....

    J'ai fait différemment du coup... Au lieu de passer par une méthode Action, j'ai utilisé un attributeValues

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    <bindings>
        <attributeValues id="ViewObj1ServerBaseUrl" IterBinding="ViewObj1Iterator">
          <AttrNames>
            <Item Value="ServerBaseUrl"/>
          </AttrNames>
        </attributeValues>
      </bindings>
    et du coup

    dans mon jsp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <taglib1:Tag1 ServerBaseUrl="${bindings.ViewObj1ServerBaseUrl.inputValue}"/>

    et ca marche...

    Merci pour tout quand meme ! Tu m'as éclairci le schmilblick à maintes reprises !
    Bonne journée
    Cordialement,
    Vincent

  9. #29
    Modérateur
    Avatar de OButterlin
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    7 313
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 7 313
    Billets dans le blog
    1
    Par défaut
    De rien...

    En passant, comme tu sembles fan des Tontons, je suis tombé sur cette retranscription de cette scène absolument légendaire, un régal

    A+
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java

  10. #30
    Membre éprouvé Avatar de raOOn
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    100
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Décembre 2006
    Messages : 100
    Par défaut
    Je connais déjà ! Ce site est sublime ! Vive AUDIARD !

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. [PHP 5.3] [POO] Comment afficher le nom de l'attribut et non pas sa valeur
    Par pierrot10 dans le forum Langage
    Réponses: 5
    Dernier message: 28/03/2010, 21h59
  2. Facelets n'interprete pas le code
    Par rushtakn dans le forum JSF
    Réponses: 4
    Dernier message: 16/06/2009, 22h21
  3. Réponses: 2
    Dernier message: 11/11/2007, 16h49
  4. html:checkbox qui n'interprete pas un attribut
    Par gloglo dans le forum Struts 1
    Réponses: 1
    Dernier message: 20/03/2007, 10h03
  5. [POO] La valeur de l'attribut ne change pas...
    Par slydemusli dans le forum Langage
    Réponses: 3
    Dernier message: 26/03/2006, 12h10

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