You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mitch Claborn <mi...@claborn.net> on 2007/10/11 20:14:03 UTC

Validation not validating

Struts 2.0.9 + Tomcat 6 + Debian Linux

I'm not seeing any validation messages when the fields I submit are empty.
?debug=xml does not show any error messages on the stack.  Seems like the
validation is not firing.

What am I missing?  I tried to copy everything from the Logon example in the
tutorial which works like it should.

Struts.xml
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts
Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
[snip]
  <package name="default" extends="struts-default" namespace="/">
    <action name="Question" class="com.csc.survey.ActionQuestion">
      <result>/Question2.jsp</result>
    </action>
  </package>

Struts.properties
struts.devMode = true
struts.url.http.port = 8080
struts.action.extension=html
struts.ui.theme=xhtml

Question2.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
[snip]
      <s:form method="post" action="Question">
      <s:textfield label="username" name="username"/>
        <s:radio list="question.answers" listKey="value" listValue="text"
name="q1" cssClass="radioClass" required="true"  /> 
        <s:submit value="doit" />
      </s:form>







Mitch Claborn
mitch@claborn.net


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Validation not validating

Posted by Mitch Claborn <mi...@claborn.net>.
Ahh.  The doc is a bit misleading.  It reads:

Validation rules can be specified:

   1. Per Action class: in a file named ActionName-validation.xml

Should probably be in a file named ActionClassName-validation.xml


Thanks!
  _____  

Mitch Claborn
mitch@claborn.net



-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com] 
Sent: Thursday, October 11, 2007 1:48 PM
To: Struts Users Mailing List
Subject: RE: Validation not validating


--- Mitch Claborn <mi...@claborn.net> wrote:
> Oops.
> 
> Question-validation.xml
> public class ActionQuestion extends ActionSupport {

If you're gunning for validation based on the action
class name then this should be
ActionQuestion-validation.xml.

d.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System for
Cedar Creek Software. 
______________________________________________________________________


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Validation not validating

Posted by Dave Newton <ne...@yahoo.com>.
--- Mitch Claborn <mi...@claborn.net> wrote:
> Oops.
> 
> Question-validation.xml
> public class ActionQuestion extends ActionSupport {

If you're gunning for validation based on the action
class name then this should be
ActionQuestion-validation.xml.

d.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Validation not validating

Posted by Mitch Claborn <mi...@claborn.net>.
Oops.

Question-validation.xml
<!DOCTYPE validators PUBLIC 
"-//OpenSymphony Group//XWork Validator 1.0.2//EN" 
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

<validators>
    <field name="username">
        <field-validator type="requiredstring">
            <message>Username is required</message>
        </field-validator>
    </field>
    <field name="q1">
        <field-validator type="requiredstring">
            <message>Please answer q1</message>
        </field-validator>
    </field>
</validators>

Here are snippets from the action
ActionQuestion.java
public class ActionQuestion extends ActionSupport {

	public String execute() throws Exception {
  	System.out.println(this.getClass().getName() + ".execute() start");
  	log.trace("starting");
  	System.out.println("q1=" + getQ1());
  	
  	Question l_question = new Question("this is my question",
QuestionType.MULTIPLE_CHOICE);
  	l_question.addAnswer(new Answer("a9", "Answer first"));
  	l_question.addAnswer(new Answer("a1", "Answer 1"));
  	l_question.addAnswer(new Answer("a2", "Answer 2"));
  	l_question.addAnswer(new Answer("a3", "Answer 3"));
  	l_question.addAnswer(new Answer("a4", "Answer 4"));
  	l_question.addAnswer(new Answer("a0", "Answer last"));
		setQuestion(l_question);
		
		HashMap l_map = new HashMap(10);
		l_map.put("x1", "Answer x1");
		l_map.put("x2", "Answer x2");
		l_map.put("x3", "Answer x3");
		l_map.put("x4", "Answer x4");
		l_map.put("x5", "Answer x5");
		setMap(l_map);
		
  	System.out.println(this.getClass().getName() + ".execute() end");
    return SUCCESS;
}

There is no validate() in my action.




  _____  

Mitch Claborn

mitch@claborn.net



-----Original Message-----
From: Dave Newton [mailto:newton.dave@yahoo.com] 
Sent: Thursday, October 11, 2007 1:23 PM
To: Struts Users Mailing List
Subject: Re: Validation not validating


--- Mitch Claborn <mi...@claborn.net> wrote:
> Seems like the validation is not firing.
> What am I missing?

Without any validation files and / or action files
it's kind of hard to say.

If you post your validation file (the tutorial uses an
XML config) that might be enough; posting your Action
file as well will remove one more point where things
could go wrong.

d.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System for
Cedar Creek Software. 
______________________________________________________________________


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Validation not validating

Posted by Dave Newton <ne...@yahoo.com>.
--- Mitch Claborn <mi...@claborn.net> wrote:
> Seems like the validation is not firing.
> What am I missing?

Without any validation files and / or action files
it's kind of hard to say.

If you post your validation file (the tutorial uses an
XML config) that might be enough; posting your Action
file as well will remove one more point where things
could go wrong.

d.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org