Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Struts and the fly likes Retrieving prepopulated form values in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Retrieving prepopulated form values in jsp" Watch "Retrieving prepopulated form values in jsp" New topic
Author

Retrieving prepopulated form values in jsp

Jera Blade
Greenhorn

Joined: May 08, 2005
Posts: 15
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jera Blade
Greenhorn

Joined: May 08, 2005
Posts: 15
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

Joined: May 24, 2005
Posts: 11
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.


Ryan Dillon<br />Code Canvas Technologies<br />RapidJ - Rapid Java Web Development<br /><a href="http://www.codecanvas.com.au/rapidj/" target="_blank" rel="nofollow">http://www.codecanvas.com.au/rapidj/</a>
Jera Blade
Greenhorn

Joined: May 08, 2005
Posts: 15
Thanks

thats what it was i was referencing the wrong form when adding to the session.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieving prepopulated form values in jsp
 
Similar Threads
multi-step user registration ?
Problem Passing Parameter values to action
No getter method for property ename of bean org.apache. struts.taglib.html. BEAN
DynaValidatorActionForm not working
servlet or jsp page with prefilled forms