permaculture playing cards*
The moose likes Struts and the fly likes Want to call a method rather than property in html:text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Want to call a method rather than property in html:text" Watch "Want to call a method rather than property in html:text" New topic
Author

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

Tanveer Rameez
Ranch Hand

Joined: Dec 11, 2000
Posts: 158
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


Author of JPhotoBrush Pro (www.jphotobrushpro.com)
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
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

Joined: Dec 11, 2000
Posts: 158
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Want to call a method rather than property in html:text
 
Similar Threads
access form field element
Struts: No getter method for property name problem
How to display string array value in jsp for html:text box
Garbage Values in TextBoxes
Accessing formbean