GeeCON Prague 2014*
The moose likes Struts and the fly likes Prepoulating form fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Prepoulating form fields" Watch "Prepoulating form fields" New topic
Author

Prepoulating form fields

Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
I know I've seen this discussed previously, but I'm not having any luck searching the forum.

I'm trying to prepopulate some form fields from user information that is held in the session (things like name, email address etc).

I have a link that goes to a "setup action" where I check to see if a user is logged in, if they are I use myForm.setXX(user.getXX). Return mapping.findForward("continue") (which goes to the page that actually displays the form). Both actions in the config file have the same value for the name attribute. However the form is not showing any values (checking session variables, I know the user values are there.. just the form doesnt seem to be getting set).

-Tad
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Post what you have so far please.


A good workman is known by his tools.
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
Yeah ok, I figured out my problem the html:form name attribute needs to be the same name as the form attribute name in the struts config file duh.

-Tad
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
Jsp:

Setup action:
Struts-config



I'm baffeled... when I changed the form name from dataCorrection to DataCorrection it started working, despite the fact its different from whats in the config file. Although I just noticed in the setupaction I put the form in the request, under yet a different name than whats in the config file, maybe this is what has me confused.
[ December 16, 2004: Message edited by: Tad Dicks ]
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
Ok I'm at a loss why changing the name of the form from dataCorrection to DataCorrection causes it to work. Regardless of the name of the form in the struts-config is "dataCorrection" or "DataCorrection", or wether or not I load the form into the request "manually" inside the setup action. I don't think I can find any other place I refer to or name this form.

Should the name of the form inside the <html:form> tag (in the JSP) be the same as the name of the formbean as declared inside the struts-config file?


-Tad
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
Ok it was working... I had no idea how/why. Now its not working again no idea why it stopped, truly frustrating. I've tried changing so manythings.



the bean write at the bottom for property firstName writes out the correct value its stored there. Its just not being displayed in the form.

I followed the directions from the apache site the best I could. I have a seupt action and I set the values inside of that action and then do a forward to the above page.

-Tad
[ December 16, 2004: Message edited by: Tad Dicks ]
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
Ok I know I'm mostly rambling to myself here, but
changing:

<html:form name="dataCorrection" action="DataCorrectionSub" type="com.formBeans.DataCorrectionForm" focus="firstName">

to

<html:form action="DataCorrectionSub" focus="firstName">
fixed the problem?
does giving the form a name and type cause the page to create an new instance of the formBean class? How does teh form know what bean to associate to it?(through the action?).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Prepoulating form fields