You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by dippedingold <sh...@tcs.com> on 2009/02/26 20:27:01 UTC
how to Validate tabular input.
I want to make a tabular input along with validation.
For example:
IN JSP:
<% for (int i=0;i<=someBussinessLogicResultSet.size();i++) { %>
<s:textfield name="mytext" />
<% } %>
<s:submit>
Then in Action I wrote:
@Validation
public myaction extends ActionSupport{
public String execute()
{
return SUCCESS;
}
@RequiredStringValidation(message="Please enter value in text box")
public void getMytext() {return mytext;}
public void setMytext(List mytext) {this.mytext=mytext;}
private List mytext;
}
I know the above code will not work unless i remove the validations.
But however if I need a validation so that a error message is displayed on
only those text fields which are left empty by the user, how can I do so??
Although just for note I am not using scriplet as shown above but my text
fiels are within display tags.
--
View this message in context: http://www.nabble.com/how-to-Validate-tabular-input.-tp22231696p22231696.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
回复:Re: how to Validate tabular input.
Posted by 张云勇 <ev...@163.com>.
use vistor validator. you can see the sample app shipped with the struts full source download archives.
在2009-02-27,"Wes Wannemacher" <we...@wantii.com> 写道:
On Thursday 26 February 2009 20:04:55 Greg Lindholm wrote:
> I would really like to know the answer as well, how do you validate a list
> of fields with annotations?
>
> let me tweak your example a bit so it will at least work (before
> validation).
> (See http://struts.apache.org/2.x/docs/tabular-inputs.html)
>
> <s:iterator value="myText" status="stat" >
> <s:textfield name="myText[%{#stat.index}]" value="top"/>
> </s:iterator>
>
> public List<String> getMytext() {return mytext;}
> public void setMytext(List<String> mytext) {this.mytext=mytext;}
> private List<String> mytext = new ArrayList<String>();
>
The XML and annotation-based validation doesn't really have support for list-
based (or map-based) properties. With indexed properties, it's best to
implement a 'validate' method on your action.
Yes, it's a pain, but, before you file an improvement JIRA, I would suggest
trying to come up with a patch. I know I, for one, have been patiently waiting
on JSR-303 before I consider writing improvements to the validation framework.
-Wes
--
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: how to Validate tabular input.
Posted by Wes Wannemacher <we...@wantii.com>.
On Thursday 26 February 2009 20:04:55 Greg Lindholm wrote:
> I would really like to know the answer as well, how do you validate a list
> of fields with annotations?
>
> let me tweak your example a bit so it will at least work (before
> validation).
> (See http://struts.apache.org/2.x/docs/tabular-inputs.html)
>
> <s:iterator value="myText" status="stat" >
> <s:textfield name="myText[%{#stat.index}]" value="top"/>
> </s:iterator>
>
> public List<String> getMytext() {return mytext;}
> public void setMytext(List<String> mytext) {this.mytext=mytext;}
> private List<String> mytext = new ArrayList<String>();
>
The XML and annotation-based validation doesn't really have support for list-
based (or map-based) properties. With indexed properties, it's best to
implement a 'validate' method on your action.
Yes, it's a pain, but, before you file an improvement JIRA, I would suggest
trying to come up with a patch. I know I, for one, have been patiently waiting
on JSR-303 before I consider writing improvements to the validation framework.
-Wes
--
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: how to Validate tabular input.
Posted by Greg Lindholm <gl...@yahoo.com>.
I would really like to know the answer as well, how do you validate a list of
fields with annotations?
let me tweak your example a bit so it will at least work (before
validation).
(See http://struts.apache.org/2.x/docs/tabular-inputs.html)
<s:iterator value="myText" status="stat" >
<s:textfield name="myText[%{#stat.index}]" value="top"/>
</s:iterator>
public List<String> getMytext() {return mytext;}
public void setMytext(List<String> mytext) {this.mytext=mytext;}
private List<String> mytext = new ArrayList<String>();
dippedingold wrote:
>
> I want to make a tabular input along with validation.
> For example:
> IN JSP:
>
> <% for (int i=0;i<=someBussinessLogicResultSet.size();i++) { %>
> <s:textfield name="mytext" />
> <% } %>
> <s:submit>
>
> Then in Action I wrote:
>
> @Validation
> public myaction extends ActionSupport{
>
> public String execute()
> {
> return SUCCESS;
> }
>
> @RequiredStringValidation(message="Please enter value in text box")
> public void getMytext() {return mytext;}
>
> public void setMytext(List mytext) {this.mytext=mytext;}
>
> private List mytext;
>
> }
>
>
> I know the above code will not work unless i remove the validations.
> But however if I need a validation so that a error message is displayed on
> only those text fields which are left empty by the user, how can I do so??
>
> Although just for note I am not using scriplet as shown above but my text
> fiels are within display tags.
>
--
View this message in context: http://www.nabble.com/how-to-Validate-tabular-input.-tp22231696p22237450.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org