Hello,
a few things, I believe this is unnecessary:
//Creation du form bean "moncompteForm" s'il n'existe pas
if (form==null) {
//Creation du from-bean
form = new MoncompteForm();
//Ajout a la requets ou session selon l'attribut "scope" de
<action-mapping>
if ("request".equals(mapping.getScope()))
request.setAttribute(mapping.getAttribute(),form);
else
request.getSession().setAttribute(mapping.getAttri bute(),form);
}
as long as your struts-config is set up properly, struts should
automatically create a form bean for you and place it in the
appropriate scope..
however I don't think your action-mapping is correct.. it should be:
<action path="/editMonCompte"
type="eshop.actions.EditMonCompteAction"
name="moncompteForm"
scope="request"
validate="false"/>
I believe you used 'attribute' instead of 'name'.. check out
strutsconsole (
http://jamesholmes.com/struts/) it will validate your
struts-config file for you..
give that a try and see what happens..
james
"Java_Forum" <> wrote in message news:<bkhklq$30g$>...
> <html>
> <font size="-1">
> hi,<BR>i am trying to do a simple thing without success!!!<BR>in my
> web application (designed under the struts framework), i have a logon action
> which check the username and password of a user, if it's ok i create and
> store an object User with a session scope.<BR>i have a another item at my
> menu wich enable a user to display his information (stored in the user
> object), here is the code. theres is 3 files<BR>EditmonCompteAction wich
> display the user information.<BR>User bean wich store information about the
> user.<BR>MoncompteForm is the bean form used in the mapping-action.<BR>and
> finally of course the
> struts-config.xml<BR><BR><pre><BR>EDITMONCOMPTEACTION<BR> *******************
> *<BR><b>public</b> <b>class</b> EditMonCompteAction <b>extends</b> Action
> {<BR><BR> <b>public</b> ActionForward execute(ActionMapping
> mapping,ActionForm form,HttpServletRequest request,HttpServletResponse
> response)<b>throws</b> Exception { <BR> <BR> <font
> color="#aa0000"><i>//Recupere l'utilisateur 'user' en cours</font></i><BR>
> User user = (User)
> (request.getSession()).getAttribute(Globals.USER_K EY);<BR> <b>if</b> (user
> == null)<BR> <b>return</b> mapping.findForward(<font
> color="#000099">"logon"</font>);<BR> <BR> <font
> color="#aa0000"><i>//Creation du form bean "moncompteForm" s'il n'existe
> pas</font></i><BR> <b>if</b> (form==null) {<BR> <font
> color="#aa0000"><i>//Creation du from-bean</font></i><BR> form =
> <b>new</b> MoncompteForm();<BR> <font color="#aa0000"><i>//Ajout a la
> requets ou session selon l'attribut "scope" de
> <action-mapping></font></i><BR> <b>if</b> (<font
> color="#000099">"request"</font>.equals(mapping.getScope()))<BR>
> request.setAttribute(mapping.getAttribute(),form); <BR> <b>else</b><BR>
> request.getSession().setAttribute(mapping.getAttri bute(),form);<BR> }<BR>
> <BR> <font color="#aa0000"><i>//Copie de user vers form</font></i><BR>
> MoncompteForm moncompteForm = (MoncompteForm) form;<BR>
> PropertyUtils.copyProperties(moncompteForm, user);<BR> <BR> <font
> color="#aa0000"><i>//Attache un synchroniser token pour eviter le double
> posting</font></i><BR> saveToken(request);<BR> <BR> <font
> color="#aa0000"><i>//Renvoie vers moncompte</font></i><BR> <b>return</b>
> mapping.findForward(<font color="#000099">"moncompte"</font>); <BR> }
> <BR>}<BR></pre><BR>STRUTS-CONFIG.XML<BR>*****************<BR><pre><BR>....<B
> R><!-- ========== Global Forward Definitions
> ============================== --><BR> <global-forwards><BR>
> <forward name=<font color="#000099">"index"</font> path=<font
> color="#000099">"/index.jsp"</font>/><BR> <forward name=<font
> color="#000099">"logon"</font> path=<font
> color="#000099">"/logon.jsp"</font>/><BR> <forward name=<font
> color="#000099">"acceuilUser"</font> path=<font
> color="#000099">"/acceuilUser.jsp"</font>/><BR> <forward name=<font
> color="#000099">"moncompte"</font> path=<font
> color="#000099">"/moncompte.jsp"</font>/><BR>
> </global-forwards><BR>......<BR><!-- process an edit
> moncompte --><BR> <action path=<font
> color="#000099">"/editMonCompte"</font><BR> type=<font
> color="#000099">"eshop.actions.EditMonCompteAction "</font><BR>
> attribute=<font color="#000099">"moncompteForm"</font><BR>
> scope=<font color="#000099">"request"</font><BR> validate=<font
> color="#000099">"false"</font>/>
> <BR>......<BR></pre><BR>MONCOMPTEFORM<BR>*************<BR><pre><BR ><b>public
> </b> <b>class</b> MoncompteForm <b>extends</b> ValidatorForm{<BR>....<BR>
> <b>private</b> String nom;<BR> <b>private</b> String prenom;<BR>
> <b>private</b> String password;<BR>....<BR> <b>public</b> <b>void</b>
> setNom(String nom) {<b>this</b>.nom=nom;}<BR> <b>public</b> <b>void</b>
> setPassword(String password) {<b>this</b>.password = password;}<BR>
> <b>public</b> <b>void</b> setPrenom(String prenom)
> {<b>this</b>.prenom=prenom;}<BR>....<BR> <b>public</b> String getNom()
> {System.out.println(<font color="#000099">"entr?e dans
> MonCOmpteForm.getNom"</font>);<b>return</b> nom;}<BR> <b>public</b> String
> getPassword(){<b>return</b> password;}<BR> <b>public</b> String getPrenom()
> {<b>return</b>
> prenom;}<BR>}<BR></pre><BR><BR>USER<BR>****<BR><pre><BR><b>public</b>
> <b>class</b> User {<BR>...<BR> <b>private</b> String nom;<BR> <b>private</b>
> String prenom;<BR> <b>private</b> String password;<BR>...<BR> <b>public</b>
> <b>void</b> setNom(String nom) {<b>this</b>.nom=nom; <BR> <b>public</b>
> <b>void</b> setPassword(String password) {<b>this</b>.password =
> password;}<BR> <b>public</b> <b>void</b> setPrenom(String prenom)
> {<b>this</b>.prenom=prenom;}<BR>....<BR>ublic String getNom() {<b>return</b>
> nom;}<BR> <b>public</b> String getPassword(){<b>return</b> password;}<BR>
> <b>public</b> String getPrenom() {<b>return</b>
> prenom;}<BR>}<BR></pre><BR>when the editMonCompte.execute() methode is
> performed, i have display the content of the form, and its property
> reflected those of the object USER, but nothing is displayed in the
> moncompte.jsp, which use ofcourse the struts html taglib (html:text,
> html:submit....)<BR><BR>i don't understand what's wrong with my
> code<BR>thanks for your help.
> </html>