Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving prepopulated form values in jsp

 
Jera Blade
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am a bit stuck on how to get the values i populated in a form bean in a action class to be displayed in my JSP.

I want to edit a user. Thus the user selects edit from the search screen and it goes to the editaction.class. In this class I populate a form bean lets call it editForm bean and put this into the session using the following code:

EditForm updateForm = new EditForm();
updateForm.setFirstName("xxxxxxxx");
HttpSession session = httpServletRequest.getSession();
//httpServletRequest.setAttribute("updateForm", updateForm);
session.setAttribute("updateForm", updateForm);

The action class forwards onto the edit jsp which lets the user edit the first name.

however the value xxxxxxxx does not appear in the html text element of the jsp.

<td width="16%" height="36">
<html:text property="firstName"></html:text>
</td>

This will then be submitted again and is enclosed within a html:form tag which is not shown here.

Can anyone advise me on what I am doing wrong.
Thanks
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jera,
Welcome to JavaRanch!

My guess is that the form is pointing to a different bean. Try posting the html:form tag and the relevant part of the struts config file.
 
Jera Blade
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My struts config is as follows:

<action path="/actionClient"
type="com.medina.web.action.ActionClientAction"
name="actionClientForm"
scope="request"
input="/searchClient.jsp">
<forward name="edit" path="/editClient.jsp"/>
</action>

The above action is called from the search page when i click the link edit.
I then put the createClientForm form in the session in this action class with the code posted previously. Should I be using actionClientForm here and why? as this does not hold the info I want displayed

<action path="/updateClient"
type="com.medina.web.action.UpdateClientAction"
name="createClientForm"
scope="request"
parameter="update"
input="/editClient.jsp">
<forward name="failure" path="/jsp/failure.jsp"/>
<forward name="success" path="/jsp/success.jsp"/>
</action>

This is the updateClient action referred to in the edit jsp

In my edit jSP I have the following form tag:

<html:form action="/updateClient"
name="createClientForm"
type="com.medina.web.forms.CreateClientForm">

<td width="7%" height="36">
<div align="center">First Name:</div>
</td>
<td width="16%" height="36">
<html:text property="firstName"></html:text>
</td>

thanks
 
Ryan Dillon
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jera,

A couple of things. First I don't think you need to manually create and set the EditForm in the request. If you have defined the form in struts-config.xml and associated it with your action then it will be created automatically by struts and made available to you in the execute method.

However your example should still work. I think the problem there is that you have put the form under "updateForm" but in the JSP the action is "updateClient" which uses the form "createClientForm".

Hope that helps.
 
Jera Blade
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

thats what it was i was referencing the wrong form when adding to the session.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic