struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lukasz Lenart (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-3357) ognl.MethodFailedException when you do not enter a value for a field mapped to an int.
Date Fri, 12 May 2017 14:05:04 GMT

    [ https://issues.apache.org/jira/browse/WW-3357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16008171#comment-16008171
] 

Lukasz Lenart commented on WW-3357:
-----------------------------------

No, it won't default to {{0}} as this isn't the same as {{""}} (an empty string). If you allow
submitting empty values (no a required field validator is present) then you must use {{Integer}}
instead of {{int}}

> ognl.MethodFailedException when you do not enter a value for a field mapped to an int.
> --------------------------------------------------------------------------------------
>
>                 Key: WW-3357
>                 URL: https://issues.apache.org/jira/browse/WW-3357
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Core Actions
>    Affects Versions: 2.1.8
>         Environment: Websphere Application Server 6.1
>            Reporter: Kevin Adams
>             Fix For: 2.5.next
>
>
> I'm getting:
> {noformat}
> ognl.MethodFailedException: Method "setMyIntVariable" failed for object org.kevin.struts2.test.actions.TestAction@79fa79fa
[java.lang.NoSuchMethodException: org.kevin.struts2.test.actions.TestAction.setMyIntVariable([Ljava.lang.String;)]
> {noformat}
> ...when I try to submit a form with a <s:textfield> that is mapped to an integer
in my action. Previously, there was an issue where this happened if the value was <= 0,
but this happens blank values. Should it not default to zero?
> Here is a snippet from my .jsp:
> {code:xml}
> <s:form action="validatoraction">
> 	<s:textfield name="myIntVariable" label="Integer variable: "/>
> 	<s:textfield name="myStringVariable" label="String value: " />
> 	<s:submit />
> </s:form>
> {code}
> Here is my struts.xml
> {code:xml}
> <struts>
> 	<constant name="struts.devMode" value="false" />
>     <constant name="struts.action.extension" value="action" />
>     <package name="struts2testerdefault" namespace="" extends="struts-default">
> 	    <action name="foo">
> 	    	<result>/bar.jsp</result>
> 	    </action>
> 	    <action name="validatoraction" class="org.kevin.struts2.test.actions.TestAction">
> 	    	<result>/maintesterresult.jsp</result>
> 	    	<result name="input">/maintesterpage.jsp</result>
> 	    </action>
> 	    <action name="maintesterpage">
> 			<result>/maintesterpage.jsp</result>
> 		</action>
>     </package>
> </struts>
> {code}
> Here is my action:
> {code:java}
> package org.kevin.struts2.test.actions;
> import java.sql.Timestamp;
> import java.util.Date;
> import com.opensymphony.xwork2.ActionSupport;
> public class TestAction extends ActionSupport {
> 	
> 	/**
> 	 * 
> 	 */
> 	private static final long serialVersionUID = 1L;
> 	private int myIntVariable;
> 	private String myStringVariable;
> 	private Timestamp myTimeStamp;
> 	private Date myDate;
> 	
> 	@Override
> 	public String execute() throws Exception {
> 		myTimeStamp = new Timestamp(new java.util.Date().getTime());
> 		myDate = new java.util.Date();
> 		return SUCCESS;
> 	}
> 	public int getMyIntVariable() {
> 		return myIntVariable;
> 	}
> 	public void setMyIntVariable(int myIntVariable) {
> 		this.myIntVariable = myIntVariable;
> 	}
> 	public String getMyStringVariable() {
> 		return myStringVariable;
> 	}
> 	public void setMyStringVariable(String myStringVariable) {
> 		this.myStringVariable = myStringVariable;
> 	}
> 	public Timestamp getMyTimeStamp() {
> 		return myTimeStamp;
> 	}
> 	public void setMyTimeStamp(Timestamp myTimeStamp) {
> 		this.myTimeStamp = myTimeStamp;
> 	}
> 	public Date getMyDate() {
> 		return myDate;
> 	}
> 	public void setMyDate(Date myDate) {
> 		this.myDate = myDate;
> 	}
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message