You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Jason Douglas de Oliveira (JIRA)" <ji...@apache.org> on 2007/11/08 20:04:34 UTC

[jira] Created: (WW-2307) The value of the parameter is changing when the validation occurs both with annotation and xml

The value of the parameter is changing when the validation occurs both with annotation and xml
----------------------------------------------------------------------------------------------

                 Key: WW-2307
                 URL: https://issues.apache.org/struts/browse/WW-2307
             Project: Struts 2
          Issue Type: Bug
          Components: Core Actions
    Affects Versions: 2.0.11
         Environment: WindowsXP SP2 and jboss 4.2.1
            Reporter: Jason Douglas de Oliveira
            Priority: Critical


When I have an action's attribute of Integer type and use the @IntRangeFieldValidator the value is returned truncated.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2307) The value of the parameter is changing when the validation occurs both with annotation and xml

Posted by "Jason Douglas de Oliveira (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44038#action_44038 ] 

Jason Douglas de Oliveira commented on WW-2307:
-----------------------------------------------

For Musachy Barroso:

He saw that is a problem too. 

Ted Husted - 03/Jan/08 05:40 PM 
Setting to future pending a patch. 

The value that must be shown is the sent by parameter and not the value putted in the action.

> The value of the parameter is changing when the validation occurs both with annotation and xml
> ----------------------------------------------------------------------------------------------
>
>                 Key: WW-2307
>                 URL: https://issues.apache.org/struts/browse/WW-2307
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.11
>         Environment: WindowsXP SP2 and jboss 4.2.1
>            Reporter: Jason Douglas de Oliveira
>            Priority: Critical
>             Fix For: Future
>
>
> When I have an action's attribute of Integer type and use the @IntRangeFieldValidator the value is returned truncated.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2307) The value of the parameter is changing when the validation occurs both with annotation and xml

Posted by "Dave Newton (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42608 ] 

Dave Newton commented on WW-2307:
---------------------------------

That's not "truncated", that's an overflow.

I'm not sure what the options are, and this might be an XWork thing anyway.

Other than converting to a BigDecimal/equivalent first and comparing against Integer.MAX_VALUE first then proceeding with the existing validation I'm not sure what to suggest.

> The value of the parameter is changing when the validation occurs both with annotation and xml
> ----------------------------------------------------------------------------------------------
>
>                 Key: WW-2307
>                 URL: https://issues.apache.org/struts/browse/WW-2307
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.11
>         Environment: WindowsXP SP2 and jboss 4.2.1
>            Reporter: Jason Douglas de Oliveira
>            Priority: Critical
>
> When I have an action's attribute of Integer type and use the @IntRangeFieldValidator the value is returned truncated.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2307) The value of the parameter is changing when the validation occurs both with annotation and xml

Posted by "Jason Douglas de Oliveira (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42607 ] 

Jason Douglas de Oliveira commented on WW-2307:
-----------------------------------------------

The returned value is the same result like Integer i = new Long("12312313222121").intValue();

> The value of the parameter is changing when the validation occurs both with annotation and xml
> ----------------------------------------------------------------------------------------------
>
>                 Key: WW-2307
>                 URL: https://issues.apache.org/struts/browse/WW-2307
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.11
>         Environment: WindowsXP SP2 and jboss 4.2.1
>            Reporter: Jason Douglas de Oliveira
>            Priority: Critical
>
> When I have an action's attribute of Integer type and use the @IntRangeFieldValidator the value is returned truncated.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WW-2307) The value of the parameter is changing when the validation occurs both with annotation and xml

Posted by "Musachy Barroso (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-2307?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Musachy Barroso resolved WW-2307.
---------------------------------

    Resolution: Fixed

Fixed on trunk xwork rv1879. The solution was to put the value into a BigInteger or BigDecimal and compare the value with the MIN and MAX for the type it is being converted to. 

For example in showcase: http://localhost:8080/validation/submitFieldValidatorsExamples.action

Entering "2147483647" for the int field will show this error: "must be integer min 1 max 10 if supplied"
Entering "2147483648" for the int field will show this error: "Invalid field value for field "integerValidatorField"

> The value of the parameter is changing when the validation occurs both with annotation and xml
> ----------------------------------------------------------------------------------------------
>
>                 Key: WW-2307
>                 URL: https://issues.apache.org/struts/browse/WW-2307
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.11
>         Environment: WindowsXP SP2 and jboss 4.2.1
>            Reporter: Jason Douglas de Oliveira
>            Priority: Critical
>             Fix For: 2.1.3
>
>
> When I have an action's attribute of Integer type and use the @IntRangeFieldValidator the value is returned truncated.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2307) The value of the parameter is changing when the validation occurs both with annotation and xml

Posted by "Jason Douglas de Oliveira (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42606 ] 

Jason Douglas de Oliveira commented on WW-2307:
-----------------------------------------------

Yes. Truncated! I put 12312313222121 and is returned -1358015511.

