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

Struts 1 Java Discussion :

Données de formulaire non récupérées


Sujet :

Struts 1 Java

  1. #1
    Membre expérimenté
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2003
    Messages
    1 303
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2003
    Messages : 1 303
    Points : 1 380
    Points
    1 380
    Par défaut Données de formulaire non récupérées
    Je dois ajouter une case à cocher dans une appli existante. Le problème, c'est qu'un DynaActionForm est utilisé pour cette page. Je ne peut donc pas faire de reset des cases à cocher. J'ai donc créé un nouveau formulaire avec un reset. Quand je valide ce formulaire, j'ai l'erreur suivante (le formulaire n'est pas récupéré semble-t-il) :
    javax.servlet.ServletException: BeanUtils.populate
    ...
    java.lang.NullPointerException
    at org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:515)
    JSP :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <logic:iterate id="applications" name="creerServiceApplicationForm" property="applications">									<tr>
      <td class="texte"><bean:write name="applications" property="appSigle"/></td>
      <td><html:text name="applications" property="code" indexed="true" maxlength="20" size="20" /></td>
      <td><html:checkbox name="applications" property="integ" disabled="false" indexed="true" value="1"/></td>
    </tr>
    </logic:iterate>
    Qui donne en HTML :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    <tr><td class="texte">GESTIONS</td>
      <td><input type="text" name="applications[0].code" maxlength="20" size="20" value="azerty"></td>
      <td><input type="checkbox" name="applications[0].integ" value="1" checked="checked"></td>
    </tr><tr>
      <td class="texte">SIGMA</td>
      <td><input type="text" name="applications[1].code" maxlength="20" size="20" value=""></td>
      <td><input type="checkbox" name="applications[1].integ" value="1"></td>
    </tr>
    Le Form :
    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
    public class CreationApplicationForm extends ValidatorForm {
      private ApplicationService[] applications;
      public final void reset(ActionMapping mapping, HttpServletRequest request)  {
        System.out.println("*** *** CreationApplicationForm ==> reset");
        if (applications != null) {
    		    for (int i = 0; i < applications.length; i++) {
    		        ApplicationService appService = (ApplicationService) applications[i];
    		        appService.setInteg(null);
    		    }
    		}
        System.out.println("*** *** CreationApplicationForm ==> fin reset");
      }
      public ApplicationService[] getApplications() {
        System.out.println("*** *** getApplications : " + applications);
        return applications;
      }
    ... }
    struts-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
        <form-bean name="creationApplicationForm" 
          type="domaine.struts.form.CreationApplicationForm">
          <form-property name="applications" type="domaine.util.ApplicationService[]"/>
        </form-bean>
        <action
          path="/mettreAJourServiceApplication"
          type="domaine.struts.action.MettreAJourServiceApplicationAction"
          name="creationApplicationForm"
          attribute="creationApplicationForm"
          scope="request"
          unknown="false">
          <forward
            name="success"
            path="/chargerServiceApplication.do"
            redirect="false"
            contextRelative="false" />
        </action>
    StdOut après avoir validé le formulaire :
    *** *** CreationApplicationForm ==> reset
    *** *** CreationApplicationForm ==> fin reset
    *** *** getApplications : null

  2. #2
    Expert éminent sénior


    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    7 856
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2003
    Messages : 7 856
    Points : 34 380
    Points
    34 380
    Par défaut
    Le problème se situe au niveau du tableau.
    Lors de la tentative de populate, le tableau n'a pas de taille, d'où l'erreur.

    Il faudrait dans la mesure du possible initialiser la taille pour ne pas être confronté à ce problème.

  3. #3
    Membre expérimenté
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2003
    Messages
    1 303
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2003
    Messages : 1 303
    Points : 1 380
    Points
    1 380
    Par défaut
    Je n'ai pas trouvé comment initialiser la taille du tableau alors j'ai essayé de faire ça dans le form (utiliser une liste à la place du tableau):
    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
    private List applications;
     
    public final void reset(ActionMapping mapping, HttpServletRequest request) {
      final Factory factory = new Factory() {
        public Object create() {
          return new ApplicationService();
        }
      };
      List applications = LazyList.decorate(new ArrayList(), factory);
     
      if (applications != null) {
        for (int i = 0; i < applications.size(); i++) {
          ApplicationService appService = (ApplicationService) applications.get(i);
          appService.setInteg(null);
        }
      }
    }
     
    public Object[] getApplications() {
      System.out.println("*** CPU *** getApplications : " + applications);
      return applications.toArray();
    }
     
    public void setApplications(ApplicationService[] applicationsTableau) {
      List tmpAppli = new ArrayList();
      for (int i = 0; i < applicationsTableau.length; i++) {
        ApplicationService application = (ApplicationService)applicationsTableau[i];
        tmpAppli.add(application);
      }
      this.applications = tmpAppli;
    }
    mais j'ai la même erreur.

  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
    Et si tu mets ton form-bean en scope session, ça donne quoi ?

  5. #5
    Membre expérimenté
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2003
    Messages
    1 303
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Service public

    Informations forums :
    Inscription : Avril 2003
    Messages : 1 303
    Points : 1 380
    Points
    1 380
    Par défaut
    Le scope en session donne exactement la même chose.

  6. #6
    Membre à l'essai
    Profil pro
    Étudiant
    Inscrit en
    Avril 2006
    Messages
    9
    Détails du profil
    Informations personnelles :
    Localisation : France, Isère (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2006
    Messages : 9
    Points : 11
    Points
    11
    Par défaut
    Citation Envoyé par Christophe P.
    Je n'ai pas trouvé comment initialiser la taille du tableau alors j'ai essayé de faire ça dans le form (utiliser une liste à la place du tableau):
    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
    private List applications;
    
    public final void reset(ActionMapping mapping, HttpServletRequest request) {
      final Factory factory = new Factory() {
        public Object create() {
          return new ApplicationService();
        }
      };
      List applications = LazyList.decorate(new ArrayList(), factory);
    
      if (applications != null) {
        for (int i = 0; i < applications.size(); i++) {
          ApplicationService appService = (ApplicationService) applications.get(i);
          appService.setInteg(null);
        }
      }
    }
    
    public Object[] getApplications() {
      System.out.println("*** CPU *** getApplications : " + applications);
      return applications.toArray();
    }
    
    public void setApplications(ApplicationService[] applicationsTableau) {
      List tmpAppli = new ArrayList();
      for (int i = 0; i < applicationsTableau.length; i++) {
        ApplicationService application = (ApplicationService)applicationsTableau[i];
        tmpAppli.add(application);
      }
      this.applications = tmpAppli;
    }
    mais j'ai la même erreur.

    Tu as l'air de la redéclarer, du coup tu assignes pas ta variable donc celle retourné est null

Discussions similaires

  1. Données du formulaire non reconnues
    Par dré kam dans le forum Langage
    Réponses: 6
    Dernier message: 12/06/2012, 19h19
  2. Réponses: 1
    Dernier message: 25/09/2008, 19h09
  3. [MySQL] Données du formulaire non ajoutée dans ma BD
    Par Sofalkin dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 07/09/2008, 11h58
  4. [MySQL] Données d'un formulaire non présent en BDD
    Par esthete dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 07/11/2006, 14h12
  5. données du formulaire non-modifiables
    Par vautour29 dans le forum Access
    Réponses: 14
    Dernier message: 28/07/2006, 21h42

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