• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I change the value of a bean ?

 
Juarez Alvares Barbosa Junior
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7602
54
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Juarez Alvares Barbosa Junior
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7602
54
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7602
54
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And thanks for the feedback
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic