Pb javax.annotation.Named Target Unreachable, identifier
Bonjour,
J'ai crée un projet, dont le nom est Postage, via webProject, sous eclipse galilleo.
Les caracteristiques du Porjets sont
JSF 1.2
servlet version 2.5
lors de la declaration du serveur c'est JBOSS 5.0 (il ne me propose pas 5.1)
le serveur est JBoss 5.1
je demande l'adresse http://localhost:8080/Postage/getrequest.jsf, j'obtient le formulaire.
quand je valide le formulaire getrequest.xhtml (j'appui sur le bouttton commande) j'obtient le message suivant :
//******************************************************************************
Voici le messge d'erreur
13:22:23,972 WARNING [lifecycle] /getrequest.xhtml @27,63 value="#{r.weight}": Target Unreachable, identifier 'r' resolved to null
javax.el.PropertyNotFoundException: /getrequest.xhtml @27,63 value="#{r.weight}": Target Unreachable, identifier 'r' resolved to null
at com.sun.facelets.el.TagValueExpression.getType(TagValueExpression.java:62)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:92)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:942)
at javax.faces.component.UIInput.validate(UIInput.java:868)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1072)
at javax.faces.component.UIInput.processValidators(UIInput.java:672)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
at javax.faces.component.UIForm.processValidators(UIForm.java:235)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:700)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
//***********************************************************
voici le contenue de la classe annoté
import javax.annotation.Named;
import javax.context.RequestScoped;
import javax.inject.Current;
@Named("r")
@RequestScoped
public class Request {
private int weight;
private String patronCode;
@Current
private PostageService postageService;
public Request() {
}
// les getter et setter existe mais pas afficher ici
}
//**********************************************************
une partie du fichier getrequest.xhtml
<h:form id="f">
<h:panelGrid columns="2">
<h:outputText value="Weight:" />
<h:panelGroup>
<h:inputText id="w" value="#{r.weight}" label="weight"
required="true"
validatorMessage="weight cannot be negative!">
<f:validateLongRange minimum="0" />
</h:inputText>
<h:message for="w" errorClass="c1" />
</h:panelGroup>
<h:outputText value="Patron code:" />
<h:inputText value="#{r.patronCode}">
<x:validatePatron />
</h:inputText>
<h:outputText value="" />
<h:commandButton action="ok" value="OK">
<f:actionListener type="postage.RequestValidatingListener"/>
</h:commandButton>
</h:panelGrid>
</h:form>
//**********************************************************
le contenue de faces-config.xml
<faces-config 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-facesconfig_2_0.xsd"
version="2.0">
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<message-bundle>postage.resources</message-bundle>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>fr_FR</supported-locale>
</locale-config>
</application>
<navigation-rule>
<from-view-id>/getrequest.xhtml</from-view-id>
<navigation-case>
<from-outcome>ok</from-outcome>
<to-view-id>/showpostage.xhtml
</to-view-id>
</navigation-case>
</navigation-rule>
<validator>
<validator-id>foo.v1</validator-id>
<validator-class>postage.PatronValidator</validator-class>
</validator>
</faces-config>
//**************************************
contenue de web.xml
<?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>Postage</display-name>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>2</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>
//***************************************
le contenue de WEB-INF/lib
common-annotations.jar
commons-beanutils.jar
commons-collections.jar
commons-digester.jar
commons-logging.jar
jsf-facelets.jar
jsf-tlds.jar
jstl.jar
standard.jar
Je n'ai pas declaré un Managed Bean car j'utilise l'annotation.
Je vous remercie d'avance.
annotation JSR299 a pour d'injecter les ressources ? est que je me trompe ?
Merci pour ta reponse;
Pour information ce sont des exemples issu d'un livre Beginning JSF et JBoss Seam
http://www.apress.com/book/view/143021922x
C'est le chapitre 3 qui ne marche pas.
Je commence avec JSF, mais je pense que le but des annotation JSR299 est justement de laisser le serveur d'injecter les resources necessaire. dans mon cas un Java beans. D'ailleurs j'ai un autre projet, (chap 2) que j'ai fait de la meme manière que ce qui coince dans le quel je ne declare aucun javabeans, mais il le trouve bien mon b1
exemple qui marche (chap2)
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
| //**********************************************
faces-config.xml
<faces-config 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-facesconfig_2_0.xsd"
version="2.0">
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<message-bundle>stock.messages</message-bundle>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>fr</supported-locale>
<supported-locale>de</supported-locale>
<supported-locale>zh</supported-locale>
</locale-config>
</application>
<navigation-rule>
<from-view-id>/getsymbol.xhtml</from-view-id>
<navigation-case>
<from-outcome>ok</from-outcome>
<to-view-id>/stockvalue.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config> |
le premier formulaire getsymbol.xhtml
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| <h:form>
<h:selectOneMenu value="#{b1.sym}" required="true" label="Stock symbole">
<f:selectItems value="#{b2.symbols}"/>
</h:selectOneMenu>
<h:inputText value="#{b1.quoteDate}" required="true"
label="Quote Date">
on
<f:convertDateTime dateStyle="short"/>
</h:inputText>
<h:commandButton action="ok"></h:commandButton>
</h:form> |
le deuxieme formulaire qui affiche bien les infos stockvalue.xhtml
Code:
1 2 3 4 5 6
| <f:view>
<h:form>
<h:outputText value="#{b1.stockValue}"></h:outputText>
<h:outputText value="#{b1.quoteDate}"></h:outputText>
</h:form>
</f:view> |
le code qui permet de declarer et de mettre à disposition b1 dans le context request
Code:
1 2 3 4 5 6 7 8
| @Named("b1")
@RequestScoped
public class QuoteRequest {
private String sym="MSFT";
private Date quoteDate=new Date();
@Current private StockService stkSrv;
// getter et setter
} |
encore Merci pour tous