*
The moose likes Struts and the fly likes how to populate values in jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to populate values in jsp page" Watch "how to populate values in jsp page" New topic
Author

how to populate values in jsp page

sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
Hi Ranchers,

I have link called Details,when i click on the link,appropriate function is called and a new page is shown with the form elements populated,
but for me the elements values are not getting populated..

<html:link page="/PatientDetails.do?action=getPatientDetails">Details</html:link>
------------------------
struts-config.xml
--------------------------
<action-mappings>
<action
path="/PatientDetails"
type="ssl.phr.patientdemographics.actionservlet.PatientAction"
name="PatientDetailsForm"
scope="request"
validate="true"
parameter="action"
input="/patientregistration.jsp">
<forward name="success" path="/patientregistrationcard.jsp"/>
<forward name="patientdetails" path="/patientdetails.jsp"/>
</action>

-----------------------
part of action class
-------------------------
public ActionForward getPatientDetails(ActionMapping mapping,
ActionForm form,HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException {

HttpSession session = request.getSession();
PatientDetailsDAO dao= new PatientDetailsDAO();
//int patientID;
String userName=(String)session.getAttribute("userName");
int pid=((Integer)session.getAttribute("patientID")).intValue();

response.setContentType("text/html");
PrintWriter out = response.getWriter();

PatientDetailsForm pdform =(PatientDetailsForm) form;

pdform=(PatientDetailsForm)dao.retrieveRecord(pid);


return mapping.findForward(Patientdetials);


} // end PatientDetails

-------------------

here is my jsp page
-----------------------

<html:form method="post" action="/patientRegistration">
<html:text property="firstName" size="30" styleClass="formtext-1"/>
<html:text property="middleInitial" size="30" styleClass="formtext-1" />
<html:text property="lastName" size="30" styleClass="formtext-1" />
</html:form>

----------------

how to use value attribute here

help me out..

Thanks
[ March 22, 2007: Message edited by: sreenivas jeenor ]
sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
help me in solving the problem,its urgent
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Tell us what you've done so far to try to solve the problem. Have you placed System.out.println() statements at various points to see if the values are what you expect them to be?


Merrill
Consultant, Sima Solutions
sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
System.out.println("values.... "+pdform.getFirstName()); code is placed in the action class.I am able to see the value in the log file.

Should i keep pdform object in request/session scope to get them in jsp page?
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
Can you paste the <action> defined in struts-config.xml corresponding to the path "/PatientDetails" ?
sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
<action-mappings>
<action
path="/PatientDetails"
type="ssl.phr.patientdemographics.actionservlet.PatientAction"
name="PatientDetailsForm"
scope="request"
validate="true"
parameter="action"
input="/patientregistration.jsp">
<forward name="success" path="/patientregistrationcard.jsp"/>
<forward name="patientdetails" path="/patientdetails.jsp"/>
</action>
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
I think I may have found the problem.


In the first line of the above code, form is the action form bean that is created and stored in request scope.

In line 2, you are retrieving a new instance of the PatientDetailsForm and referencing it in via variable pdform. So now you have 2 instances of PatientDetailsForm, one that is in request scope (that was passed to the action method) and the one returned from the DAO. The request scope form is still empty.

You can copy the properties from one bean to the other using

OR

You can forcibly set the one returned by the DAO in request scope so that it overwrites the existing empty instance (key="PatientDetailsForm").

Let us know if this works.
[ March 22, 2007: Message edited by: Sheldon Fernandes ]
sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
Thanks Sheldon

i placed the following code in the action class

request.setAttribute("PatientDetailsForm",pdform);

now i am able to populate the values.

the difference is beautifully explained...

Thanks again
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
I'm glad that worked. You are welcome sreenivas.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to populate values in jsp page
 
Similar Threads
Ajax, Struts, and a few pesky event based issues
html:link and form
can i call DispatchAction from global forward
DispatchAction No action instance for path ...
module switching problem