You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Rohra, Prakash N. ,,DMDC/BEAU" <RO...@osd.pentagon.mil> on 2002/10/08 21:01:51 UTC

How to get data back from ActionForm to HTML form

Hello..

I am a newbie to Struts. While reading the documentation, I gathered that
"ActionForm" objects can be used to move data back and forth between HTML
forms fields and ActionForm properties by using the formBeans.

With proper entries in struts-congif.xml, Struts framework automatically
creates the instance of "ActionForm" class and populates its properties
based on the HTTP Post Request parameters while submitting a HTML form. I
can see the form values in m y ActionForm and also in Action class.

However, how do I achieve the same thing backwards. I mean, if I retrieve or
generate some values in a Action class code, and populate these values in
the ActionForm by calling myForm.setXXX(), I don't see these values
appearing in the corresponding HTML form that gets forwarded by my Action.

here is the part of my struts-config.xml

    <form-bean      name="personnelForm"
                    type="blankApp.PersonnelForm"/>


    <action    path="/getpersonnel"
               type="blankApp.PersonnelAction"
               name="personnelForm"
              scope="request"
              input="/personnel.jsp" >
             <forward name="success"   path="/personnel.jsp" />
    </action>

Here is the code from PersonnelAction.java:

public ActionForward execute(ActionMapping mapping,
				 ActionForm form,
				 HttpServletRequest request,
				 HttpServletResponse response)
  	throws Exception 
{

      PersonnelForm fForm = (PersonnelForm)form;
      fForm.setRank("RANK");
      fForm.setPaygrade("PG");

      System.out.println(fForm.getRank());
      System.out.println(fForm.getPaygrade());

}


Where rank, paygrade are properties of PersonnelForm.java and also defined
as html:text in personnel.jsp.

When I execute the /getpersonnel.do action, I see my code getting executed
in PersonnelAction.java, but muy text fields in HTML form generated by
personnel.jsp are blank. I expected it to display the data from
PersonnelForm properties.

What am I doing wrong?

thanks

-Prakash




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: How to get data back from ActionForm to HTML form

Posted by William Wan <wi...@netvigator.com>.
You have to add 
request.setAttribute("personnelForm ", fForm);
in the action so that the form will be stored in the request for
population in jsp. Otherwsie the tForm will only be available within
your action scope only.

-----Original Message-----
From: Rohra, Prakash N. ,,DMDC/BEAU [mailto:ROHRAPN@osd.pentagon.mil] 
Sent: Wednesday, October 09, 2002 3:02 AM
To: 'struts-user@jakarta.apache.org'
Subject: How to get data back from ActionForm to HTML form

Hello..

I am a newbie to Struts. While reading the documentation, I gathered
that
"ActionForm" objects can be used to move data back and forth between
HTML
forms fields and ActionForm properties by using the formBeans.

With proper entries in struts-congif.xml, Struts framework automatically
creates the instance of "ActionForm" class and populates its properties
based on the HTTP Post Request parameters while submitting a HTML form.
I
can see the form values in m y ActionForm and also in Action class.

However, how do I achieve the same thing backwards. I mean, if I
retrieve or
generate some values in a Action class code, and populate these values
in
the ActionForm by calling myForm.setXXX(), I don't see these values
appearing in the corresponding HTML form that gets forwarded by my
Action.

here is the part of my struts-config.xml

    <form-bean      name="personnelForm"
                    type="blankApp.PersonnelForm"/>


    <action    path="/getpersonnel"
               type="blankApp.PersonnelAction"
               name="personnelForm"
              scope="request"
              input="/personnel.jsp" >
             <forward name="success"   path="/personnel.jsp" />
    </action>

Here is the code from PersonnelAction.java:

public ActionForward execute(ActionMapping mapping,
				 ActionForm form,
				 HttpServletRequest request,
				 HttpServletResponse response)
  	throws Exception 
{

      PersonnelForm fForm = (PersonnelForm)form;
      fForm.setRank("RANK");
      fForm.setPaygrade("PG");

      System.out.println(fForm.getRank());
      System.out.println(fForm.getPaygrade());

}


Where rank, paygrade are properties of PersonnelForm.java and also
defined
as html:text in personnel.jsp.

When I execute the /getpersonnel.do action, I see my code getting
executed
in PersonnelAction.java, but muy text fields in HTML form generated by
personnel.jsp are blank. I expected it to display the data from
PersonnelForm properties.

What am I doing wrong?

thanks

-Prakash




--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>