File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Trying to set properties in my form with no luck Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Trying to set properties in my form with no luck" Watch "Trying to set properties in my form with no luck" New topic
Author

Trying to set properties in my form with no luck

Kimbo Inatl
Greenhorn

Joined: Jun 30, 2010
Posts: 11
I'm having a really bizarre problem... actually I'm probably just missing something obvious, but I can't seem to figure it out.

I'm writing a bean to the session here (facilityView is my bean with the getter/setter methods):



Here is the form definition in my struts config file:



(I only have two properties defined right now so that I can test it)

Here is a simple JSP I put together to test it out:



The logic:present stuff is what I've been using to debug. Here's the weird thing - outside of the html:form it says the bean exists, and outputs the correct values. Inside the html:form, though, it says the bean exists, but the values are blank. It seems like maybe Struts is overwriting the values I passed in the bean for some reason. I've got this set up exactly like one of my other forms (I think) which works fine. Any ideas?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Name the session bean something different (or define the form as session scope in the action config and stop doing it all manually).
Kimbo Inatl
Greenhorn

Joined: Jun 30, 2010
Posts: 11
Changing the scope from request to session in my action mapping fixed it. Thank you very much.

So why did this work? (I ask because I've got the scope set to "request" in many of my other action mappings, which all seem to work just fine)
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Once you're inside the form tag I'd imagine that non-scope-specific references to the bean name are referring to the form bean defined by the action config, rather than the session bean. (That sentence sucked; sorry.) If you intended them to be the same actual instance, then you don't need to set anything into session scope or use the jsp:useBean tag--it's just the form for that action, and it'll always be stored in the session.

If you *don't* want them to be the exact same instance, i.e. you want to transfer bean values, you'd need to name the session bean something different so there's no name collision, or just do it in the action itself (preferable).
Kimbo Inatl
Greenhorn

Joined: Jun 30, 2010
Posts: 11
OK, that makes perfect sense. I thought maybe that there was some sort of name collision going.

EDIT: Nevermind... silly question Thanks again for the help.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

There are no silly questions, only silly answers. Or something like that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to set properties in my form with no luck