> The value of the parameter is changing when the validation occurs both with annotation and xml
> ----------------------------------------------------------------------------------------------
>
>                 Key: WW-2307
>                 URL: https://issues.apache.org/struts/browse/WW-2307
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.11
>         Environment: WindowsXP SP2 and jboss 4.2.1
>            Reporter: Jason Douglas de Oliveira
>            Priority: Critical
>
> When I have an action's attribute of Integer type and use the @IntRangeFieldValidator the value is returned truncated.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2307) The value of the parameter is changing when the validation occurs both with annotation and xml

Posted by "Musachy Barroso (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=44969#action_44969 ] 

Musachy Barroso commented on WW-2307:
-------------------------------------

The fix to this is not as easy as it sounds. The values shown in the page usually come from the action in the stack, not from the parameters. I think real problem is that these conversion problems are not reported as such, from this code in XWorkBasicConverter

NumberFormat numFormat = NumberFormat.getInstance(getLocale(context));
ParsePosition parsePos = new ParsePosition(0);
if (isIntegerType(toType)) {
     numFormat.setParseIntegerOnly(true);
}
numFormat.setGroupingUsed(true);
Number number = numFormat.parse(stringValue, parsePos);

NumberFormat  will return -1 when it cannot parse the string. The solution would be to fix this and report the conversion error, like the other conversion errors, that's as much as the framework can do I think.

> The value of the parameter is changing when the validation occurs both with annotation and xml
> ----------------------------------------------------------------------------------------------
>
>                 Key: WW-2307
>                 URL: https://issues.apache.org/struts/browse/WW-2307
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.11
>         Environment: WindowsXP SP2 and jboss 4.2.1
>            Reporter: Jason Douglas de Oliveira
>            Priority: Critical
>             Fix For: Future
>
>
> When I have an action's attribute of Integer type and use the @IntRangeFieldValidator the value is returned truncated.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2307) The value of the parameter is changing when the validation occurs both with annotation and xml

Posted by "Musachy Barroso (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43931#action_43931 ] 

Musachy Barroso commented on WW-2307:
-------------------------------------

I think you are confusing parameters interceptor with validation. The value is truncated when it is set in your action, the problem is that if the truncated value is in the validation range, then the app won't find out about it. Assuming your Int Range validator as a range of [-1, 10 ], and the user enters "111111111111111111111111111111111" then the validation will pass (-1 is the truncated value)

> The value of the parameter is changing when the validation occurs both with annotation and xml
> ----------------------------------------------------------------------------------------------
>
>                 Key: WW-2307
>                 URL: https://issues.apache.org/struts/browse/WW-2307
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.11
>         Environment: WindowsXP SP2 and jboss 4.2.1
>            Reporter: Jason Douglas de Oliveira
>            Priority: Critical
>             Fix For: Future
>
>
> When I have an action's attribute of Integer type and use the @IntRangeFieldValidator the value is returned truncated.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (WW-2307) The value of the parameter is changing when the validation occurs both with annotation and xml

Posted by "Jason Douglas de Oliveira (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42609 ] 

jasondouglas77@gmail.com edited comment on WW-2307 at 11/8/07 5:39 PM:
------------------------------------------------------------------------

Or better, lost of information.
http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#25363 \
"Despite the fact that overflow, underflow, or other loss of information may occur..."
But we know what's happening.

The expected behaviour would be.
1 - The field is validate.
2 - If is valid, convert. (if the conversion lost some information, throw anything about it)
3 - If is not valid, return the same value and the message to the page.

Never convert and send to page with error or convert losing precision.

      was (Author: jasondouglas77@gmail.com):
    Or better, lost of information.
http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#25363 \
"Despite the fact that overflow, underflow, or other loss of information may occur..."
But we know what's happening.

The expected behaviour would be.
1 - The field is validate.
2 - If is valid, convert. (if the conversion lost some information, throw anything about it)
3 - If is not valid, return the same value and the message to the page.

Never convert and send to page with error or convert losting precision.
  
> The value of the parameter is changing when the validation occurs both with annotation and xml
> ----------------------------------------------------------------------------------------------
>
>                 Key: WW-2307
>                 URL: https://issues.apache.org/struts/browse/WW-2307
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.11
>         Environment: WindowsXP SP2 and jboss 4.2.1
>            Reporter: Jason Douglas de Oliveira
>            Priority: Critical
>
> When I have an action's attribute of Integer type and use the @IntRangeFieldValidator the value is returned truncated.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2307) The value of the parameter is changing when the validation occurs both with annotation and xml

Posted by "Dave Newton (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42605 ] 

Dave Newton commented on WW-2307:
---------------------------------

What do you mean "truncated"? Like 1234 is coming back as 12?

> The value of the parameter is changing when the validation occurs both with annotation and xml
> ----------------------------------------------------------------------------------------------
>
>                 Key: WW-2307
>                 URL: https://issues.apache.org/struts/browse/WW-2307
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.11
>         Environment: WindowsXP SP2 and jboss 4.2.1
>            Reporter: Jason Douglas de Oliveira
>            Priority: Critical
>
> When I have an action's attribute of Integer type and use the @IntRangeFieldValidator the value is returned truncated.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2307) The value of the parameter is changing when the validation occurs both with annotation and xml

