aspose file tools*
The moose likes Struts and the fly likes How can I change the value of a bean ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How can I change the value of a bean ?" Watch "How can I change the value of a bean ?" New topic
Author

How can I change the value of a bean ?

Juarez Alvares Barbosa Junior
Ranch Hand

Joined: Mar 18, 2002
Posts: 80
How can I change the value of a bean ?
If I want to expose its value, I can use
<bean:write.../> but what if I want to change some property value ?
I checked the struts-bean library documentation and did not find anything...
If there's another library (commons ?) will be suitable as well.
Juarez
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5018
    
    8

I suppose you could use the <jsp:setProperty> tag but you don't normally go changing bean values in your JSP when you are working with the Struts framework. Why do you want to do that? Why do you think it should be done in the JSP?
[ March 26, 2003: Message edited by: Junilu Lacar ]

Junilu - [How to Ask Questions] [How to Answer Questions]
Juarez Alvares Barbosa Junior
Ranch Hand

Joined: Mar 18, 2002
Posts: 80
Yes, I tried this approach but it did not work.
This is a known workaround for fixing the checkboxes problems in Struts (unchecked ones are not included in the request).
<html:checkbox name="autorizacaoForm" property="inclusive" value="S"/>
<jsp:setProperty name="autorizacaoForm" property="inclusive" value="N"/>
This approach does work in a single jsp page but it's not working when using Tiles...
I have just checked Class PropertyUtils from commons-beanutils but it doesn't find the right prop (perhaps because I am using a DynaValidatorActionForm and its props are in a Map).
Thanks for helping.
Juarez
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5018
    
    8

The fix to the checkbox problem is to override the ActionForm.reset method and in there, set the property that corresponds to the checkbox to its default, unchecked value. When the request comes in, only properties that have corresponding request parameter values are set. If the checkbox is unchecked, then the form property will retain the default or unchecked value.
Edit #1: This is when you have a regular ActionForm though. Not too sure about the DynaForm.
Edit #2: Just read through your other posts and saw that you've tried the reset() approach. I'll have to explore this DynaForm thing because I honestly haven't used it before.
[ March 26, 2003: Message edited by: Junilu Lacar ]
Juarez Alvares Barbosa Junior
Ranch Hand

Joined: Mar 18, 2002
Posts: 80
Hi,
I have fixed the problem, using the c:set tag of
JSTL.
The reset is not working due to the fact that the property bound to my checkbox is a String, not a Boolean.
Thanks a lot for helping,
Juarez
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5018
    
    8

And thanks for the feedback
 
 
subject: How can I change the value of a bean ?