
|
If you were logged in you would be able to see more operations.
|
|
|
|
I am using WW 2.0 and I need to let the user input a 2 dimensional array of
values (String[][] amount), while the size of the dimensions are determined at
runtime.
To do this I create textfields in my jsp using two iterators to produce
indexed names like: 'amount[0][0]', 'amount[0][1]', ..., 'amount[1][0]', ...
When the user submits his input, Ognl raises an IllegalArgumentException:
java.lang.IllegalArgumentException: array element type mismatch
at java.lang.reflect.Array.set(Native Method)
at ognl.ArrayPropertyAccessor.setProperty(ArrayPropertyAccessor.java:120)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1460)
at ognl.ASTProperty.setValueBody(ASTProperty.java:105)
at ognl.SimpleNode.setValue(SimpleNode.java:215)
at ognl.ASTChain.setValueBody(ASTChain.java:172)
at ognl.SimpleNode.setValue(SimpleNode.java:215)
at ognl.Ognl.setValue(Ognl.java:478)
at com.opensymphony.xwork.util.OgnlValueStack.setValue(OgnlValueStack.java:83)
at com.opensymphony.xwork.util.OgnlValueStack.setValue(OgnlValueStack.java:74)
at
com.opensymphony.xwork.interceptor.ParametersInterceptor.before(ParametersInterceptor.java:44)
After carefully looking, I saw that the problem was that the submitted
parameter values were String arrays with length 1. This may be the problem that Ognl can't set the array String element with a String array.
I try in the debugger to set a single String value instead of an array String in ParametersInterceptor:
this line=> stack.setValue(entry.getKey().toString(), entry.getValue());
Now I see that the right value is set in the property amount.
|
|
Description
|
I am using WW 2.0 and I need to let the user input a 2 dimensional array of
values (String[][] amount), while the size of the dimensions are determined at
runtime.
To do this I create textfields in my jsp using two iterators to produce
indexed names like: 'amount[0][0]', 'amount[0][1]', ..., 'amount[1][0]', ...
When the user submits his input, Ognl raises an IllegalArgumentException:
java.lang.IllegalArgumentException: array element type mismatch
at java.lang.reflect.Array.set(Native Method)
at ognl.ArrayPropertyAccessor.setProperty(ArrayPropertyAccessor.java:120)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1460)
at ognl.ASTProperty.setValueBody(ASTProperty.java:105)
at ognl.SimpleNode.setValue(SimpleNode.java:215)
at ognl.ASTChain.setValueBody(ASTChain.java:172)
at ognl.SimpleNode.setValue(SimpleNode.java:215)
at ognl.Ognl.setValue(Ognl.java:478)
at com.opensymphony.xwork.util.OgnlValueStack.setValue(OgnlValueStack.java:83)
at com.opensymphony.xwork.util.OgnlValueStack.setValue(OgnlValueStack.java:74)
at
com.opensymphony.xwork.interceptor.ParametersInterceptor.before(ParametersInterceptor.java:44)
After carefully looking, I saw that the problem was that the submitted
parameter values were String arrays with length 1. This may be the problem that Ognl can't set the array String element with a String array.
I try in the debugger to set a single String value instead of an array String in ParametersInterceptor:
this line=> stack.setValue(entry.getKey().toString(), entry.getValue());
Now I see that the right value is set in the property amount.
|
Show » |
|
-------------
Hi,
I am using Ognl in combination with WebWork 2.0 and encounter a problem when
setting an indexed named property, for example 'amount[0]', after a user
submit. WebWork 2.0 is using Ognl 2.6.3.
WebWork tries to set 'amount[0]' with a String array, because HTTP allows
multiple values using the same parameter name. It is using Ognl to do this
job, but then Ognl is throwing an IllegalArgumentException:
java.lang.IllegalArgumentException: array element type mismatch
at java.lang.reflect.Array.set(Native Method)
at ognl.ArrayPropertyAccessor.setProperty(ArrayPropertyAccessor.java:120)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1460)
at ognl.ASTProperty.setValueBody(ASTProperty.java:105)
at ognl.SimpleNode.setValue(SimpleNode.java:215)
at ognl.ASTChain.setValueBody(ASTChain.java:172)
at ognl.SimpleNode.setValue(SimpleNode.java:215)
at ognl.Ognl.setValue(Ognl.java:478)
at
com.opensymphony.xwork.util.OgnlValueStack.setValue(OgnlValueStack.java:83)
at
com.opensymphony.xwork.util.OgnlValueStack.setValue(OgnlValueStack.java:74)
at
com.opensymphony.xwork.interceptor.ParametersInterceptor.before(ParametersInterceptor.java:44)
If the property name is not indexed, the custom TypeConvertor inside WebWork
is invoked and they handle the String array conversion properly by returning
the first value in the array if the array length is 1. But setting an indexed
named property never triggers the TypeConvertor.
After debugging through the sources of both WebWork and Ognl, I see that the
ArrayPropertyAccessor will just do an Array.set call to set the array element
and that is the source of the problem. A non-indexed property name will use
the ObjectPropertyAccessor which eventually will use the TypeConvertor to do
the conversion, but for an array this never happens.
I looked in the sources of bith 3.0.0 and 2.6.5 Ognl versions and this problem
still exist in both versions. Array.set is called if the index is a number.
A solution is to catch the IllegalArgumentException and invoke the setProperty
method in its super class (ObjectPropertyAccessor in 2.6.3) if this happens.
Or check the type of the value first before setting the value and then pass
the call to the setProperty in the super class if the type does not match.