Posted by "Jason Douglas de Oliveira (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42609 ] 

Jason Douglas de Oliveira commented on WW-2307:
-----------------------------------------------

Or better, lost of information.
http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#25363 \
"Despite the fact that overflow, underflow, or other loss of information may occur..."
But we know what's happening.

The expected behaviour would be.
1 - The field is validate.
2 - If is valid, convert. (if the conversion lost some information, throw anything about it)
3 - If is not valid, return the same value and the message to the page.

Never convert and send to page with error or convert losting precision.

> The value of the parameter is changing when the validation occurs both with annotation and xml
> ----------------------------------------------------------------------------------------------
>
>                 Key: WW-2307
>                 URL: https://issues.apache.org/struts/browse/WW-2307
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.11
>         Environment: WindowsXP SP2 and jboss 4.2.1
>            Reporter: Jason Douglas de Oliveira
>            Priority: Critical
>
> When I have an action's attribute of Integer type and use the @IntRangeFieldValidator the value is returned truncated.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WW-2307) The value of the parameter is changing when the validation occurs both with annotation and xml

Posted by "Jason Douglas de Oliveira (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/struts/browse/WW-2307?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_42620 ] 

Jason Douglas de Oliveira commented on WW-2307:
-----------------------------------------------

Below are the action class and the jsp.

package com.jdo.actions.customer;

import org.apache.struts2.config.Namespace;
import org.apache.struts2.config.Result;
import org.apache.struts2.config.Results;
import org.apache.struts2.dispatcher.ServletDispatcherResult;
import org.apache.struts2.dispatcher.ServletRedirectResult;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.EmailValidator;
import com.opensymphony.xwork2.validator.annotations.IntRangeFieldValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredFieldValidator;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;

@Namespace(value="/register")
@Results({
	@Result (name="success", value="/jsp/success.jsp", type=ServletRedirectResult.class),
	@Result (name="input", value="/jsp/customer.jsp", type=ServletDispatcherResult.class),
	@Result (name="error", value="/jsp/error.jsp", type=ServletRedirectResult.class)
	})
public class CreateAction extends ActionSupport{ 
	
	/**
	 * 
	 */ 
	private static final long serialVersionUID = 5476256575966528231L;

	private String name;
	private Integer age;
	private String email;
	
	@RequiredStringValidator(trim=true, message="The name is required")
	@StringLengthFieldValidator(minLength="2",maxLength="10", message="The name must have the size between ${minLength} and ${maxLength}")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@RequiredFieldValidator(message="The age is required")
	@IntRangeFieldValidator(message="The age must be an integer")
	public Integer getAge() {
		return age;
	}

	
	public void setAge(Integer age) {
		this.age = age;
	}

	@RequiredStringValidator(trim=true, message="The email is required")
	@EmailValidator(message="The email is invalid")
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String execute() throws Exception{
		System.err.println("In CreateAction :");
		return "success";
	}
}

<%@ taglib prefix="s" uri="/WEB-INF/tags/struts-tags.tld" %>
<html>
	<table>
		<tr>
			<td colspan="2"><h2>Create User</h2></td>	
		</tr>
		<s:form action="create" namespace="/register"> 
		<tr>
			<td>Name:</td>	
			<td>
				<s:textfield name="name"/>
			</td>
		</tr>
		<tr>
			<td>Age:</td>	
			<td>
				<s:textfield name="age"/>
			</td>
		</tr>
		<tr>
			<td>email:</td>	
			<td>
				<s:textfield name="email"/>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<s:submit value="Go!"/>
			</td>	
		</tr>
		</s:form>
	</table>
</html>

I believe that the problem is in textfield tag. It must to verify first the values in request.
I found a workaroud, but it is very ugly. Putting the value in textfield tag (value="%{#parameters.age}").

> The value of the parameter is changing when the validation occurs both with annotation and xml
> ----------------------------------------------------------------------------------------------
>
>                 Key: WW-2307
>                 URL: https://issues.apache.org/struts/browse/WW-2307
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.11
>         Environment: WindowsXP SP2 and jboss 4.2.1
>            Reporter: Jason Douglas de Oliveira
>            Priority: Critical
>
> When I have an action's attribute of Integer type and use the @IntRangeFieldValidator the value is returned truncated.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (WW-2307) The value of the parameter is changing when the validation occurs both with annotation and xml

Posted by "Musachy Barroso (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/struts/browse/WW-2307?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Musachy Barroso updated WW-2307:
--------------------------------

    Fix Version/s:     (was: Future)
                   2.1.3

> The value of the parameter is changing when the validation occurs both with annotation and xml
> ----------------------------------------------------------------------------------------------
>
>                 Key: WW-2307
>                 URL: https://issues.apache.org/struts/browse/WW-2307
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.0.11
>         Environment: WindowsXP SP2 and jboss 4.2.1
>            Reporter: Jason Douglas de Oliveira
>            Priority: Critical
>             Fix For: 2.1.3
>
>
> When I have an action's attribute of Integer type and use the @IntRangeFieldValidator the value is returned truncated.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.