• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to populate values in jsp page

 
sreenivas jeenor
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
help me in solving the problem,its urgent
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
sreenivas jeenor
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you paste the <action> defined in struts-config.xml corresponding to the path "/PatientDetails" ?
 
sreenivas jeenor
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad that worked. You are welcome sreenivas.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic