Setting HTML form parameters to Custom classes (not action support)

View: New views
2 Messages — Rating Filter:   Alert me  

Setting HTML form parameters to Custom classes (not action support)

by ravi_eze :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi,

we have multiple classes (C1,C2,C3) each as java beans. now i have a form as:
<s:form...>
<s:textfield name="a.field1" ../>
<s:textfield name="b.field1" ../>
<s:textfield name="c.field1" ../>

is it possible for me to populate the individual classes? The problem is that we need to build a framework in struts2 and it requires the above to happen.

After googling a lot... i found that that the current ActionSupport class is kept in ognl value stack which is later filled. If this is true then can we push the C1's object as a, C2's object as b etc into value stack???

Also, ModelInterceptor... would also push the object to the value stack. But my problem is that i need all the 3 objects into the stack...

please correct me if i am wrong... any help would be great...

cheers,
ravi

Re: Setting HTML form parameters to Custom classes (not action support)

by Jim Kiley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I would handle this by creating an ordinary Java class for the page, and
then having the following fields:

public class MyAction {
C1 a;
C2 b;
C3 c;

//...
}

...and make sure I had a public getA() and setA(), getB() and setB(), and so
on.

If you need to preset values for a, b, and c, one option is to have MyAction
implement Preparable, and put the pre-population in the prepare() method
that it requires.

jk

On Tue, May 13, 2008 at 1:16 AM, ravi_eze <ravichandrac@...>
wrote:

>
> hi,
>
> we have multiple classes (C1,C2,C3) each as java beans. now i have a form
> as:
> <s:form...>
> <s:textfield name="a.field1" ../>
> <s:textfield name="b.field1" ../>
> <s:textfield name="c.field1" ../>
>
> is it possible for me to populate the individual classes? The problem is
> that we need to build a framework in struts2 and it requires the above to
> happen.
>
> After googling a lot... i found that that the current ActionSupport class
> is
> kept in ognl value stack which is later filled. If this is true then can
> we
> push the C1's object as a, C2's object as b etc into value stack???
>
> Also, ModelInterceptor... would also push the object to the value stack.
> But
> my problem is that i need all the 3 objects into the stack...
>
> please correct me if i am wrong... any help would be great...
>
> cheers,
> ravi
> --
> View this message in context:
> http://www.nabble.com/Setting-HTML-form-parameters-to-Custom-classes-%28not-action-support%29-tp17201248p17201248.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>


--
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com