[
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.