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

Wildfly/JBoss Java Discussion :

[EJB][jboss][struts]probleme de logic:iterate


Sujet :

Wildfly/JBoss Java

  1. #1
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 37
    Points : 26
    Points
    26
    Par défaut [EJB][jboss][struts]probleme de logic:iterate
    bonjour tout le monde,
    dans mon projet j'utilise struts avec des EJBs ,mais j'ai le probleme suivant:
    No getter method for property id_alarm of bean alarm du code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
             <logic:iterate id="alarm" name="tables">
              <td><bean:write name="alarm" property="id_alarm" /> </td>
              <td><bean:write name="alarm" property="id_type_alarm" /> </td>
              <td><bean:write name="alarm" property="lib_alarm" /> </td>
            </logic:iterate>
    sachant que mon EJB contiendra bien ce getter!!
    j'ai oublie de vous dire que de la view de monEJB je recupere les données et je les met dans un array list que je le met a son tour dans la session

    merci de m'aider,je suis vraiment blocké dans ce point!
    cordialement

  2. #2
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Remplace :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <logic:iterate id="alarm" name="tables">
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <logic:iterate id="alarm" property="tables">
    si tables est bien le nom de ton ArrayList de bean.
    Modératrice Java - Struts, Servlets/JSP, ...

  3. #3
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 37
    Points : 26
    Points
    26
    Par défaut [EJB][jboss][struts]probleme Null attribute name
    salut c_nvy,
    j'ai essaié mais j'ai eu un autre probleme qui est :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    java.lang.NullPointerException: Null attribute name 	org.apache.jasper.runtime.PageContextImpl.findAttribute(PageContextImpl.java:450) 	org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:874)
    est ce que t'as une idée s'il te plait

    [ Modéré par SEMPERE Benjamin ]
    Ajout des balises code
    Les Règles du Forum

  4. #4
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Essaie alors en ajoutant l'attribut name à ton tag logic:iterate en y spécifiant le nom de ton form-bean comme ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <logic:iterate id="alarm" property="tables" name="tonForm">
    Modératrice Java - Struts, Servlets/JSP, ...

  5. #5
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 37
    Points : 26
    Points
    26
    Par défaut
    salut,
    j'ai essaye avec le code suivant:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <logic:iterate id="alarm"  property="tables" name="alarmEditForm">
       <html:select property="id_type_alarm" size="1" value="<%=(String)session.getAttribute("id_type_alarm")%>">
       <%if(request.getAttribute("id_type_alarm") == null) {%>
       <option value="0">Choisissez un type
       </option>
       <%} else 
                       {%>
       <html:options name="tables" labelName="tables" />
     
       <% } %>
       </html:select>
    mais le probleme rien ne s'affiche pour la case id_type_alarm et si j'enleve le logic:iterate je vois afficher

    dans le select choisissez un type
    donc le tables ne contient rien ,sachant qu'il ya des enregistrement dans la table Alarm
    stp aidez moi!!!
    et merci infiniment

  6. #6
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Essaie déjà ceci tout simplement et dis-moi si ça marche :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    <html:select property="id_type_alarm" >
         <html:options collection="tables" property="id_type_alarm" labelProperty="lib_alarm" />
    </html:select>
    J'ai mis lib_alarm comme label mais je ne sais pas si c'est cela que tu veux voir apparaître dans ta combobox.
    Modératrice Java - Struts, Servlets/JSP, ...

  7. #7
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 37
    Points : 26
    Points
    26
    Par défaut probleme logic:iterate
    non ca marche plus encore ,je veux plutot afficher le id_type_alarm
    il me donne l'erreur:
    javax.servlet.ServletException: No getter method available for property id_type_alarm for bean under name tables

    dans l'action j'ai mis le code suivant:
    ***********alarmEditAction***********
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    alarmEditForm.setAlarmView(alarmmanager.getAlarmByPrimaryKey(id));
                    session.setAttribute("alarmView",alarmEditForm.getAlarmView());
                    tables.add(String.valueOf(alarmEditForm.getId_type_alarm()));
     
                    session.setAttribute("id_alarm",alarmEditForm.getId_alarm());
                    session.setAttribute("id_type_alarm",alarmEditForm.getId_type_alarm());
                    session.setAttribute("lib_alarm",alarmEditForm.getLib_alarm());
                    request.setAttribute("tables", tables);
    [ Modéré par SEMPERE Benjamin ]
    Ajout des balises code
    Les Règles du Forum

  8. #8
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    tables étant une simple ArrayList et non une ArrayList de beans comme je le pensais, et étant mise dans le scope via un setAttribute et non un form-bean, il suffit de coder ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    <html:select property="id_type_alarm" >
         <html:options name="tables"/>
    </html:select>
    Par contre, j'avoue ne pas bien comprendre comment tu alimentes ton ArrayList tables.
    D'après le code que tu as donné, il n'y aura qu'une seule ligne dans tables ???
    tables.add(String.valueOf(alarmEditForm.getId_type_alarm()));
    et tu récupères l'id_type_alarm de quel formulaire ?
    Modératrice Java - Struts, Servlets/JSP, ...

  9. #9
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 37
    Points : 26
    Points
    26
    Par défaut
    pour le code que tu m'as proposé au debut ,il m'affiche le select qui contient 2 null
    en ce qui concerne le .add c vrai il va rapporter qu'un champ
    je voulais justement tester le select

    alarEditForm est sous la forme:
    ********alarmeditForm********
    //Created by MyEclipse Struts
    // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.9.210/xslt/JavaClass.xsl


    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
     import java.util.ArrayList;
     
    import javax.servlet.http.HttpServletRequest;
     
    import ma.pcard.scrashcard.entity.interfaces.AlarmValue;
    import ma.pcard.scrashcard.view.AlarmView;
     
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;
     
    /** 
     * MyEclipse Struts
     * Creation date: 04-04-2006
     * 
     * XDoclet definition:
     * @struts:form name="alarmEditForm"
     */
    public class AlarmEditForm extends ActionForm {
     
        // --------------------------------------------------------- Instance Variables
     
        // --------------------------------------------------------- Methods
     
        private AlarmView alarmView = new AlarmView();
        private ArrayList tables;
     
        public ArrayList getTables() {
            return tables;
        }
     
        public void setTables(ArrayList tables) {
            this.tables = tables;
        }
     
        public AlarmView getAlarmView() {
            return alarmView;
        }
     
        public void setAlarmView(AlarmView alarmView) {
            this.alarmView = alarmView;
        }
        public boolean equals(Object other) {
            return alarmView.equals(other);
        }
     
        public AlarmValue getAlarmValue() {
            return alarmView.getAlarmValue();
        }
     
        public Integer getId_alarm() {
            return alarmView.getId_alarm();
        }
     
        public Integer getId_type_alarm() {
            return alarmView.getId_type_alarm();
        }
     
        public String getLib_alarm() {
            return alarmView.getLib_alarm();
        }
     
        public Integer getPrimaryKey() {
            return alarmView.getPrimaryKey();
        }
     
        public int hashCode() {
            return alarmView.hashCode();
        }
     
        public boolean id_alarmHasBeenSet() {
            return alarmView.id_alarmHasBeenSet();
        }
     
        public boolean id_type_alarmHasBeenSet() {
            return alarmView.id_type_alarmHasBeenSet();
        }
     
        public boolean isIdentical(Object other) {
            return alarmView.isIdentical(other);
        }
     
        public boolean lib_alarmHasBeenSet() {
            return alarmView.lib_alarmHasBeenSet();
        }
     
        public void setAlarmValue(AlarmValue alarmValue) {
            alarmView.setAlarmValue(alarmValue);
        }
     
        public void setId_alarm(Integer id_alarm) {
            alarmView.setId_alarm(id_alarm);
        }
     
        public void setId_type_alarm(Integer id_type_alarm) {
            alarmView.setId_type_alarm(id_type_alarm);
        }
     
        public void setLib_alarm(String lib_alarm) {
            alarmView.setLib_alarm(lib_alarm);
        }
     
        public void setPrimaryKey(Integer pk) {
            alarmView.setPrimaryKey(pk);
        }
     
        public String toString() {
            return alarmView.toString();
        }
     
        /** 
         * Method reset
         * @param mapping
         * @param request
         */
        public void reset(ActionMapping mapping, HttpServletRequest request) {
     
            // TODO Auto-generated method stub
        }
     
    }
     
    et l'objet alarmView est le suivant
    ************alarmView********
    package ma.pcard.scrashcard.view;
     
    import ma.pcard.scrashcard.entity.interfaces.AlarmValue;
     
     
    public class AlarmView implements java.io.Serializable{
     
    private AlarmValue alarmValue = new AlarmValue();
     
     
        public AlarmValue getAlarmValue() {
            return alarmValue;
        }
        public void setAlarmValue(AlarmValue alarmValue) {
            this.alarmValue = alarmValue;
        }
        public boolean equals(Object other) {
            return alarmValue.equals(other);
        }
        public Integer getId_alarm() {
            return alarmValue.getId_alarm();
        }
        public Integer getId_type_alarm() {
            return alarmValue.getId_type_alarm();
        }
        public String getLib_alarm() {
            return alarmValue.getLib_alarm();
        }
        public Integer getPrimaryKey() {
            return alarmValue.getPrimaryKey();
        }
        public int hashCode() {
            return alarmValue.hashCode();
        }
        public boolean id_alarmHasBeenSet() {
            return alarmValue.id_alarmHasBeenSet();
        }
        public boolean id_type_alarmHasBeenSet() {
            return alarmValue.id_type_alarmHasBeenSet();
        }
        public boolean isIdentical(Object other) {
            return alarmValue.isIdentical(other);
        }
        public boolean lib_alarmHasBeenSet() {
            return alarmValue.lib_alarmHasBeenSet();
        }
        public void setId_alarm(Integer id_alarm) {
            alarmValue.setId_alarm(id_alarm);
        }
        public void setId_type_alarm(Integer id_type_alarm) {
            alarmValue.setId_type_alarm(id_type_alarm);
        }
        public void setLib_alarm(String lib_alarm) {
            alarmValue.setLib_alarm(lib_alarm);
        }
        public void setPrimaryKey(Integer pk) {
            alarmValue.setPrimaryKey(pk);
        }
        public String toString() {
            return alarmValue.toString();
        }
     
    }
    et l'alarmedit action
    **********alarmEditAction*************
    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
     import java.rmi.RemoteException;
    import java.util.ArrayList;
     
    import javax.ejb.CreateException;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
     
    import ma.pcard.scrashcard.session.interfaces.AlarmManager;
    import ma.pcard.scrashcard.session.interfaces.AlarmManagerHome;
    import ma.pcard.scrashcard.session.interfaces.TypeManager;
    import ma.pcard.scrashcard.session.interfaces.TypeManagerHome;
    import ma.pcard.scrashcard.struts.form.AlarmEditForm;
    import ma.pcard.scrashcard.struts.form.TypeEditForm;
     
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.actions.DispatchAction;
     
    /** 
     * MyEclipse Struts
     * Creation date: 04-04-2006
     * 
     * XDoclet definition:
     * @struts:action path="/alarmEdit" name="alarmEditForm" parameter="do" scope="request" validate="true"
     * @struts:action-forward name="showEdit" path="/jsp/alarmEdit.jsp"
     * @struts:action-forward name="showList" path="/alarmList.do" redirect="true"
     * @struts:action-forward name="showAdd" path="/jsp/alarmAdd.jsp"
     */
    public class AlarmEditAction extends DispatchAction {
     
        // --------------------------------------------------------- Instance Variables
     
        // --------------------------------------------------------- Methods
        /** 
         * Method editAlarm
         * @param mapping
         * @param form
         * @param request
         * @param response
         * @return ActionForward
         */
        public ActionForward editAlarm(
                ActionMapping mapping,
                ActionForm form,
                HttpServletRequest request,
                HttpServletResponse response) {
                AlarmEditForm alarmEditForm = (AlarmEditForm) form;
                HttpSession session = request.getSession();
                ArrayList tables = new ArrayList();    
                /* lalinuna.de 04.11.2004
                 * get id of the book from request
                 */
                Integer id = Integer.valueOf(request.getParameter("id_alarm"));
                //Integer id1 = Integer.valueOf(request.getParameter("id_type_alarm"));
     
                /* lalinuna.de 16.11.2004
                 * load the session facade and get the book by primary key
                 */
                try {
                    InitialContext context = new InitialContext();
                    //holen des Home Interfaces für BookSession mit JNDI vom Appplication Server
                    AlarmManagerHome alarmmanagerHome = (AlarmManagerHome)context.lookup(AlarmManagerHome.JNDI_NAME);
                    AlarmManager alarmmanager = alarmmanagerHome.create();
     
                    //bestimme das Buch anhand seines Primärschlüssels und setzte es im Form Bean    
     
                    alarmEditForm.setAlarmView(alarmmanager.getAlarmByPrimaryKey(id));
                    session.setAttribute("alarmView",alarmEditForm.getAlarmView());
                    tables.add(String.valueOf(alarmEditForm.getId_type_alarm()));
     
                    session.setAttribute("id_alarm",alarmEditForm.getId_alarm());
                    session.setAttribute("id_type_alarm",alarmEditForm.getId_type_alarm());
                    session.setAttribute("lib_alarm",alarmEditForm.getLib_alarm());
                    request.setAttribute("tables", tables);
     
     
                } catch (RemoteException e) {
                    e.printStackTrace();
                } catch (NamingException e) {
                    e.printStackTrace();
                } catch (CreateException e) {
                    e.printStackTrace();
                }
     
                return mapping.findForward("showEdit");
     
            }

    merci infiniment de bien m'aider.

  10. #10
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Si j'ai bien compris, AlarmView est la classe qui correspond à ta table.
    Donc, à partir du contenu de la table, il faudrait constituer une ArrayList de beans AlarmView.
    Est-ce bien ceci que te renvoie ton EJB ?
    Si c'est bien le cas, il suffit ensuite de faire dans ton Action qui initialise ton formulaire AlarmEditAction :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    ArrayList tables = appel de la méthode qui te renvoie l'ArrayList de beans AlarmView ;
    AlarmEditForm alarmEditForm = (AlarmEditForm) form ;
    alarmEditForm.setTables(tables) ;
    Et dans ta jsp :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    <html:form action="alarmEdit">
       <html:select property="id_type_alarm">
           <html:optionsCollection property="tables" value="id_type_alarm" label="id_type_alarm"/>
       </html:select>
    </html:form>
    Modératrice Java - Struts, Servlets/JSP, ...

  11. #11
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Puisque l'appel de alarmmanager.getAlarmByPrimaryKey(id) te renvoie un bean AlarmView, pour tester, tu peux faire aussi ceci dans ton Action :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    ArrayList tables = new ArrayList() ;
    AlarmView alarmView = alarmmanager.getAlarmByPrimaryKey(id) ;
    tables.add(alarmView);
    AlarmEditForm alarmEditForm = (AlarmEditForm) form ;
    alarmEditForm.setTables(tables) ;
    Et toujours dans la jsp :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    <html:form action="alarmEdit">
       <html:select property="id_type_alarm">
           <html:optionsCollection property="tables" value="id_type_alarm" label="id_type_alarm"/>
       </html:select>
    </html:form>
    Modératrice Java - Struts, Servlets/JSP, ...

  12. #12
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 37
    Points : 26
    Points
    26
    Par défaut
    bonjour,
    ce qui se trouve dans la view c lui qui correspont à mon EJB.

    j'ai essaye ce que tu m'as dis dans la 2eme proposition mais il me donne une autre erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    javax.servlet.jsp.JspException: Failed to obtain specified collection
    par contre j'arrive pas à concevoir la methode qui me renvoie un arraylist de beans alarmView
    comment je vais faire pour extraire seulement le champ id_type_alarm et le mettre dans l'arraylist ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
         ArrayList tables=new ArrayList();
         ArrayList table=alarmView.getId_type_alarm();
          tables.add(table);
    ou quoi mettre???

    [ Modéré par SEMPERE Benjamin ]
    Ajout des balises code
    Les Règles du Forum

  13. #13
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Pour pouvoir constituer une ArrayList de beans AlarmView, il faut créer une méthode qui lit tous les records de ta table, et pour chaque record créer une instance de AlarmView, l'alimenter via les setters sur chacun des attributs d'AlarmView et ajouter chaque bean dans une ArrayList.

    As-tu créé une méthode qui lit tous les records de ta table ?
    Si oui, poste-là.

    Quant à l'ArrayList, le code que je t'ai donné devrait marcher.
    Ou alors, teste en remplaçant le html:optionsCollection par un html:options comme ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    <html:select property="id_type_alarm">
        <html:options collection="tables" property="id_type_alarm" labelProperty="id_type_alarm"/>   
    </html:select>
    PS: Regarde ce post qui traite du même sujet.
    Modératrice Java - Struts, Servlets/JSP, ...

  14. #14
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 37
    Points : 26
    Points
    26
    Par défaut
    es ce que cela est juste?

    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
    public ArrayList[] getAllAlarms() throws javax.ejb.EJBException {
      try {
        InitialContext context = new InitialContext();
        //Get the home interface with JNDI from the application server
        AlarmLocalHome alarmLocalHome = (AlarmLocalHome)context.lookup(AlarmLocalHome.JNDI_NAME);
     
        //get all alarms with the local home interface
        Collection collection = alarmLocalHome.findAll();
     
        //define an ArrayList
        ArrayList arrayList = new ArrayList();
     
        //loop over the collection 
        for (Iterator iter = collection.iterator(); iter.hasNext();) {
          AlarmLocal element = (AlarmLocal) iter.next();
     
          //define a new AlarmView object
          AlarmView alarmView = new AlarmView();
     
          //set the AlarmValue in alarmView
     
          alarmView.setAlarmValue(element.getAlarmValue());                                                                                                          
          //add the alarmView object to the ArrayList
          arrayList.add(alarmView);
        }
     
        //return the array of AlarmView
        return arrayList;
     
      } catch (NamingException e) {
         throw new EJBException(e.getMessage());
      } catch (FinderException e) {
         throw new EJBException(e.getMessage());
      }
    }
    ou bien es ce qu'il ya une methode pour convertir le alarmView[] que la methode getAllAlarms me retourn en un arrayList? parce que j'ai deja ecrit getAllAlarms et c'est elle qui me retourne cet alarmView que je ne peut pas iterer sur lui??????
    j'espere que tu m'as compris
    merci

  15. #15
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    La méthode retourne une ArrayList et non ArrayList[].
    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
     
    public ArrayList getAllAlarms() throws javax.ejb.EJBException {
    try {
    InitialContext context = new InitialContext();
    //Get the home interface with JNDI from the application server
    AlarmLocalHome alarmLocalHome = (AlarmLocalHome)context.lookup(AlarmLocalHome.JNDI_NAME);
     
    //get all alarms with the local home interface
    Collection collection = alarmLocalHome.findAll();
     
    //define an ArrayList
    ArrayList arrayList = new ArrayList();
     
    //loop over the collection 
    for (Iterator iter = collection.iterator(); iter.hasNext():wink: {
    AlarmLocal element = (AlarmLocal) iter.next();
     
    //define a new AlarmView object
    AlarmView alarmView = new AlarmView();
     
    //set the AlarmValue in alarmView
    alarmView.setAlarmValue(element.getAlarmValue());
     
     
    //add the alarmView object to the ArrayList
    arrayList.add(alarmView);
    }
     
    //return the array of AlarmView
    return arrayList;
     
    } catch (NamingException e) {
    throw new EJBException(e.getMessage());
    } catch (FinderException e) {
    throw new EJBException(e.getMessage());
    }
    }
    Ce code constitue bien une ArrayList de bean AlarmView mais comme tu ne fais appel qu'à la méthode setAlarmValue, les autres propriétés du bean ne sont pas renseignées.
    Là où tu fais appel à la méthode setAlarmValue, il faut aussi faire appel à tous les autres setters de AlarmView, si tu veux vraiment constituer une ArrayList de bean AlarmView qui sera le reflet de ta table.
    Je ne sais pas si je suis assez claire.
    Modératrice Java - Struts, Servlets/JSP, ...

  16. #16
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 37
    Points : 26
    Points
    26
    Par défaut
    j'ai bien essaye ce que tu m'as dit exactement et j'ai eu l'erreur 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
    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
    javax.servlet.jsp.JspException: No getter method available for property id_type_alarm for bean under name tables
        at org.apache.struts.taglib.html.OptionsTag.doEndTag(OptionsTag.java:252)
        at org.apache.jsp.jsp.alarmAdd_jsp._jspx_meth_html_options_0(alarmAdd_jsp.java:240)
        at org.apache.jsp.jsp.alarmAdd_jsp._jspx_meth_html_select_0(alarmAdd_jsp.java:212)
        at org.apache.jsp.jsp.alarmAdd_jsp._jspx_meth_html_form_0(alarmAdd_jsp.java:133)
        at org.apache.jsp.jsp.alarmAdd_jsp._jspService(alarmAdd_jsp.java:84)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:474)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:409)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
        at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
        at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
        at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
        at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
        at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:44)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:169)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
        at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
        at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
        at java.lang.Thread.run(Thread.java:534)
    sachant que mon getAllAlarm dans mon action est le 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
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    public ArrayList getAllAlarm() throws javax.ejb.EJBException {
            try {
                InitialContext context = new InitialContext();
                //Get the home interface with JNDI from the application server
                AlarmLocalHome alarmLocalHome = (AlarmLocalHome)context.lookup(AlarmLocalHome.JNDI_NAME);
     
                //get all alarms with the local home interface
                Collection collection = alarmLocalHome.findAll();
     
                //define an ArrayList
                ArrayList arrayList = new ArrayList();
     
                //loop over the collection 
                for (Iterator iter = collection.iterator(); iter.hasNext();) {
                    AlarmLocal element = (AlarmLocal) iter.next();
     
                    //define a new AlarmView object
                    AlarmView alarmView = new AlarmView();
     
                    //set the AlarmValue in alarmView
                    alarmView.setAlarmValue(element.getAlarmValue());
                    alarmView.setId_type_alarm(element.getId_type_alarm());
                    alarmView.setId_alarm(element.getId_alarm());
                    alarmView.setLib_alarm(element.getLib_alarm());
     
     
                    //add the alarmView object to the ArrayList
                    arrayList.add(alarmView);
                }
    es ce que t'as une idée de ce qui se passe?

    [ Modéré par SEMPERE Benjamin ]
    Ajout des balises code
    Les Règles du Forum

  17. #17
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Je ne vois rien d'anormal pourtant. Ca devrait marcher.
    Tu n'aurais pas quelque part un name="tables" dans ta jsp ?
    Puis-je voir le code exact de ta jsp avec le html:form ?
    Modératrice Java - Struts, Servlets/JSP, ...

  18. #18
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    As-tu essayé les deux solutions html:options et html:optionsCollection ?

    Il me semble que la solution suivante est plus adaptée quand l'ArrayList est un attribut du form-bean :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
       <html:select property="id_type_alarm">
           <html:optionsCollection property="tables" value="id_type_alarm" label="id_type_alarm"/>
       </html:select>
    Modératrice Java - Struts, Servlets/JSP, ...

  19. #19
    Nouveau membre du Club
    Inscrit en
    Mars 2006
    Messages
    37
    Détails du profil
    Informations forums :
    Inscription : Mars 2006
    Messages : 37
    Points : 26
    Points
    26
    Par défaut
    le code de ma jsp est:
    ******alarmAdd.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
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
     
    <%@ page language="java"%>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> 
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
     
    <html> 
        <head>
            <title>Add an alarm</title>
        </head>
        <body>
            <%-- create a html form --%>
            <html:form action="alarmEdit">
                <%-- print out the form data --%>
                <table border="1">
                    <tbody>
                    <tr>
                        <td>id alarm:</td>
                        <td><html:text property="id_alarm" /></td>
                    </tr>
                    <tr>
                        <td>id type alarm:</td>
     
                 <!-- iteration sur les résultats de la requête -->
            <td>
        <html:select property="id_type_alarm">
        <html:options collection="tables" property="id_type_alarm" labelProperty="id_type_alarm"/>   
    </html:select>
                </td>
                <tr>
                        <td>Lib alarm:</td>
                        <td><html:text property="lib_alarm" /></td>
                    </tr>
                    </tbody>
                </table>
                <%-- set the parameter for the dispatch action --%>
                <html:hidden property="do" value="saveAlarm" />    
     
                <br>
                <%-- submit and back button --%>
                <html:button property="back" 
                             onclick="history.back();">
                             Back
                </html:button>
                &nbsp;
                <html:submit>Save</html:submit>
            </html:form>
     
     
        </body>
    </html>
    et portant j'ai essaye avec les deux :
    pour l'une elle m'affiche no getter methode for property id_type_alarm
    et pour l'autre : Failed to obtain specified collection.

    [ Modéré par SEMPERE Benjamin ]
    Ajout des balises code
    Les Règles du Forum

  20. #20
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Et dans l'action-mapping de ton action de path alarmEdit, dans le struts-config.xml, tu as bien un name="alarmEditForm" ?

    Sinon, la jsp me semble correcte.
    Montre-moi alors de nouveau le code de ton action AlarmEditAction après les modifications apportées.
    Modératrice Java - Struts, Servlets/JSP, ...

Discussions similaires

  1. Probleme avec Logic:iterate
    Par ForHuman dans le forum Struts 1
    Réponses: 7
    Dernier message: 17/07/2008, 16h05
  2. probleme property <logic:iterate>
    Par D.Mounir dans le forum Struts 1
    Réponses: 16
    Dernier message: 04/03/2007, 16h18
  3. struts formulaire dans logic:iterate
    Par jeb001 dans le forum Struts 1
    Réponses: 1
    Dernier message: 07/08/2006, 15h50
  4. [ EJB ] [JBoss ] [ XDoclet ] probleme avec cascade-delete
    Par Houbbba dans le forum Wildfly/JBoss
    Réponses: 4
    Dernier message: 03/05/2006, 10h05
  5. [EJB2.1 Entity] [BMP] [Struts] Problème avec <logic:iterate>
    Par romain3395 dans le forum Java EE
    Réponses: 2
    Dernier message: 07/06/2004, 10h12

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