You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by dsarris <ch...@gmail.com> on 2005/01/03 10:16:16 UTC

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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: ActionForm automatic type conversion

Posted by Pavel Kolesnikov <pa...@gmail.com>.
On Mon, 3 Jan 2005 11:16:16 +0200, dsarris <ch...@gmail.com> wrote:
> 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>

What about something like 

       <html:select property="selectedAthlete">
               <html:optionsCollection
                          name="controlPanelValues"
                          property="athletes"
                          label="name"
                          value="athleteId" />
       </html:select>

where athleteId is a primary key of "Athlete"?

Pavel

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: ActionForm automatic type conversion

Posted by dsarris <ch...@gmail.com>.
On Mon, 3 Jan 2005 17:46:46 +0100, Pavel Kolesnikov
<pa...@gmail.com> wrote:
> On Mon, 3 Jan 2005 11:16:16 +0200, dsarris <ch...@gmail.com> wrote:
> 
> > I am trying to fill an ActionForm with values that are neither Strings
> > or primitives.
> 
> I think you can do it by extending the RequestProcessor class
> and overloading "processPopulate" method or something like that.
> 
> But in general - I guess you should better avoid it. HTML forms are
> designed for sending String values typed by user and Struts layer
> (= ActionForms or Actions) should transform them into appropriate
> business objects.
> 
> If you tell us something about why you need it, it could be possible to
> find out better designed (IMHO) solution.
> 
> Pavel Kolesnikov

I am using Hibernate to retrieve information from DB (I have several
implemented DAO classes). The information retrieved is stored in Java
POJOs.

In order to integrate with Struts I have 2 choices:
1. Implement a model structure where I save all the information needed
from application.
2. Retrieve the information needed using DAO classes which will access the DB.

Do you have any other suggestions. I am going to use a mix of these 2
solutions.
That is, each application transaction will hold its temporary model
which will be discarded after the end of the transaction in order to
be used from all the action and JSP classes

Everything else is kept in DB.

chipix

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: ActionForm automatic type conversion

Posted by Pavel Kolesnikov <pa...@gmail.com>.
On Mon, 3 Jan 2005 11:16:16 +0200, dsarris <ch...@gmail.com> wrote:

> I am trying to fill an ActionForm with values that are neither Strings
> or primitives.

I think you can do it by extending the RequestProcessor class
and overloading "processPopulate" method or something like that.

But in general - I guess you should better avoid it. HTML forms are 
designed for sending String values typed by user and Struts layer
(= ActionForms or Actions) should transform them into appropriate
business objects.

If you tell us something about why you need it, it could be possible to
find out better designed (IMHO) solution. 

Pavel Kolesnikov

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org