You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Brian Pontarelli <br...@pontarelli.com> on 2007/04/02 19:09:23 UTC
XWork and OGNL question
I'm playing around with Guice as an ObjectFactory and I've run into an
issue. I've got an action that I want to handle an array of values from
a form using the [] notation. My form looks something like:
<input type="text" name="numbers[0]"/>
<input type="text" name="numbers[1]"/>
...
My action is roughly:
public class Update extends ActionSupport {
private int[] numbers;
// getter and setter
}
What I've found is that when the ParametersInterceptor is called it
delegates to Ognl and rather than Ognl creating the array and doing all
the type conversions it is passing control over to Guice and asking
Guice to instantiate an instance of int[], which of course fails. Is
this correct or am I missing something between Ognl, XWork and Guice? Or
is Guice not playing nice and handing back control to Ognl or XWork like
it is supposed to?
Thanks,
-bp
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: XWork and OGNL question
Posted by Brian Pontarelli <br...@pontarelli.com>.
Okay, I figured I would do some digging around the old WebWork lists and
I figured out the issue.
Struts doesn't support array creation due to an issue with size
determination. Kinda what I though earlier. So, I've changed it over to
use a List<Integer> and that works fine.
The docs are very misleading on this point. I'd be more than happy to
clean up the type conversion doc and also create an collection handling
doc to help folks out with this issue. Let me know if I can help out at all.
Thanks,
-bp
Brian Pontarelli wrote:
> Okay, some more on this.
>
> This is not a Guice issue. This might not be an issue at all. Since
> the docs didn't really have any good array examples, I just made some
> assumptions, which might actually be incorrect - still waiting for the
> final verdict from a Struts committer. I removed the Guice code and
> went through everything again and it does appear that this doesn't
> work. Ognl appears to call the getter for the array, which returns
> null, and then just bails because it can't set the value into null.
>
> Is there anyway to handle creation of arrays from the parameters in
> the form foo[0], foo[1], etc? Or do I need to write the additional
> code for managing a list internally or using an indexed setter?
>
> thx,
> -bp
>
>
>
> Brian Pontarelli wrote:
>> Yeah, it looks like it goes all the way through the Ognl stack and
>> out to the ObjectFactory. Not sure why this is happening since
>> supposedly it should handle arrays, collections, Maps, etc. I'm gonna
>> grab the Ognl code and see if I can track this puppy down. If anyone
>> has info, please send it my way.
>>
>> thanks,
>> -bp
>>
>>
>> Bob Lee wrote:
>>> Are you using the Guice Struts 2 plugin? I didn't realize Struts 2
>>> would
>>> delegate to the ObjectFactory to create an int[].
>>>
>>> Bob
>>>
>>> On 4/2/07, Brian Pontarelli <br...@pontarelli.com> wrote:
>>>>
>>>>
>>>> I'm playing around with Guice as an ObjectFactory and I've run into an
>>>> issue. I've got an action that I want to handle an array of values
>>>> from
>>>> a form using the [] notation. My form looks something like:
>>>>
>>>> <input type="text" name="numbers[0]"/>
>>>> <input type="text" name="numbers[1]"/>
>>>> ...
>>>>
>>>> My action is roughly:
>>>>
>>>> public class Update extends ActionSupport {
>>>> private int[] numbers;
>>>> // getter and setter
>>>> }
>>>>
>>>> What I've found is that when the ParametersInterceptor is called it
>>>> delegates to Ognl and rather than Ognl creating the array and doing
>>>> all
>>>> the type conversions it is passing control over to Guice and asking
>>>> Guice to instantiate an instance of int[], which of course fails. Is
>>>> this correct or am I missing something between Ognl, XWork and
>>>> Guice? Or
>>>> is Guice not playing nice and handing back control to Ognl or XWork
>>>> like
>>>> it is supposed to?
>>>>
>>>> Thanks,
>>>> -bp
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: dev-help@struts.apache.org
>>>>
>>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
>> For additional commands, e-mail: dev-help@struts.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: XWork and OGNL question
Posted by Brian Pontarelli <br...@pontarelli.com>.
Okay, some more on this.
This is not a Guice issue. This might not be an issue at all. Since the
docs didn't really have any good array examples, I just made some
assumptions, which might actually be incorrect - still waiting for the
final verdict from a Struts committer. I removed the Guice code and went
through everything again and it does appear that this doesn't work. Ognl
appears to call the getter for the array, which returns null, and then
just bails because it can't set the value into null.
Is there anyway to handle creation of arrays from the parameters in the
form foo[0], foo[1], etc? Or do I need to write the additional code for
managing a list internally or using an indexed setter?
thx,
-bp
Brian Pontarelli wrote:
> Yeah, it looks like it goes all the way through the Ognl stack and out
> to the ObjectFactory. Not sure why this is happening since supposedly
> it should handle arrays, collections, Maps, etc. I'm gonna grab the
> Ognl code and see if I can track this puppy down. If anyone has info,
> please send it my way.
>
> thanks,
> -bp
>
>
> Bob Lee wrote:
>> Are you using the Guice Struts 2 plugin? I didn't realize Struts 2 would
>> delegate to the ObjectFactory to create an int[].
>>
>> Bob
>>
>> On 4/2/07, Brian Pontarelli <br...@pontarelli.com> wrote:
>>>
>>>
>>> I'm playing around with Guice as an ObjectFactory and I've run into an
>>> issue. I've got an action that I want to handle an array of values from
>>> a form using the [] notation. My form looks something like:
>>>
>>> <input type="text" name="numbers[0]"/>
>>> <input type="text" name="numbers[1]"/>
>>> ...
>>>
>>> My action is roughly:
>>>
>>> public class Update extends ActionSupport {
>>> private int[] numbers;
>>> // getter and setter
>>> }
>>>
>>> What I've found is that when the ParametersInterceptor is called it
>>> delegates to Ognl and rather than Ognl creating the array and doing all
>>> the type conversions it is passing control over to Guice and asking
>>> Guice to instantiate an instance of int[], which of course fails. Is
>>> this correct or am I missing something between Ognl, XWork and
>>> Guice? Or
>>> is Guice not playing nice and handing back control to Ognl or XWork
>>> like
>>> it is supposed to?
>>>
>>> Thanks,
>>> -bp
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: dev-help@struts.apache.org
>>>
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: XWork and OGNL question
Posted by Brian Pontarelli <br...@pontarelli.com>.
Yeah, it looks like it goes all the way through the Ognl stack and out
to the ObjectFactory. Not sure why this is happening since supposedly it
should handle arrays, collections, Maps, etc. I'm gonna grab the Ognl
code and see if I can track this puppy down. If anyone has info, please
send it my way.
thanks,
-bp
Bob Lee wrote:
> Are you using the Guice Struts 2 plugin? I didn't realize Struts 2 would
> delegate to the ObjectFactory to create an int[].
>
> Bob
>
> On 4/2/07, Brian Pontarelli <br...@pontarelli.com> wrote:
>>
>>
>> I'm playing around with Guice as an ObjectFactory and I've run into an
>> issue. I've got an action that I want to handle an array of values from
>> a form using the [] notation. My form looks something like:
>>
>> <input type="text" name="numbers[0]"/>
>> <input type="text" name="numbers[1]"/>
>> ...
>>
>> My action is roughly:
>>
>> public class Update extends ActionSupport {
>> private int[] numbers;
>> // getter and setter
>> }
>>
>> What I've found is that when the ParametersInterceptor is called it
>> delegates to Ognl and rather than Ognl creating the array and doing all
>> the type conversions it is passing control over to Guice and asking
>> Guice to instantiate an instance of int[], which of course fails. Is
>> this correct or am I missing something between Ognl, XWork and Guice? Or
>> is Guice not playing nice and handing back control to Ognl or XWork like
>> it is supposed to?
>>
>> Thanks,
>> -bp
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
>> For additional commands, e-mail: dev-help@struts.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: XWork and OGNL question
Posted by Bob Lee <cr...@crazybob.org>.
Are you using the Guice Struts 2 plugin? I didn't realize Struts 2 would
delegate to the ObjectFactory to create an int[].
Bob
On 4/2/07, Brian Pontarelli <br...@pontarelli.com> wrote:
>
>
> I'm playing around with Guice as an ObjectFactory and I've run into an
> issue. I've got an action that I want to handle an array of values from
> a form using the [] notation. My form looks something like:
>
> <input type="text" name="numbers[0]"/>
> <input type="text" name="numbers[1]"/>
> ...
>
> My action is roughly:
>
> public class Update extends ActionSupport {
> private int[] numbers;
> // getter and setter
> }
>
> What I've found is that when the ParametersInterceptor is called it
> delegates to Ognl and rather than Ognl creating the array and doing all
> the type conversions it is passing control over to Guice and asking
> Guice to instantiate an instance of int[], which of course fails. Is
> this correct or am I missing something between Ognl, XWork and Guice? Or
> is Guice not playing nice and handing back control to Ognl or XWork like
> it is supposed to?
>
> Thanks,
> -bp
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>