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 :

[Facelets] probleme type attributs


Sujet :

JSF Java

  1. #1
    Membre habitué
    Développeur informatique
    Inscrit en
    Juillet 2007
    Messages
    167
    Détails du profil
    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2007
    Messages : 167
    Points : 143
    Points
    143
    Par défaut [Facelets] probleme type attributs
    Bonjour,
    Je réalise un composant qui me permettra de simplifier la tâche de création de page web.
    Pour l'instant je bloque lors de la récupération de la valeur des attributs du composant.
    Lorsque un attribut est de type String, j'ai une belle exception.
    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
    java.lang.IllegalArgumentException: Cannot convert toto of type class java.lang.String to class javax.el.ValueExpression
    	at org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:380)
    	at org.apache.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:46)
    	at com.sun.facelets.tag.BeanPropertyTagRule$LiteralPropertyMetadata.applyMetadata(BeanPropertyTagRule.java:45)
    	at com.sun.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:36)
    	at com.sun.facelets.tag.MetaTagHandler.setAttributes(MetaTagHandler.java:62)
    	at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:144)
    	at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
    	at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
    	at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
    	at com.sun.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:64)
    	at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:131)
    	at com.sun.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:310)
    	at com.sun.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:280)
    	at com.sun.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:68)
    	at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
    	at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
    	at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
    	at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
    	at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:248)
    	at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:294)
    	at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:273)
    	at com.sun.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:144)
    	at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:113)
    	at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
    	at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
    	at com.sun.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:95)
    	at com.sun.facelets.FaceletViewHandler.buildView(FaceletViewHandler.java:524)
    	at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:567)
    	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)
    	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
    	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    	at java.lang.Thread.run(Thread.java:619)
    +- Component Tree
    <UIViewRoot locale="fr" renderKitId="HTML_BASIC" rendered="true" transient="false" viewId="/proxy.xhtml">
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>Facelets: Number Guess Tutorial</title> <style type="text/css"> <!-- body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small; } --> </style> </head> <body> <h1>
    </h1> <p>
    </UIViewRoot>
    Ce qui n'est pas le cas s'il s'agit de type ValueExpression (${bean.property}). Mais cela ne foncionne pas pour autant car, j'ai un log dans la console qui me dit que le label est vide...
    Quels sont mes erreurs? Merci d'avance pour votre aide et vos commentaires
    JD

    Voici le source de ma page xhtml
    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
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:tm="http://ui.proxy.com/sample">
    <body>
    <ui:composition template="/template.xhtml">
        <ui:define name="title"></ui:define>
        <ui:define name="body">
            <h:form id="helloForm">
                <h:inputText value="#{samplebean.myDate}"></h:inputText><br/>
                <tm:input type="checkbox" label="#{samplebean.myDate}" ></tm:input><br/>
                <tm:input type="date" value="#{samplebean.myDate}"></tm:input><br/>
                <h:commandButton type="submit" id="submit" action="success" value="Submit"/>
            </h:form>
        </ui:define>
        This text will not be displayed.
    </ui:composition>
    </body>
    </html>
    Voici le code java de ce composant
    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 UIIProxy extends UIIHtmlCommons {
        //   public static final String COMPONENT_TYPE = "javax.faces.Input";
        private String type;
        private ValueExpression label;
        private ValueExpression data;
        private ValueExpression value;
     
        public UIIProxy() {
    //        FacesContext.getCurrentInstance();
    //        this.label = (ValueExpression) getAttributes().get("label");
     
        }
     
        public String getFamily() {
            return "ui.proxy";
        }
        public String getRendererType(){
            return null;
        }
     
        public void decode(FacesContext context) {
            List<UIComponent> children = this.getChildren();
            for (UIComponent child : children)
                if (child instanceof HtmlInputHidden)
                    type = (String) ((HtmlInputHidden) child).getValue();
     
        }
     
        void setUIInputChildren() {
            if (!getChildren().isEmpty())
                return;
            UIInputFactory factory = new UIInputFactory();
            UIInput input = factory.getUIInput(type);
            if (input == null) {
                System.out.println("no input, input is null.");
                return;
            }
            List<UIComponent> children = getChildren();
            HtmlInputHidden h = new HtmlInputHidden();
            HtmlOutputLabel l = null;
            children.add(h);
            if (label != null) {
                l = new HtmlOutputLabel();
                if (label instanceof ValueExpression)
                    l.setValueExpression("value", (ValueExpression) label);
                else
                    l.setValue(label);
            } else {
                System.out.println("label not set for component");
            }
            h.setValue(type);
     
            children.add(input);
            input.setValueExpression("value", value);
            if (factory.getLabelPosition() > 0 && l != null) {
                children.add(l);
            }
     
        }
     
        public String getType() {
            return type;
        }
     
        public void setType(String type) {
            this.type = type;
        }
     
        public ValueExpression getData() {
            return data;
        }
     
        public void setData(ValueExpression data) {
            this.data = data;
        }
     
        public ValueExpression getValue() {
            return value;
        }
     
        public void setValue(ValueExpression value) {
            System.out.println("value is " + value);
            this.value = value;
        }
     
        public void setLabel(ValueExpression label) {
            this.label = label;
        }
    }
    qui extend
    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
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    public abstract class UIIHtmlCommons extends UIComponentBase {
        protected String accesskey;
        protected String alt;
        protected String lang;
        protected int maxlength;
        protected String onblur;
        protected String onchange;
        protected String onclick;
        protected String ondblclick;
        protected String onfocus;
        protected String onkeydown;
        protected String onkeypress;
        protected String onkeyup;
        protected String onmousedown;
        protected String onmousemove;
        protected String onmouseout;
        protected String onmouseover;
        protected String onmouseup;
        protected String onselect;
        protected int size;
        protected String style;
        protected String styleClass;
        protected String tabindex;
        protected String title;
    //    protected ValueExpression autocomplete;
    //    protected ValueExpression converter;
    //    protected ValueExpression converterMessage;
    //    protected ValueExpression dir;
    //    protected ValueExpression disabled;
    //    protected ValueExpression immediate;
    //    protected ValueExpression readonly;
    //    protected ValueExpression required;
    //    protected ValueExpression requiredMessage;
     
    //    protected ValueExpression validatorMessage;
    //    protected MethodExpression validator;
    //    protected MethodExpression valueChangeListener;
     
        abstract void setUIInputChildren();
     
        public UIIHtmlCommons() {
        }
     
        public void encodeBegin(FacesContext context) throws IOException {
            setUIInputChildren();
            super.encodeBegin(context);
        }
     
        public String getDebugString() {
            return (new StringBuilder()).append("id: ").append(getId()).append(" class: ").append(getClass().getName()).toString();
        }
     
        public String getAccesskey() {
            return accesskey;
        }
     
        public void setAccesskey(String accesskey) {
            this.accesskey = accesskey;
        }
     
        public String getAlt() {
            return alt;
        }
     
        public void setAlt(String alt) {
            this.alt = alt;
        }
     
        public String getLang() {
            return lang;
        }
     
        public void setLang(String lang) {
            this.lang = lang;
        }
     
        public int getMaxlength() {
            return maxlength;
        }
     
        public void setMaxlength(int maxlength) {
            this.maxlength = maxlength;
        }
     
        public String getOnblur() {
            return onblur;
        }
     
        public void setOnblur(String onblur) {
            this.onblur = onblur;
        }
     
        public String getOnchange() {
            return onchange;
        }
     
        public void setOnchange(String onchange) {
            this.onchange = onchange;
        }
     
        public String getOnclick() {
            return onclick;
        }
     
        public void setOnclick(String onclick) {
            this.onclick = onclick;
        }
     
        public String getOndblclick() {
            return ondblclick;
        }
     
        public void setOndblclick(String ondblclick) {
            this.ondblclick = ondblclick;
        }
     
        public String getOnfocus() {
            return onfocus;
        }
     
        public void setOnfocus(String onfocus) {
            this.onfocus = onfocus;
        }
     
        public String getOnkeydown() {
            return onkeydown;
        }
     
        public void setOnkeydown(String onkeydown) {
            this.onkeydown = onkeydown;
        }
     
        public String getOnkeypress() {
            return onkeypress;
        }
     
        public void setOnkeypress(String onkeypress) {
            this.onkeypress = onkeypress;
        }
     
        public String getOnkeyup() {
            return onkeyup;
        }
     
        public void setOnkeyup(String onkeyup) {
            this.onkeyup = onkeyup;
        }
     
        public String getOnmousedown() {
            return onmousedown;
        }
     
        public void setOnmousedown(String onmousedown) {
            this.onmousedown = onmousedown;
        }
     
        public String getOnmousemove() {
            return onmousemove;
        }
     
        public void setOnmousemove(String onmousemove) {
            this.onmousemove = onmousemove;
        }
     
        public String getOnmouseout() {
            return onmouseout;
        }
     
        public void setOnmouseout(String onmouseout) {
            this.onmouseout = onmouseout;
        }
     
        public String getOnmouseover() {
            return onmouseover;
        }
     
        public void setOnmouseover(String onmouseover) {
            this.onmouseover = onmouseover;
        }
     
        public String getOnmouseup() {
            return onmouseup;
        }
     
        public void setOnmouseup(String onmouseup) {
            this.onmouseup = onmouseup;
        }
     
        public String getOnselect() {
            return onselect;
        }
     
        public void setOnselect(String onselect) {
            this.onselect = onselect;
        }
     
        public int getSize() {
            return size;
        }
     
        public void setSize(int size) {
            this.size = size;
        }
     
        public String getStyle() {
            return style;
        }
     
        public void setStyle(String style) {
            this.style = style;
        }
     
        public String getStyleClass() {
            return styleClass;
        }
     
        public void setStyleClass(String styleClass) {
            this.styleClass = styleClass;
        }
     
        public String getTabindex() {
            return tabindex;
        }
     
        public void setTabindex(String tabindex) {
            this.tabindex = tabindex;
        }
     
        public String getTitle() {
            return title;
        }
     
        public void setTitle(String title) {
            this.title = title;
        }
    }
    Mon composant est déclaré dans le fichier sample.taglib.xml suivant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    <?xml version="1.0"?>
     
    <!DOCTYPE facelet-taglib PUBLIC
      "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
      "facelet-taglib_1_0.dtd">
    <facelet-taglib>
        <namespace>http://ui.proxy.com/sample</namespace>
        <tag>
            <tag-name>input</tag-name>
            <component>
                <component-type>ui.proxy</component-type>
            </component>
        </tag>
    </facelet-taglib>
    lui même déclaré dans mon 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
    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
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app 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"
             version="2.5">
        <!-- Use Documents Saved as *.xhtml -->
        <context-param>                                                         
            <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
            <param-value>.xhtml</param-value>
        </context-param>
     
        <!-- Special Debug Output for Development -->
        <context-param>
            <param-name>facelets.DEVELOPMENT</param-name>
            <param-value>true</param-value>
        </context-param>
        <context-param>
            <param-name>facelets.LIBRARIES</param-name>
            <param-value>/WEB-INF/facelets/tags/sample.taglib.xml;</param-value>
        </context-param>
     
        <!-- Optional JSF-RI Parameters to Help Debug -->
        <context-param>
            <param-name>com.sun.faces.validateXml</param-name>
            <param-value>true</param-value>
        </context-param>
        <context-param>
            <param-name>com.sun.faces.verifyObjects</param-name>
            <param-value>true</param-value>
        </context-param>
     
     
        <!-- 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>
     
        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>/faces/*</url-pattern>
        </servlet-mapping>
     
        <security-constraint>
            <display-name>welcome page</display-name>
            <web-resource-collection>
                <web-resource-name>No-JSP-JSF-Page</web-resource-name>
                <url-pattern>/welcomeJSF.jsp</url-pattern>
            </web-resource-collection>
            <auth-constraint>
                <description>Pas de rôles, donc pas d’accès direct</description>
            </auth-constraint>
        </security-constraint>
    </web-app>
    voici le fichier faces-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
    30
    31
    32
    33
    34
    35
    <?xml version='1.0' encoding='UTF-8'?>
    <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_1_2.xsd"
                  version="1.2">
        <component>
            <component-type>ui.proxy</component-type>
            <component-class>com.sample.UIIProxy</component-class>
        </component>
        <managed-bean>
            <managed-bean-name>samplebean</managed-bean-name>
            <managed-bean-class>com.sample.SampleBean</managed-bean-class>
            <managed-bean-scope>request</managed-bean-scope>
        </managed-bean>
        <application>
            <!-- facelets configuration -->
            <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
            <!-- -->
            <resource-bundle>
                <base-name>jsf_messages</base-name>
                <var>bundle</var>
            </resource-bundle>
            <message-bundle>jsf_messages</message-bundle>
            <locale-config>
                <default-locale>en</default-locale>
                <supported-locale>de</supported-locale>
                <supported-locale>fr</supported-locale>
                <supported-locale>es</supported-locale>
            </locale-config>
        </application>
        <navigation-rule>
            <from-view-id>/index.xhtml</from-view-id>
        </navigation-rule>
    </faces-config>
    ai oublié la UIInputFactory
    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
    public class UIInputFactory {
        private int labelPosition = 0;
        private boolean containsList;
     
        UIInput getUIInput(String type) {
            System.out.println("getUIInput for type:" + type);
            UIInput ui = new HtmlInputText();
            if (type == null)
                return ui;
            if (type.equals("checkbox")) {
                ui = new UISelectBoolean();
                labelPosition = 1;
            else if (type.equals("date"))
                ui = new HtmlInputText();
            return ui;
        }
     
        public int getLabelPosition() {
            return labelPosition;
        }
     
        public boolean isContainsList() {
            return containsList;
        }
    }
    et enfin mon bean
    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
    public class SampleBean implements Serializable {
     
        private String myString="not null";
        private Date myDate=new Date();
        private Boolean myBoolean;
        private boolean myBoolean2;
        private Date[] myDates;
        private int myInt;
        private Integer myInteger;
     
        public String getMyString() {
            return myString;
        }
     
        public void setMyString(String myString) {
            this.myString = myString;
        }
     
        public Date getMyDate() {
            return myDate;
        }
     
        public void setMyDate(Date myDate) {
            this.myDate = myDate;
        }
     
        public Boolean getMyBoolean() {
            return myBoolean;
        }
     
        public void setMyBoolean(Boolean myBoolean) {
            this.myBoolean = myBoolean;
        }
     
        public boolean isMyBoolean2() {
            return myBoolean2;
        }
     
        public void setMyBoolean2(boolean myBoolean2) {
            this.myBoolean2 = myBoolean2;
        }
     
        public Date[] getMyDates() {
            return myDates;
        }
     
        public void setMyDates(Date[] myDates) {
            this.myDates = myDates;
        }
     
        public int getMyInt() {
            return myInt;
        }
     
        public void setMyInt(int myInt) {
            this.myInt = myInt;
        }
     
        public Integer getMyInteger() {
            return myInteger;
        }
     
        public void setMyInteger(Integer myInteger) {
            this.myInteger = myInteger;
        }
    }

  2. #2
    Membre habitué
    Développeur informatique
    Inscrit en
    Juillet 2007
    Messages
    167
    Détails du profil
    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2007
    Messages : 167
    Points : 143
    Points
    143
    Par défaut
    Bon je viens de modifier les type des propriété de ma classe UIIProxy (type des propriétés).
    Du coup, je n'ai plus d'exceptions. Je récupère alors bien les types texte.
    Par contre les ValueExpression ne sont toujours pas interprétées...

    voici ma classe
    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
    90
    91
    92
    93
    94
    95
    96
    97
    public class UIIProxy extends UIIHtmlCommons {
        //   public static final String COMPONENT_TYPE = "javax.faces.Input";
        private String type;
        private Object label;
        private Object data;
        private Object value;
     
        public UIIProxy() {
        }
     
        public String getFamily() {
            return "ui.proxy";
        }
        public String getRendererType(){
            return null;
        }
     
        public void decode(FacesContext context) {
            List<UIComponent> children = this.getChildren();
            for (UIComponent child : children)
                if (child instanceof HtmlInputHidden)
                    type = (String) ((HtmlInputHidden) child).getValue();
     
        }
     
        void setUIInputChildren() {
            if (!getChildren().isEmpty())
                return;
            UIInputFactory factory = new UIInputFactory();
            UIInput input = factory.getUIInput(type);
            if (input == null) {
                System.out.println("no input, input is null.");
                return;
            }
            if(value!=null){
                if(value instanceof ValueExpression)
                    input.setValueExpression("value", (ValueExpression)value);
                else
                    input.setValue(value);
            }else{
                 System.out.println("value is null");
            }
            List<UIComponent> children = getChildren();
            HtmlInputHidden h = new HtmlInputHidden();
            h.setValue(type);
            HtmlOutputLabel l = null;
            children.add(h);
            if (label != null) {
                l = new HtmlOutputLabel();
                if (label instanceof ValueExpression)
                    l.setValueExpression("value", (ValueExpression) label);
                else
                    l.setValue(label);
            } else {
                System.out.println("label not set for component");
            }
     
     
            children.add(input);
            if(value instanceof ValueExpression)
                input.setValueExpression("value", (ValueExpression)value);
            else
                input.setValue(value);
            if (factory.getLabelPosition() > 0 && l != null) {
                children.add(l);
            }
     
        }
     
        public String getType() {
            return type;
        }
     
        public void setType(String type) {
            this.type = type;
        }
     
        public Object getData() {
            return data;
        }
     
        public void setData(Object data) {
            this.data = data;
        }
     
        public Object getValue() {
            return value;
        }
     
        public void setValue(Object value) {
            this.value = value;
        }
     
        public void setLabel(Object label) {
            this.label = label;
        }
    }

  3. #3
    Rédacteur
    Avatar de romaintaz
    Homme Profil pro
    Java craftsman
    Inscrit en
    Juillet 2005
    Messages
    3 790
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Points : 7 275
    Points
    7 275
    Par défaut
    Personnellement, mes getters ont cette tête :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    public String getTruc() {
        if (truc != null) {
            return truc;
        }
        ValueBinding vb = getValueBinding("truc");
        if (vb != null) {
            return (String) vb.getValue(getFacesContext());
        }
        return null;
    }
    Faut juste adapter, le ValueBinding étant déprécié...
    Nous sommes tous semblables, alors acceptons nos différences !
    --------------------------------------------------------------
    Liens : Blog | Page DVP | Twitter
    Articles : Hudson | Sonar | Outils de builds Java Maven 3 | Play! 1 | TeamCity| CitConf 2009
    Critiques : Apache Maven

  4. #4
    Membre habitué
    Développeur informatique
    Inscrit en
    Juillet 2007
    Messages
    167
    Détails du profil
    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2007
    Messages : 167
    Points : 143
    Points
    143
    Par défaut

    Merci romaintaz, tu viens de me débloquer.
    En fait j'ai juste eu à modifier ma classe UIIProxy comme suit:
    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
    ...
    void setUIInputChildren() {
            try{
                label = getValueExpression("label");
            }catch(NullPointerException e){
                System.out.println("ValueExpression not found" + e.getMessage());   
            }
            try{
                value = getValueExpression("value");
            }catch(NullPointerException e){
                System.out.println("ValueExpression not found" + e.getMessage());
            }
            try{
                data = getValueExpression("data");
            }catch(NullPointerException e){
                System.out.println("ValueExpression not found" + e.getMessage());
            }...

  5. #5
    Rédacteur
    Avatar de romaintaz
    Homme Profil pro
    Java craftsman
    Inscrit en
    Juillet 2005
    Messages
    3 790
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Points : 7 275
    Points
    7 275
    Par défaut
    Tant mieux si cela fonctionne, mais je trouve assez laid de catcher explicitement des NPE, et en plus de faire des try { ... } catch à la suite comme ça...
    Nous sommes tous semblables, alors acceptons nos différences !
    --------------------------------------------------------------
    Liens : Blog | Page DVP | Twitter
    Articles : Hudson | Sonar | Outils de builds Java Maven 3 | Play! 1 | TeamCity| CitConf 2009
    Critiques : Apache Maven

  6. #6
    Membre habitué
    Développeur informatique
    Inscrit en
    Juillet 2007
    Messages
    167
    Détails du profil
    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2007
    Messages : 167
    Points : 143
    Points
    143
    Par défaut
    Citation Envoyé par romaintaz Voir le message
    Tant mieux si cela fonctionne, mais je trouve assez laid de catcher explicitement des NPE, et en plus de faire des try { ... } catch à la suite comme ça...
    je suis complètement d'accord avec toi.
    Mais comment puis-je faire autrement?

  7. #7
    Rédacteur
    Avatar de romaintaz
    Homme Profil pro
    Java craftsman
    Inscrit en
    Juillet 2005
    Messages
    3 790
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Java craftsman
    Secteur : Finance

    Informations forums :
    Inscription : Juillet 2005
    Messages : 3 790
    Points : 7 275
    Points
    7 275
    Par défaut
    Déjà, plutôt que de faire des :

    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
    try {
        a();
    } catch (NPE e) {
       ...
    }
    try {
        b();
    } catch (NPE e) {
       ...
    }
    try {
        c();
    } catch (NPE e) {
       ...
    }
    pourquoi ne pas faire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    try {
        a();
        b();
        c();
    } catch (NPE e) {
        ...
    }
    Ensuite, pourquoi catcher un NPE ?
    D'après le code que je vois de getValueExpression, il ne lance un NPE que si le name - le paramètre donné en argument - est null. Or ce n'est jamais le cas chez toi !

    Sans ces try { ... } catch (NPE), as-tu des problèmes de NPE lorsque tu exécutes ton code ?
    Nous sommes tous semblables, alors acceptons nos différences !
    --------------------------------------------------------------
    Liens : Blog | Page DVP | Twitter
    Articles : Hudson | Sonar | Outils de builds Java Maven 3 | Play! 1 | TeamCity| CitConf 2009
    Critiques : Apache Maven

  8. #8
    Membre habitué
    Développeur informatique
    Inscrit en
    Juillet 2007
    Messages
    167
    Détails du profil
    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2007
    Messages : 167
    Points : 143
    Points
    143
    Par défaut
    Citation Envoyé par romaintaz Voir le message
    Déjà, plutôt que de faire des :

    Ensuite, pourquoi catcher un NPE ?
    D'après le code que je vois de getValueExpression, il ne lance un NPE que si le name - le paramètre donné en argument - est null. Or ce n'est jamais le cas chez toi !

    Sans ces try { ... } catch (NPE), as-tu des problèmes de NPE lorsque tu exécutes ton code ?

    en effet, les try catch sont inutiles. J'ai écrit n'importe quoi pour le coup.

    merci encore

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Debutant(e)]Eclipse 3.1, probleme d'attribut
    Par sophie86 dans le forum Eclipse Java
    Réponses: 4
    Dernier message: 28/11/2005, 21h21
  2. Probleme type enum
    Par azertyuiop75 dans le forum Oracle
    Réponses: 4
    Dernier message: 08/07/2005, 16h09
  3. [LG]Problème "Type Mismatch"
    Par Aezar dans le forum Langage
    Réponses: 9
    Dernier message: 25/02/2005, 22h50
  4. [probleme]Type INNODB
    Par Grimaud dans le forum Requêtes
    Réponses: 8
    Dernier message: 06/08/2004, 16h55
  5. [LG]Problême "types incompatibles"
    Par pierrOPSG dans le forum Langage
    Réponses: 7
    Dernier message: 23/04/2004, 21h34

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