Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Want to call a method rather than property in html:text

 
Tanveer Rameez
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a struts html tag:
<html:text name="myFormBean" property="myProperty" />
I want to call a method instead of the property, i.e I want something like this:
<html:text name="myFormBean" property="someMethod" />
the someMethod returns a string and has signature : public String someMethod().
How do I do it?
Also I would like to have a set method so that the value can be set though that method, rather than set directly into a property.The method can be public void someMethod(String s);
Is there anything like get-method and set-method attribute in the html:text to use?
Thanks in Advance
Tanveer
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm afraid you have to stick to java bean conventions, which requires getters and setters for the values you want to obtain.

but: that's a feature, not a bug :-)

Is there any specific reason why your String has to be obtained through someMethod() instead of getSomeString()?

bye,
jan
[ October 13, 2006: Message edited by: Jan Groth ]
 
Tanveer Rameez
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jan Groth:

Is there any specific reason why your String has to be obtained through someMethod() instead of getSomeString()?


I want the value to be determined at runtime based on certain conditions. The value in the form bean property is set once but meanwhile certain conditions changes and so only the displayed value should change(while the property should remain same).
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34378
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tanveer,
Your get and set methods could do that though. There is nothing dictating that a getter can only return a property and a setter can only store a property. You can do validation, calculations, etc within the standard named methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic