http://jakarta.apache.org/commons/beanutils/api/index.html
Specifically, the work is done by o.a.struts.util.RequestUtils.populate(...), which makes a call to the static form of o.a.c.beanutils.BeanUtils.populate:
http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/beanutils/BeanUtils.html#populate(java.lang.Object,%20java.util.Map)
The static form relies on Converter classes statically registered using o.a.c.beanutils.ConvertUtils.register(...):
http://jakarta.apache.org/commons/beanutils/api/org/apache/commons/beanutils/ConvertUtils.html#register(org.apache.commons.beanutils.Converter,%20java.lang.Class)
So basically, assuming that there's exactly one conversion path from string to your object, you need to register a converter at app startup using a ServletContextListener or Plugin class.
BeanUtils has since evolved to provide more nuanced conversions (particularly not requiring that converters be registered statically) but there hasn't been call to upgrade Struts to use this. Date conversions are about the only place where I can see the need for multiple conversions from string to date in a single app. Meanwhile, managing temporary or limited-scope converters might be pretty clumsy to implement.
Hope this helps Joe
At 11:36 AM -0500 1/5/05, [EMAIL PROTECTED] wrote:
ActionForm attributes are defined as Strings. In your case, a good solution would be to define an adapter class that will do the conversion from String to the appropriate type. Your business objects will use the converted data types to execute the business logic. This approach is discussed in detail in the book Struts in Action.
Bala
-----Original Message----- From: dsarris [mailto:[EMAIL PROTECTED] Sent: Monday, January 03, 2005 4:16 AM To: Struts Users Mailing List Subject: ActionForm automatic type conversion
Hi all and happy new year,
I am trying to fill an ActionForm with values that are neither Strings or primitives. The specified values are selected using the <html:select> tag. This a sample of my JSP code:
<html:form action="/sumbit.do"> <html:select property="selectedAthlete"> <html:optionsCollection name="controlPanelValues" property="athletes" label="name" value="value" />
</html:select> <html:submit> <bean:message key="cp.button.submit"/> </html:submit> </html:form>
The "controlPanelValues" Bean contains a collection (list) named "athletes" containing Beans of type "Pair". The "Pair" object contains 2 attributes: The "name" which is a String and the value which is an "Athlete" object.
My ActionForm contains an attribute named "selectedAthlete" of the type "Athlete".
However, whenever I submit this form the "selectedAthlete" is filled with the string representation of the "Athlete" type.
I used both simple and map-backed actionform with no success.
Is Struts capable for doing assignment of non String or primitive fields?
Chipix
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Note: The information contained in this email and in any attachments is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. The recipient should check this email and any attachments for the presence of viruses. Sender accepts no liability for any damages caused by any virus transmitted by this email. If you have received this email in error, please notify us immediately by replying to the message and delete the email from your computer. This e-mail is and any response to it will be unencrypted and, therefore, potentially unsecure. Thank you. NOVA Information Systems, Inc.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--
Joe Germuska [EMAIL PROTECTED] http://blog.germuska.com "Narrow minds are weapons made for mass destruction" -The Ex
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]