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... :'(
Version imprimable
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... :'(
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 :mouarf:
La page JSP
La TLDCode:
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>
Le TAGCode:
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>
Si ça peut t'aider...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 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; } }
Merci d'avoir repris du temps pour moi.
Ou est ce que tu as déclaré ton user.name?
Avec ça, tu as tout ce qu'il faut je pense...
face-config.xml
web.xmlCode:
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>
User.java (un peu complexe, je te l'accorde :mouarf:)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 <?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>
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 /******************************************************************************* * 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; } }
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
Non, session ou request, ça fonctionnera de la même manière...
ok :)
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
et du coupCode:
1
2
3
4
5
6
7
8 <bindings> <attributeValues id="ViewObj1ServerBaseUrl" IterBinding="ViewObj1Iterator"> <AttrNames> <Item Value="ServerBaseUrl"/> </AttrNames> </attributeValues> </bindings>
dans mon jsp
Code:
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
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 :ccool:
A+
Je connais déjà ! Ce site est sublime ! Vive AUDIARD !