[ https://issues.apache.org/jira/browse/WW-4216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13794924#comment-13794924
]
Harigopal Patel commented on WW-4216:
-------------------------------------
/***************JSP*******************/
<form action="abc.action" id="myForm" name="myForm" method="post">
<s:hidden name="status" id="status" value="0"></s:hidden>
<input type="button" onclick="return submitForm();"/>
</form>
<script type="text/javascript">
function submitForm()
{
var f=document.myForm;
f.action = "abc.action?status=1";
f.submit();
}
</script>
/***************ACTION*******************/
public class AbcAction extends ActionSupport{
private int status;
public void setStatus(int status) {
this.status = status;
}
public int getStatus() {
return status;
}
}
/************ERROR*****************/
throws XWork ConversionError because status field datatype is int and value is String array
Object "value" is array (String status array value[1,0])
Class "toType" is int
XWorkBasicConverter.convertValue(Map context, Object o, Member member, String s, Object value,
Class toType)
> Error in XWorkBasicConverter.convertValue()
> -------------------------------------------
>
> Key: WW-4216
> URL: https://issues.apache.org/jira/browse/WW-4216
> Project: Struts 2
> Issue Type: Bug
> Affects Versions: 2.3.15.1
> Reporter: Harigopal Patel
> Fix For: 2.3.17
>
>
> if multiple name parameter in action then create string array
> ex :- abc.action?id=4&id=4&name=xyz
> Object value = string array [0=4,1=4]
> Class toType = int
> 2.0.7 branch :- no check Primitive data type
> {code:java}
> public Object convertValue(Map context, Object o, Member member, String s, Object value,
Class toType) {
> Object result = null;
> if (value == null || toType.isAssignableFrom(value.getClass())) {
> return value;
> }
> if (toType == String.class) {
> Class inputType = value.getClass();
> if (Number.class.isAssignableFrom(inputType)) {
> result = doConvertFromNumberToString(context, value, inputType);
> if (result != null) {
> return result;
> }
> }
> result = doConvertToString(context, value);
> } else if (toType == boolean.class) {
> result = doConvertToBoolean(value);
> } else if (toType == Boolean.class) {
> result = doConvertToBoolean(value);
> } else if (toType.isArray()) {
> result = doConvertToArray(context, o, member, s, value, toType);
> } else if (Date.class.isAssignableFrom(toType)) {
> result = doConvertToDate(context, value, toType);
> } else if (Collection.class.isAssignableFrom(toType)) {
> result = doConvertToCollection(context, o, member, s, value, toType);
> } else if (toType == Character.class) {
> result = doConvertToCharacter(value);
> } else if (toType == char.class) {
> result = doConvertToCharacter(value);
> } else if (Number.class.isAssignableFrom(toType)) {
> result = doConvertToNumber(context, value, toType);
> } else if (toType == Class.class) {
> result = doConvertToClass(value);
> }
> if (result == null) {
> if (value instanceof Object[]) {
> Object[] array = (Object[]) value;
> if (array.length >= 1) {
> value = array[0]; /************ call this code value = 4 ****************/
> }
> result = convertValue(context, o, member, s, value, toType);
> } else if (!"".equals(value)) { // we've already tried the types we know
> result = super.convertValue(context, value, toType);
> }
> if (result == null && value != null && !"".equals(value))
{
> throw new XWorkException("Cannot create type " + toType + " from value
" + value);
> }
> }
> return result;
> }
> {code}
> 2.1.2 branch :- check Primitive data type
> {code:java}
> public Object convertValue(Map<String, Object> context, Object o, Member member,
String propertyName, Object value, Class toType) {
> Object result = null;
> if (value == null || toType.isAssignableFrom(value.getClass())) {
> return value;
> }
> if (toType == String.class) {
> Class inputType = value.getClass();
> if (Number.class.isAssignableFrom(inputType)) {
> result = doConvertFromNumberToString(context, value, inputType);
> if (result != null) {
> return result;
> }
> }
> result = doConvertToString(context, value);
> } else if (toType == boolean.class) {
> result = doConvertToBoolean(value);
> } else if (toType == Boolean.class) {
> result = doConvertToBoolean(value);
> } else if (toType.isArray()) {
> result = doConvertToArray(context, o, member, propertyName, value, toType);
> } else if (Date.class.isAssignableFrom(toType)) {
> result = doConvertToDate(context, value, toType);
> } else if (Calendar.class.isAssignableFrom(toType)) {
> result = doConvertToCalendar(context, value);
> } else if (Collection.class.isAssignableFrom(toType)) {
> result = doConvertToCollection(context, o, member, propertyName, value, toType);
> } else if (toType == Character.class) {
> result = doConvertToCharacter(value);
> } else if (toType == char.class) {
> result = doConvertToCharacter(value);
> } else if (Number.class.isAssignableFrom(toType) || toType.isPrimitive()) {
> /************ call this code because toType is a int data type but throws error because
value is a string array[0=4,1=4] ****************/
> result = doConvertToNumber(context, value, toType);
> } else if (toType == Class.class) {
> result = doConvertToClass(value);
> }
> if (result == null) {
> if (value instanceof Object[]) {
> Object[] array = (Object[]) value;
> if (array.length >= 1) {
> value = array[0];
> } else {
> value = null;
> }
> result = convertValue(context, o, member, propertyName, value, toType);
> } else if (!"".equals(value)) { // we've already tried the types we know
> result = super.convertValue(context, value, toType);
> }
> if (result == null && value != null && !"".equals(value))
{
> throw new XWorkException("Cannot create type " + toType + " from value
" + value);
> }
> }
> return result;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.1#6144)
|