You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by sagarlotiya <sa...@aspl.in> on 2007/11/20 11:28:17 UTC

Problem with struts2 iterator and ognl

Hi,
I have a iterator and i am loop through it in my jsp file and iterator
contains textbox.
Problem occurs when i am try to set the values directly on "Model" through
ognl.
any one has idea how to do that ?

e.g.
<s:iterator id="product" value="%{products}"  status="stat">
<s:textfield name="%{#roles.quantity}"
value="%{#product.quantity}"></s:textfield>
</s:iterator>

when i am trying to set the value through ognl directly on model without
going through action it didn't set it through ognl.

can any one tell me the solution?

-- 
View this message in context: http://www.nabble.com/Problem-with-struts2-iterator-and-ognl-tf4842578.html#a13854424
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Problem with struts2 iterator and ognl

Posted by Gary Affonso <gl...@greywether.com>.
sagarlotiya wrote:
> Hi,
> "not going through the action " means that, directly set on "Model bean"
> without going through action.

I don't think you want to avoid "going through the action".  You may not 
want the property to be a direct property of the action (and instead 
have it be a property of the model object) but in *both* cases you need 
the action to provide access to either the direct-action property, or 
the model object that contains your property.

You *can* avoid that and stick your model object somewhere else (like in 
the context, in the session, etc.) but why?  Just make the model object 
a property of the action and provide a getter in that same action.

> Otherewise what happen, first we have to get the value in our action using
> reqest.getParameter()

You probably don't want to do that.  You probably want to have the 
params interceptor translate the request parameters for you.  That way 
you get all the benefits of auto-type conversion, the conversion 
framework for custom conversions (if you need it), the validation 
framework, etc.

By processing params directly with request.getParameter() you're 
avoiding much of what makes S2 useful.

> or through getter/setter using paramPrepareParamStack
> and then set these values on "Model" from that action

You do not need the whole "params/prepare/params" sandwich to just get 
values from your forms injected into your model objects.

You just need *one* params interceptor in your stack, and then you need 
a *getter* for your model object in the action processing the incoming data.

In your form that feeds the action data, you use form-filed names like 
you're doing...

   <input type="foo" name="myModelObject.myProperty" />

As long as you've got a getter for the model object in the action that 
processes this form, ognl will call the getter, retrieve your model 
object, and then set values on the properties within that object.

OGNL will even instantiate the model object for you if you've left it 
null in the action.

> but i don't want to do
> that through ognl we can directly set the value on "Model" right ?

Right.  But you still need at least one params interceptor.  It's what 
does the work.

> It works
> fine for all cases but when if we will use Iterator at that time it creates
> problem.

In your iterator you're naming your textfield "roles".  The action that 
processes that form does have a "roles" object and a getter for that 
object, right?

If none of that helped, turn on debugging and watch your console (or 
stdout) while you submit the form.  It's very enlightening.

- Gary

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


Re: Problem with struts2 iterator and ognl

Posted by sagarlotiya <sa...@aspl.in>.
Hi,
"not going through the action " means that, directly set on "Model bean"
without going through action.
Otherewise what happen, first we have to get the value in our action using
reqest.getParameter() or through getter/setter using paramPrepareParamStack
and then set these values on "Model" from that action but i don't want to do
that through ognl we can directly set the value on "Model" right ? It works
fine for all cases but when if we will use Iterator at that time it creates
problem.


newton.dave wrote:
> 
> What do you mean by "not going through the action"?
> 
> d.
> 
> --- sagarlotiya <sa...@aspl.in> wrote:
> 
>> 
>> Hi,
>> I have a iterator and i am loop through it in my jsp
>> file and iterator
>> contains textbox.
>> Problem occurs when i am try to set the values
>> directly on "Model" through
>> ognl.
>> any one has idea how to do that ?
>> 
>> e.g.
>> <s:iterator id="product" value="%{products}" 
>> status="stat">
>> <s:textfield name="%{#roles.quantity}"
>> value="%{#product.quantity}"></s:textfield>
>> </s:iterator>
>> 
>> when i am trying to set the value through ognl
>> directly on model without
>> going through action it didn't set it through ognl.
>> 
>> can any one tell me the solution?
>> 
>> -- 
>> View this message in context:
>>
> http://www.nabble.com/Problem-with-struts2-iterator-and-ognl-tf4842578.html#a13854424
>> Sent from the Struts - User mailing list archive at
>> Nabble.com.
>> 
>> 
>>
> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> user-unsubscribe@struts.apache.org
>> For additional commands, e-mail:
>> user-help@struts.apache.org
>> 
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Problem-with-struts2-iterator-and-ognl-tf4842578.html#a13870755
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Problem with struts2 iterator and ognl

Posted by Dave Newton <ne...@yahoo.com>.
What do you mean by "not going through the action"?

d.

--- sagarlotiya <sa...@aspl.in> wrote:

> 
> Hi,
> I have a iterator and i am loop through it in my jsp
> file and iterator
> contains textbox.
> Problem occurs when i am try to set the values
> directly on "Model" through
> ognl.
> any one has idea how to do that ?
> 
> e.g.
> <s:iterator id="product" value="%{products}" 
> status="stat">
> <s:textfield name="%{#roles.quantity}"
> value="%{#product.quantity}"></s:textfield>
> </s:iterator>
> 
> when i am trying to set the value through ognl
> directly on model without
> going through action it didn't set it through ognl.
> 
> can any one tell me the solution?
> 
> -- 
> View this message in context:
>
http://www.nabble.com/Problem-with-struts2-iterator-and-ognl-tf4842578.html#a13854424
> Sent from the Struts - User mailing list archive at
> Nabble.com.
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 


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