You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Niklas Johansson <ni...@gmail.com> on 2009/05/25 19:24:02 UTC

RequiredString Validation doesn't work and AbstractValidationActionSupport is missing‏

Hello,

I am trying to create my first validation. I have two problems:

First one:

I want to use Requieredstring validator. The problem is that my
application is not complaining if I do leave the input field empty.

Here is my code:

reqisterqa.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../resources/css/mobiletrainingstyle.css"
type="text/css" media="screen">
<title>Insert title here</title>
</head>
<body>

<h3 class="redtext"><s:property value="message" /></h3>

	<s:form method="POST" action="postRegisterQAForm.action">			
    		<s:textfield name="heading" label="Fråga" required="true"/>
    		<s:textarea name="answer" label="Svar" cols="30" rows="15"
required="true"/>
       		<s:submit value="Spara" align="center"/>
  	</s:form>
</body>
</html>


 struts.xml (part of):

<package name="org.nicsoft.application.mobiletraining.qa"
extends="struts-default">
     	<action name="postRegisterQAForm"
class="org.nicsoft.application.mobiletraining.qa.RegisterQAFormAction">
     			<result name="input">/jsp/forms/registerqa.jsp</result>
	      		<result name="error">/jsp/forms/registerqa.jsp</result>
            <result>/jsp/forms/registerqa.jsp</result>
        </action>
</package>


RegisterQAForm class:

package org.nicsoft.application.mobiletraining.qa;

import java.io.IOException;
import java.util.Map;
import org.apache.struts2.interceptor.ParameterAware;
import com.opensymphony.xwork2.ActionSupport;

public class RegisterQAFormAction extends ActionSupport implements
ParameterAware  {

    public String message;
    public String heading;

    Map param;

    public String execute() throws Exception {

        System.out.println(param.get("heading")[0]);
        System.out.println(param.get("answer")[0]);
        QAHandler handleQA = new QAHandler();
        handleQA.storeQA(param);

        setMessage("Ärende " + param.get("heading")[0] + "
registrerat");
        if (getHeading() != null){
              return SUCCESS;
            }
            else{
              return ERROR;
            }
    }

    public void setParameters(Map param) {
        this.param = param;

    }

    public void setMessage(String message){
         this.message = message;
    }

    public String getMessage() {
         return message;
    }

    public void setHeading(String heading){
        this.heading = heading;
    }

    public String getHeading(){
        return this.heading;
    }
}


RegisterQAForm-validation.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!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="heading">
    <field-validator type="requiredstring">
      <param name="trim">true</param>
      <message>Heading Name is required</message>
    </field-validator>
  </field>

</validators>


I did put the RegisterQAForm-validation.xml in the same package as the
class RegisterQAForm. Also tried to put it in the root/default
package, no difference.

Can anyone tell me what is the problem?

Since I moved this mail-conversation from another mail that corrupted
the mail, I include some questions from the old conversation here
posted by Dave:

Q: "why you're using ParameterAware" ... "it's generally cleaner to
just use the action properties"

A: The reason is because I found the instructions on the struts
homepage. Using the action properties, I assume I need to define those
in the struts.xml, correct?


My second problem:

I also want to use the Field Validator at some point. But it's some
problem with the AbstractValidationActionSupport class. It isn't
found. Anyone knows where this class is located? Couldn't find it in
XWork where I though it's supposed to be.

Q: "That class is part of the showcase app, not part of Struts itself."

A: So what is the solution? The instructions wasn't that clear about
where the class came from on the instruction page:
http://struts.apache.org/2.1.6/docs/using-field-validators.html

Thank you in advance!

Regards,
Niklas

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


Re: RequiredString Validation doesn't work and AbstractValidationActionSupport is missing?

Posted by Dave Newton <ne...@yahoo.com>.
Niklas Johansson wrote:
> Regarding the ParameterAware, I found the information here and it's
> specified as the preferred solution:
> http://struts.apache.org/2.1.6/docs/how-can-we-access-request-parameters-passed-into-an-action.html

It's the preferred solution for accessing the parameters *directly*. 
That doesn't mean it's the preferred solution for accessing form 
parameters, because it isn't.

Dave

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


Re: RequiredString Validation doesn't work and AbstractValidationActionSupport is missing?

Posted by Niklas Johansson <ni...@gmail.com>.
Hello Dave,

Thanks for all answers.

Regarding the ParameterAware, I found the information here and it's
specified as the preferred solution:
http://struts.apache.org/2.1.6/docs/how-can-we-access-request-parameters-passed-into-an-action.html

I have enough information below to do some test for the rest I think,
will try it later.

Thanks again!

Regards,
Niklas


2009/5/25 Dave Newton <ne...@yahoo.com>:
> Niklas Johansson wrote:
>>
>> I want to use Requieredstring validator. The problem is that my
>> application is not complaining if I do leave the input field empty.
>
> Are you using the default interceptor stack?
>
>> Can anyone tell me what is the problem?
>
> I don't see anything immediately obvious, but I'm sleepy.
>
>> Q: "why you're using ParameterAware" ... "it's generally cleaner to
>> just use the action properties"
>>
>> A: The reason is because I found the instructions on the struts
>> homepage. Using the action properties, I assume I need to define those
>> in the struts.xml, correct?
>
> Define what in the struts.xml? The "struts homepage" doesn't have
> instructions for doing *anything*, so you'll have to be more specific as to
> what you were reading so we can correct it.
>
> The probable answer to your question is "no". One of the main features (IMO)
> of S2 is that it eliminates a lot of back-and-forth between HTML forms and
> actions, meaning your code could be written follows, getters and setters
> elided. (And why make the action properties public if you have
> getters/setters for them?)
>
> public class RegisterQAFormAction extends ActionSupport {
>
>    private String message;
>    private String heading;
>
>    public String execute() throws Exception {
>        System.out.println(heading);
>        System.out.println(answer);
>
>        // Don't know what this is trying to do, so ignoring.
>        //QAHandler handleQA = new QAHandler();
>        //handleQA.storeQA(param);
>
>        setMessage("Ärende " + heading + " registrerat");
>        if (getHeading() == null) {
>            return ERROR;
>        }
>
>        return SUCCESS;
>    }
>
> }
>
> Note that heading won't be null if the user doesn't enter a value--it will
> be an empty string, so in all probability this is a bug in your code.
>
>> Q: "That class is part of the showcase app, not part of Struts itself."
>>
>> A: So what is the solution? The instructions wasn't that clear about
>> where the class came from on the instruction page:
>> http://struts.apache.org/2.1.6/docs/using-field-validators.html
>
> Solution to what problem? You don't need that class to use the validation as
> you've written it above.
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


SV: SV: RequiredString Validation doesn't work and AbstractValidationActionSupport is missing?

Posted by Niklas Johansson <ni...@gmail.com>.
Gee... Of course it was the two most similar letters in the world, almost at
least, messing things up. I did check the file names as well but missed
this, have to be more careful next time. So difficult to find those small
little buggers. 

Well done, life is good again :) Thank you!

Cheers,
Niklas

-----Ursprungligt meddelande-----
Från: Dave Newton [mailto:newton.dave@yahoo.com] 
Skickat: den 28 maj 2009 15:31
Till: Struts Users Mailing List
Ämne: Re: SV: RequiredString Validation doesn't work and
AbstractValidationActionSupport is missing?

Heh.

Man, this took me a long time to figure out--I was looking in all the 
wrong places. The short answer is that you need to use a different font.

The longer answer--check out the filename of your validation file.

Dave

Niklas Johansson wrote:
> Hello,
> 
> Thanks for the information, but seriously, I think things are getting
> just more complicated than needed now. As I mentioned, it does work
> without AbstractValidationActionSupport. Just search Internet, there
> are several examples.
> 
> This brings it all back to my problem. I been trying to find any
> deviations from my working example I found on Internet with my own
> implementation, can't find any difference. So please, can you see
> anything that makes the validation not beeing applied? As mentioned,
> when posting my empty form it invokes the action class, which it
> shouldn't, it should react on the empty fields and return to the
> client requesting before.
> 
> Dave, you mentioned something about using the default interceptor
> stack. According to this page
>
http://www.struts2.org/form-validation-in-struts2-basic-server-side-validati
on-example/
> it's not needed to define anything: "To use any of the predefined
> validators, no initial configuration is needed. Validation is
> implemented using a ValidationInterceptor which is configured in the
> default interceptor stack." I haven't, intentionly at least, defined
> any other validation interceptor stack. I am sure I would have
> noticed...
> 
> Thanks again!
> 
> Regards,
> Niklas
> 
> 2009/5/27 Martin Gainty <mg...@hotmail.com>:
>> --assuming you have this validation setup for your username from
/validation/fieldValidatorsExample.jsp
>> <validators>
>>        <field name="requiredValidatorField">
>>                <field-validator type="required">
>>                        <message><![CDATA[ required ]]></message>
>>                </field-validator>
>>        </field>
>> </validators>
>> referencong doc from
>> http://struts.apache.org/2.0.14/docs/using-field-validators.html
>> //the abstract class determines navigation and flow (input being the
first page)
>> //success and or error being the end result
>>    <package name="validationExamples" extends="struts-default"
namespace="/validation" >
>>
>>        <!-- ======================== -->
>>        <!-- === Field Validators === -->
>>        <!-- ======================== -->
>>        <action name="showFieldValidatorsExamples"
class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction"
method="input">
>>            <result name="input"
type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>>        </action>
>>
>>        <action name="submitFieldValidatorsExamples"
class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction"
method="submit">
>>            <result name="input"
type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>>            <result
type="dispatcher">/validation/successFieldValidatorsExample.jsp</result>
>>        </action>
>>
>>        <action name="submitFieldValidatorsExamples"
class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction"
method="submit">
>>            <result name="input"
type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>>            <result
type="dispatcher">/validation/successFieldValidatorsExample.jsp</result>
>>        </action>
>>
>> //determing where dispatcher mapped to is defined here
>> <result-type name="dispatcher"
class="org.apache.struts2.dispatcher.ServletDispatcherResult"
default="true"/>
>>
>> /* <pre><!-- START SNIPPET: example -->
>>  * <result name="success" type="dispatcher">
>>  *   <param name="location">foo.jsp</param>
>>  * </result>
>>  * <!-- END SNIPPET: example --></pre>
>>  *
>>  * This result follows the same rules from {@link StrutsResultSupport}.
>>  *
>>  * @see javax.servlet.RequestDispatcher
>>  */
>> public class ServletDispatcherResult extends StrutsResultSupport {
>>
>>    private static final long serialVersionUID = -1970659272360685627L;
>>
>>    private static final Logger LOG =
LoggerFactory.getLogger(ServletDispatcherResult.class);
>>
>>    public ServletDispatcherResult() {
>>        super();
>>    }
>>
>>    public ServletDispatcherResult(String location) {
>>        super(location);
>>    }
>>
>>    /**
>>     * Dispatches to the given location. Does its forward via a
RequestDispatcher. If the
>>     * dispatch fails a 404 error will be sent back in the http response.
>>     *
>>     * @param finalLocation the location to dispatch to.
>>     * @param invocation    the execution state of the action
>>     * @throws Exception if an error occurs. If the dispatch fails the
error will go back via the
>>     *                   HTTP request.
>>     */
>> //if action returns input doExecute would take location of
/validation/fieldValidatorsExample.jsp and route to
>>  //<result name="input"
type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>>
>>    public void doExecute(String finalLocation, ActionInvocation
invocation) throws Exception {
>>        if (LOG.isDebugEnabled()) {
>>            LOG.debug("Forwarding to location " + finalLocation);
>>        }
>>
>>        PageContext pageContext = ServletActionContext.getPageContext();
>>
>>        if (pageContext != null) {
>>            pageContext.include(finalLocation);
>>        } else {
>>            HttpServletRequest request =
ServletActionContext.getRequest();
>>            HttpServletResponse response =
ServletActionContext.getResponse();
>>            RequestDispatcher dispatcher =
request.getRequestDispatcher(finalLocation);
>>
>>            //add parameters passed on the location to #parameters
>>            // see WW-2120
>>            if (invocation != null && finalLocation != null &&
finalLocation.length() > 0
>>                    && finalLocation.indexOf("?") > 0) {
>>                String queryString =
finalLocation.substring(finalLocation.indexOf("?") + 1);
>>                Map parameters = (Map)
invocation.getInvocationContext().getContextMap().get("parameters");
>>                Map queryParams = UrlHelper.parseQueryString(queryString,
true);
>>                if (queryParams != null && !queryParams.isEmpty())
>>                    parameters.putAll(queryParams);
>>            }
>>
>>            // if the view doesn't exist, let's do a 404
>>            if (dispatcher == null) {
>>                response.sendError(404, "result '" + finalLocation + "'
not found");
>>
>>                return;
>>            }
>>
>>            // If we're included, then include the view
>>            // Otherwise do forward
>>            // This allow the page to, for example, set content type
>>            if (!response.isCommitted() &&
(request.getAttribute("javax.servlet.include.servlet_path") == null)) {
>>                request.setAttribute("struts.view_uri", finalLocation);
>>                request.setAttribute("struts.request_uri",
request.getRequestURI());
>>
>>                dispatcher.forward(request, response);
>>            } else {
>>                dispatcher.include(request, response);
>>            }
>>        }
>>    }
>> }
>>
>> //ServletDispatcherResult only handles navigation
>> //we still dont know how this validation is achieved until we look at
/WEB-INF/classes/validators.xml
>> <!DOCTYPE validators PUBLIC
>>          "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
>>          "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
>> <validators>
>>    <validator name="required"
class="com.opensymphony.xwork.validator.validators.RequiredFieldValidator"/>
>>
>> how does the
FieldValidatorsExampleAction-submitFieldValidatorsExamples-validation.xml
get referenced?
>> To define validation rules for an Action, create a file named
ActionName-validation.xml
>> in the same package as the Action. You may also create alias-specific
>> validation rules which add to the default validation rules defined in
ActionName-validation.xml by creating another file in the same directory
named ActionName-aliasName-validation.xml.  In both cases,  ActionName is
the name of the Action class, and aliasName is the name of the Action alias
defined in the xwork.xml configuration for the Action.
>>
>>
>> The framework will also search up the inheritance tree of the Action
>> to find validation rules for directly implemented interfaces and parent
>> classes of the Action. This is particularly powerful when combined with
>> ModelDriven Actions and the VisitorFieldValidator.  Here's an example of
how validation rules are discovered.  Given the following class structure:
>>
>>
>> interface Animal;interface Quadraped extends Animal;class AnimalImpl
implements Animal;class QuadrapedImpl extends AnimalImpl implements
Quadraped;class Dog extends QuadrapedImpl;
>>
>>
>> The framework method will look for the following config files if Dog is
to be validated:
>>
>>
>>
AnimalAnimal-aliasnameAnimalImplAnimalImpl-aliasnameQuadrapedQuadraped-alias
nameQuadrapedImplQuadrapedImpl-aliasnameDogDog-aliasname
>>
>>
>>
>> While this process is similar to what the XW:Localization
>> framework does when finding messages, there are some subtle
>> differences. The most important difference is that validation rules are
>> discovered from the parent downwards.
>> //how do i enable ValidationInterceptor in my webapp?
>>    <package name="example">
>>        <interceptors>
>>            <interceptor name="validator"
>>
class="com.opensymphony.xwork.validator.ValidationInterceptor"/>
>>        </interceptors>
>>
>> a worthwhile read to understanding xwork validation framework is
available
athttp://www.opensymphony.com/xwork/wikidocs/Validation%20Framework.html
>>
>> Martin Gainty
>> ______________________________________________
>> Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
>>
>> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene
Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte
Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht
dient lediglich dem Austausch von Informationen und entfaltet keine
rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von
E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
>> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas
le destinataire prévu, nous te demandons avec bonté que pour satisfaire
informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie
de ceci est interdite. Ce message sert à l'information seulement et n'aura
pas n'importe quel effet légalement obligatoire. Étant donné que les email
peuvent facilement être sujets à la manipulation, nous ne pouvons accepter
aucune responsabilité pour le contenu fourni.
>>
>>
>>
>>
>>> Date: Wed, 27 May 2009 06:18:36 -0400
>>> From: newton.dave@yahoo.com
>>> To: user@struts.apache.org
>>> Subject: Re: SV: RequiredString Validation doesn't work and
AbstractValidationActionSupport   is missing?
>>>
>>> Niklas Johansson wrote:
>>>> P.S. AbstractValidationActionSupport doesn’t seem to be included in the
>>>> Struts2 (2.1.6) framework anyhow, couldn’t find it in any jar. But
there are
>>>> quite a few so perhaps I missed it.
>>> It's in the showcase application, like I said before.
>>>
>>>> Från: Martin Gainty [mailto:mgainty@hotmail.com]
>>>>> do NOT extend ActionSupport as ActionSupport doesnt contain Field
Validation
>>>>> Lofic
>>> Here's the source for AbstractValidationActionSupport:
>>>
>>> public abstract class AbstractValidationActionSupport
>>>                  extends ActionSupport {
>>>      public String submit() throws Exception {
>>>          return "success";
>>>      }
>>>      public String input() throws Exception {
>>>          return "input";
>>>      }
>>> }
>>>
>>> Please explain to us what you mean, both how the above method adds field
>>> validation logic, and how ActionSupport doesn't.
>>>
>>> Dave
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>> _________________________________________________________________
>> Insert movie times and more without leaving Hotmail®.
>>
http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutori
al_QuickAdd1_052009
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

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


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


Re: SV: RequiredString Validation doesn't work and AbstractValidationActionSupport is missing?

Posted by Dave Newton <ne...@yahoo.com>.
Heh.

Man, this took me a long time to figure out--I was looking in all the 
wrong places. The short answer is that you need to use a different font.

The longer answer--check out the filename of your validation file.

Dave

Niklas Johansson wrote:
> Hello,
> 
> Thanks for the information, but seriously, I think things are getting
> just more complicated than needed now. As I mentioned, it does work
> without AbstractValidationActionSupport. Just search Internet, there
> are several examples.
> 
> This brings it all back to my problem. I been trying to find any
> deviations from my working example I found on Internet with my own
> implementation, can't find any difference. So please, can you see
> anything that makes the validation not beeing applied? As mentioned,
> when posting my empty form it invokes the action class, which it
> shouldn't, it should react on the empty fields and return to the
> client requesting before.
> 
> Dave, you mentioned something about using the default interceptor
> stack. According to this page
> http://www.struts2.org/form-validation-in-struts2-basic-server-side-validation-example/
> it's not needed to define anything: "To use any of the predefined
> validators, no initial configuration is needed. Validation is
> implemented using a ValidationInterceptor which is configured in the
> default interceptor stack." I haven't, intentionly at least, defined
> any other validation interceptor stack. I am sure I would have
> noticed...
> 
> Thanks again!
> 
> Regards,
> Niklas
> 
> 2009/5/27 Martin Gainty <mg...@hotmail.com>:
>> --assuming you have this validation setup for your username from /validation/fieldValidatorsExample.jsp
>> <validators>
>>        <field name="requiredValidatorField">
>>                <field-validator type="required">
>>                        <message><![CDATA[ required ]]></message>
>>                </field-validator>
>>        </field>
>> </validators>
>> referencong doc from
>> http://struts.apache.org/2.0.14/docs/using-field-validators.html
>> //the abstract class determines navigation and flow (input being the first page)
>> //success and or error being the end result
>>    <package name="validationExamples" extends="struts-default" namespace="/validation" >
>>
>>        <!-- ======================== -->
>>        <!-- === Field Validators === -->
>>        <!-- ======================== -->
>>        <action name="showFieldValidatorsExamples" class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction" method="input">
>>            <result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>>        </action>
>>
>>        <action name="submitFieldValidatorsExamples" class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction" method="submit">
>>            <result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>>            <result type="dispatcher">/validation/successFieldValidatorsExample.jsp</result>
>>        </action>
>>
>>        <action name="submitFieldValidatorsExamples" class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction" method="submit">
>>            <result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>>            <result type="dispatcher">/validation/successFieldValidatorsExample.jsp</result>
>>        </action>
>>
>> //determing where dispatcher mapped to is defined here
>> <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
>>
>> /* <pre><!-- START SNIPPET: example -->
>>  * <result name="success" type="dispatcher">
>>  *   <param name="location">foo.jsp</param>
>>  * </result>
>>  * <!-- END SNIPPET: example --></pre>
>>  *
>>  * This result follows the same rules from {@link StrutsResultSupport}.
>>  *
>>  * @see javax.servlet.RequestDispatcher
>>  */
>> public class ServletDispatcherResult extends StrutsResultSupport {
>>
>>    private static final long serialVersionUID = -1970659272360685627L;
>>
>>    private static final Logger LOG = LoggerFactory.getLogger(ServletDispatcherResult.class);
>>
>>    public ServletDispatcherResult() {
>>        super();
>>    }
>>
>>    public ServletDispatcherResult(String location) {
>>        super(location);
>>    }
>>
>>    /**
>>     * Dispatches to the given location. Does its forward via a RequestDispatcher. If the
>>     * dispatch fails a 404 error will be sent back in the http response.
>>     *
>>     * @param finalLocation the location to dispatch to.
>>     * @param invocation    the execution state of the action
>>     * @throws Exception if an error occurs. If the dispatch fails the error will go back via the
>>     *                   HTTP request.
>>     */
>> //if action returns input doExecute would take location of /validation/fieldValidatorsExample.jsp and route to
>>  //<result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>>
>>    public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
>>        if (LOG.isDebugEnabled()) {
>>            LOG.debug("Forwarding to location " + finalLocation);
>>        }
>>
>>        PageContext pageContext = ServletActionContext.getPageContext();
>>
>>        if (pageContext != null) {
>>            pageContext.include(finalLocation);
>>        } else {
>>            HttpServletRequest request = ServletActionContext.getRequest();
>>            HttpServletResponse response = ServletActionContext.getResponse();
>>            RequestDispatcher dispatcher = request.getRequestDispatcher(finalLocation);
>>
>>            //add parameters passed on the location to #parameters
>>            // see WW-2120
>>            if (invocation != null && finalLocation != null && finalLocation.length() > 0
>>                    && finalLocation.indexOf("?") > 0) {
>>                String queryString = finalLocation.substring(finalLocation.indexOf("?") + 1);
>>                Map parameters = (Map) invocation.getInvocationContext().getContextMap().get("parameters");
>>                Map queryParams = UrlHelper.parseQueryString(queryString, true);
>>                if (queryParams != null && !queryParams.isEmpty())
>>                    parameters.putAll(queryParams);
>>            }
>>
>>            // if the view doesn't exist, let's do a 404
>>            if (dispatcher == null) {
>>                response.sendError(404, "result '" + finalLocation + "' not found");
>>
>>                return;
>>            }
>>
>>            // If we're included, then include the view
>>            // Otherwise do forward
>>            // This allow the page to, for example, set content type
>>            if (!response.isCommitted() && (request.getAttribute("javax.servlet.include.servlet_path") == null)) {
>>                request.setAttribute("struts.view_uri", finalLocation);
>>                request.setAttribute("struts.request_uri", request.getRequestURI());
>>
>>                dispatcher.forward(request, response);
>>            } else {
>>                dispatcher.include(request, response);
>>            }
>>        }
>>    }
>> }
>>
>> //ServletDispatcherResult only handles navigation
>> //we still dont know how this validation is achieved until we look at /WEB-INF/classes/validators.xml
>> <!DOCTYPE validators PUBLIC
>>          "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
>>          "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
>> <validators>
>>    <validator name="required" class="com.opensymphony.xwork.validator.validators.RequiredFieldValidator"/>
>>
>> how does the FieldValidatorsExampleAction-submitFieldValidatorsExamples-validation.xml get referenced?
>> To define validation rules for an Action, create a file named ActionName-validation.xml
>> in the same package as the Action. You may also create alias-specific
>> validation rules which add to the default validation rules defined in ActionName-validation.xml by creating another file in the same directory named ActionName-aliasName-validation.xml.  In both cases,  ActionName is the name of the Action class, and aliasName is the name of the Action alias defined in the xwork.xml configuration for the Action.
>>
>>
>> The framework will also search up the inheritance tree of the Action
>> to find validation rules for directly implemented interfaces and parent
>> classes of the Action. This is particularly powerful when combined with
>> ModelDriven Actions and the VisitorFieldValidator.  Here's an example of how validation rules are discovered.  Given the following class structure:
>>
>>
>> interface Animal;interface Quadraped extends Animal;class AnimalImpl implements Animal;class QuadrapedImpl extends AnimalImpl implements Quadraped;class Dog extends QuadrapedImpl;
>>
>>
>> The framework method will look for the following config files if Dog is to be validated:
>>
>>
>> AnimalAnimal-aliasnameAnimalImplAnimalImpl-aliasnameQuadrapedQuadraped-aliasnameQuadrapedImplQuadrapedImpl-aliasnameDogDog-aliasname
>>
>>
>>
>> While this process is similar to what the XW:Localization
>> framework does when finding messages, there are some subtle
>> differences. The most important difference is that validation rules are
>> discovered from the parent downwards.
>> //how do i enable ValidationInterceptor in my webapp?
>>    <package name="example">
>>        <interceptors>
>>            <interceptor name="validator"
>>                class="com.opensymphony.xwork.validator.ValidationInterceptor"/>
>>        </interceptors>
>>
>> a worthwhile read to understanding xwork validation framework is available athttp://www.opensymphony.com/xwork/wikidocs/Validation%20Framework.html
>>
>> Martin Gainty
>> ______________________________________________
>> Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
>>
>> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
>> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.
>>
>>
>>
>>
>>> Date: Wed, 27 May 2009 06:18:36 -0400
>>> From: newton.dave@yahoo.com
>>> To: user@struts.apache.org
>>> Subject: Re: SV: RequiredString Validation doesn't work and AbstractValidationActionSupport   is missing?
>>>
>>> Niklas Johansson wrote:
>>>> P.S. AbstractValidationActionSupport doesn’t seem to be included in the
>>>> Struts2 (2.1.6) framework anyhow, couldn’t find it in any jar. But there are
>>>> quite a few so perhaps I missed it.
>>> It's in the showcase application, like I said before.
>>>
>>>> Från: Martin Gainty [mailto:mgainty@hotmail.com]
>>>>> do NOT extend ActionSupport as ActionSupport doesnt contain Field Validation
>>>>> Lofic
>>> Here's the source for AbstractValidationActionSupport:
>>>
>>> public abstract class AbstractValidationActionSupport
>>>                  extends ActionSupport {
>>>      public String submit() throws Exception {
>>>          return "success";
>>>      }
>>>      public String input() throws Exception {
>>>          return "input";
>>>      }
>>> }
>>>
>>> Please explain to us what you mean, both how the above method adds field
>>> validation logic, and how ActionSupport doesn't.
>>>
>>> Dave
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>> _________________________________________________________________
>> Insert movie times and more without leaving Hotmail®.
>> http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd1_052009
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

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


Re: SV: RequiredString Validation doesn't work and AbstractValidationActionSupport is missing?

Posted by Niklas Johansson <ni...@gmail.com>.
Hello,

Thanks for the information, but seriously, I think things are getting
just more complicated than needed now. As I mentioned, it does work
without AbstractValidationActionSupport. Just search Internet, there
are several examples.

This brings it all back to my problem. I been trying to find any
deviations from my working example I found on Internet with my own
implementation, can't find any difference. So please, can you see
anything that makes the validation not beeing applied? As mentioned,
when posting my empty form it invokes the action class, which it
shouldn't, it should react on the empty fields and return to the
client requesting before.

Dave, you mentioned something about using the default interceptor
stack. According to this page
http://www.struts2.org/form-validation-in-struts2-basic-server-side-validation-example/
it's not needed to define anything: "To use any of the predefined
validators, no initial configuration is needed. Validation is
implemented using a ValidationInterceptor which is configured in the
default interceptor stack." I haven't, intentionly at least, defined
any other validation interceptor stack. I am sure I would have
noticed...

Thanks again!

Regards,
Niklas

2009/5/27 Martin Gainty <mg...@hotmail.com>:
>
> --assuming you have this validation setup for your username from /validation/fieldValidatorsExample.jsp
> <validators>
>        <field name="requiredValidatorField">
>                <field-validator type="required">
>                        <message><![CDATA[ required ]]></message>
>                </field-validator>
>        </field>
> </validators>
> referencong doc from
> http://struts.apache.org/2.0.14/docs/using-field-validators.html
> //the abstract class determines navigation and flow (input being the first page)
> //success and or error being the end result
>    <package name="validationExamples" extends="struts-default" namespace="/validation" >
>
>        <!-- ======================== -->
>        <!-- === Field Validators === -->
>        <!-- ======================== -->
>        <action name="showFieldValidatorsExamples" class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction" method="input">
>            <result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>        </action>
>
>        <action name="submitFieldValidatorsExamples" class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction" method="submit">
>            <result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>            <result type="dispatcher">/validation/successFieldValidatorsExample.jsp</result>
>        </action>
>
>        <action name="submitFieldValidatorsExamples" class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction" method="submit">
>            <result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>            <result type="dispatcher">/validation/successFieldValidatorsExample.jsp</result>
>        </action>
>
> //determing where dispatcher mapped to is defined here
> <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
>
> /* <pre><!-- START SNIPPET: example -->
>  * <result name="success" type="dispatcher">
>  *   <param name="location">foo.jsp</param>
>  * </result>
>  * <!-- END SNIPPET: example --></pre>
>  *
>  * This result follows the same rules from {@link StrutsResultSupport}.
>  *
>  * @see javax.servlet.RequestDispatcher
>  */
> public class ServletDispatcherResult extends StrutsResultSupport {
>
>    private static final long serialVersionUID = -1970659272360685627L;
>
>    private static final Logger LOG = LoggerFactory.getLogger(ServletDispatcherResult.class);
>
>    public ServletDispatcherResult() {
>        super();
>    }
>
>    public ServletDispatcherResult(String location) {
>        super(location);
>    }
>
>    /**
>     * Dispatches to the given location. Does its forward via a RequestDispatcher. If the
>     * dispatch fails a 404 error will be sent back in the http response.
>     *
>     * @param finalLocation the location to dispatch to.
>     * @param invocation    the execution state of the action
>     * @throws Exception if an error occurs. If the dispatch fails the error will go back via the
>     *                   HTTP request.
>     */
> //if action returns input doExecute would take location of /validation/fieldValidatorsExample.jsp and route to
>  //<result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>
>    public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
>        if (LOG.isDebugEnabled()) {
>            LOG.debug("Forwarding to location " + finalLocation);
>        }
>
>        PageContext pageContext = ServletActionContext.getPageContext();
>
>        if (pageContext != null) {
>            pageContext.include(finalLocation);
>        } else {
>            HttpServletRequest request = ServletActionContext.getRequest();
>            HttpServletResponse response = ServletActionContext.getResponse();
>            RequestDispatcher dispatcher = request.getRequestDispatcher(finalLocation);
>
>            //add parameters passed on the location to #parameters
>            // see WW-2120
>            if (invocation != null && finalLocation != null && finalLocation.length() > 0
>                    && finalLocation.indexOf("?") > 0) {
>                String queryString = finalLocation.substring(finalLocation.indexOf("?") + 1);
>                Map parameters = (Map) invocation.getInvocationContext().getContextMap().get("parameters");
>                Map queryParams = UrlHelper.parseQueryString(queryString, true);
>                if (queryParams != null && !queryParams.isEmpty())
>                    parameters.putAll(queryParams);
>            }
>
>            // if the view doesn't exist, let's do a 404
>            if (dispatcher == null) {
>                response.sendError(404, "result '" + finalLocation + "' not found");
>
>                return;
>            }
>
>            // If we're included, then include the view
>            // Otherwise do forward
>            // This allow the page to, for example, set content type
>            if (!response.isCommitted() && (request.getAttribute("javax.servlet.include.servlet_path") == null)) {
>                request.setAttribute("struts.view_uri", finalLocation);
>                request.setAttribute("struts.request_uri", request.getRequestURI());
>
>                dispatcher.forward(request, response);
>            } else {
>                dispatcher.include(request, response);
>            }
>        }
>    }
> }
>
> //ServletDispatcherResult only handles navigation
> //we still dont know how this validation is achieved until we look at /WEB-INF/classes/validators.xml
> <!DOCTYPE validators PUBLIC
>          "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
>          "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
> <validators>
>    <validator name="required" class="com.opensymphony.xwork.validator.validators.RequiredFieldValidator"/>
>
> how does the FieldValidatorsExampleAction-submitFieldValidatorsExamples-validation.xml get referenced?
> To define validation rules for an Action, create a file named ActionName-validation.xml
> in the same package as the Action. You may also create alias-specific
> validation rules which add to the default validation rules defined in ActionName-validation.xml by creating another file in the same directory named ActionName-aliasName-validation.xml.  In both cases,  ActionName is the name of the Action class, and aliasName is the name of the Action alias defined in the xwork.xml configuration for the Action.
>
>
> The framework will also search up the inheritance tree of the Action
> to find validation rules for directly implemented interfaces and parent
> classes of the Action. This is particularly powerful when combined with
> ModelDriven Actions and the VisitorFieldValidator.  Here's an example of how validation rules are discovered.  Given the following class structure:
>
>
> interface Animal;interface Quadraped extends Animal;class AnimalImpl implements Animal;class QuadrapedImpl extends AnimalImpl implements Quadraped;class Dog extends QuadrapedImpl;
>
>
> The framework method will look for the following config files if Dog is to be validated:
>
>
> AnimalAnimal-aliasnameAnimalImplAnimalImpl-aliasnameQuadrapedQuadraped-aliasnameQuadrapedImplQuadrapedImpl-aliasnameDogDog-aliasname
>
>
>
> While this process is similar to what the XW:Localization
> framework does when finding messages, there are some subtle
> differences. The most important difference is that validation rules are
> discovered from the parent downwards.
> //how do i enable ValidationInterceptor in my webapp?
>    <package name="example">
>        <interceptors>
>            <interceptor name="validator"
>                class="com.opensymphony.xwork.validator.ValidationInterceptor"/>
>        </interceptors>
>
> a worthwhile read to understanding xwork validation framework is available athttp://www.opensymphony.com/xwork/wikidocs/Validation%20Framework.html
>
> Martin Gainty
> ______________________________________________
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
>
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.
>
>
>
>
>> Date: Wed, 27 May 2009 06:18:36 -0400
>> From: newton.dave@yahoo.com
>> To: user@struts.apache.org
>> Subject: Re: SV: RequiredString Validation doesn't work and AbstractValidationActionSupport   is missing?
>>
>> Niklas Johansson wrote:
>> > P.S. AbstractValidationActionSupport doesn’t seem to be included in the
>> > Struts2 (2.1.6) framework anyhow, couldn’t find it in any jar. But there are
>> > quite a few so perhaps I missed it.
>>
>> It's in the showcase application, like I said before.
>>
>> > Från: Martin Gainty [mailto:mgainty@hotmail.com]
>> >> do NOT extend ActionSupport as ActionSupport doesnt contain Field Validation
>> >> Lofic
>>
>> Here's the source for AbstractValidationActionSupport:
>>
>> public abstract class AbstractValidationActionSupport
>>                  extends ActionSupport {
>>      public String submit() throws Exception {
>>          return "success";
>>      }
>>      public String input() throws Exception {
>>          return "input";
>>      }
>> }
>>
>> Please explain to us what you mean, both how the above method adds field
>> validation logic, and how ActionSupport doesn't.
>>
>> Dave
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
> _________________________________________________________________
> Insert movie times and more without leaving Hotmail®.
> http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd1_052009

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


Re: SV: RequiredString Validation doesn't work and AbstractValidationActionSupport is missing?

Posted by Dave Newton <ne...@yahoo.com>.
What were you trying to communicate here?

You don't need to do anything with any showcase app classes to get 
validation to work.

Here you've included some validation configuration, some action 
configuration, ServletDispatcherResult?!, and I don't even know what else.

Can you explain shorter? You're just confusing people by posting all 
this source code, and I'm reasonably sure I have a decent handle on how 
the validation stuff works.

Martin Gainty wrote:
> --assuming you have this validation setup for your username from /validation/fieldValidatorsExample.jsp
> <validators>
> 	<field name="requiredValidatorField">
> 		<field-validator type="required">
> 			<message><![CDATA[ required ]]></message>
> 		</field-validator>
> 	</field>
> </validators>
> referencong doc from
> http://struts.apache.org/2.0.14/docs/using-field-validators.html
> //the abstract class determines navigation and flow (input being the first page)
> //success and or error being the end result
>     <package name="validationExamples" extends="struts-default" namespace="/validation" >        
>         
>         <!-- ======================== -->
>         <!-- === Field Validators === -->
>         <!-- ======================== -->
>         <action name="showFieldValidatorsExamples" class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction" method="input">
>             <result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>         </action>
>         
>         <action name="submitFieldValidatorsExamples" class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction" method="submit">
>             <result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>             <result type="dispatcher">/validation/successFieldValidatorsExample.jsp</result>
>         </action>
> 
>         <action name="submitFieldValidatorsExamples" class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction" method="submit">
>             <result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
>             <result type="dispatcher">/validation/successFieldValidatorsExample.jsp</result>
>         </action>
> 
> //determing where dispatcher mapped to is defined here
> <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
> 
> /* <pre><!-- START SNIPPET: example -->
>  * &lt;result name="success" type="dispatcher"&gt;
>  *   &lt;param name="location"&gt;foo.jsp&lt;/param&gt;
>  * &lt;/result&gt;
>  * <!-- END SNIPPET: example --></pre>
>  *
>  * This result follows the same rules from {@link StrutsResultSupport}.
>  *
>  * @see javax.servlet.RequestDispatcher
>  */
> public class ServletDispatcherResult extends StrutsResultSupport {
> 
>     private static final long serialVersionUID = -1970659272360685627L;
> 
>     private static final Logger LOG = LoggerFactory.getLogger(ServletDispatcherResult.class);
> 
>     public ServletDispatcherResult() {
>         super();
>     }
> 
>     public ServletDispatcherResult(String location) {
>         super(location);
>     }
> 
>     /**
>      * Dispatches to the given location. Does its forward via a RequestDispatcher. If the
>      * dispatch fails a 404 error will be sent back in the http response.
>      *
>      * @param finalLocation the location to dispatch to.
>      * @param invocation    the execution state of the action
>      * @throws Exception if an error occurs. If the dispatch fails the error will go back via the
>      *                   HTTP request.
>      */
> //if action returns input doExecute would take location of /validation/fieldValidatorsExample.jsp and route to
>  //<result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
> 
>     public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
>         if (LOG.isDebugEnabled()) {
>             LOG.debug("Forwarding to location " + finalLocation);
>         }
> 
>         PageContext pageContext = ServletActionContext.getPageContext();
> 
>         if (pageContext != null) {
>             pageContext.include(finalLocation);
>         } else {
>             HttpServletRequest request = ServletActionContext.getRequest();
>             HttpServletResponse response = ServletActionContext.getResponse();
>             RequestDispatcher dispatcher = request.getRequestDispatcher(finalLocation);
> 
>             //add parameters passed on the location to #parameters
>             // see WW-2120
>             if (invocation != null && finalLocation != null && finalLocation.length() > 0
>                     && finalLocation.indexOf("?") > 0) {
>                 String queryString = finalLocation.substring(finalLocation.indexOf("?") + 1);
>                 Map parameters = (Map) invocation.getInvocationContext().getContextMap().get("parameters");
>                 Map queryParams = UrlHelper.parseQueryString(queryString, true);
>                 if (queryParams != null && !queryParams.isEmpty())
>                     parameters.putAll(queryParams);
>             }
> 
>             // if the view doesn't exist, let's do a 404
>             if (dispatcher == null) {
>                 response.sendError(404, "result '" + finalLocation + "' not found");
> 
>                 return;
>             }
> 
>             // If we're included, then include the view
>             // Otherwise do forward
>             // This allow the page to, for example, set content type
>             if (!response.isCommitted() && (request.getAttribute("javax.servlet.include.servlet_path") == null)) {
>                 request.setAttribute("struts.view_uri", finalLocation);
>                 request.setAttribute("struts.request_uri", request.getRequestURI());
> 
>                 dispatcher.forward(request, response);
>             } else {
>                 dispatcher.include(request, response);
>             }
>         }
>     }
> }
> 
> //ServletDispatcherResult only handles navigation
> //we still dont know how this validation is achieved until we look at /WEB-INF/classes/validators.xml
> <!DOCTYPE validators PUBLIC 
>           "-//OpenSymphony Group//XWork Validator 1.0.2//EN" 
>           "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
> <validators>
>     <validator name="required" class="com.opensymphony.xwork.validator.validators.RequiredFieldValidator"/>
> 
> how does the FieldValidatorsExampleAction-submitFieldValidatorsExamples-validation.xml get referenced?
> To define validation rules for an Action, create a file named ActionName-validation.xml
> in the same package as the Action. You may also create alias-specific
> validation rules which add to the default validation rules defined in ActionName-validation.xml by creating another file in the same directory named ActionName-aliasName-validation.xml.  In both cases,  ActionName is the name of the Action class, and aliasName is the name of the Action alias defined in the xwork.xml configuration for the Action. 
> 
> 
> The framework will also search up the inheritance tree of the Action
> to find validation rules for directly implemented interfaces and parent
> classes of the Action. This is particularly powerful when combined with
> ModelDriven Actions and the VisitorFieldValidator.  Here's an example of how validation rules are discovered.  Given the following class structure:
> 
> 
> interface Animal;interface Quadraped extends Animal;class AnimalImpl implements Animal;class QuadrapedImpl extends AnimalImpl implements Quadraped;class Dog extends QuadrapedImpl;
> 
> 
> The framework method will look for the following config files if Dog is to be validated:
> 
> 
> AnimalAnimal-aliasnameAnimalImplAnimalImpl-aliasnameQuadrapedQuadraped-aliasnameQuadrapedImplQuadrapedImpl-aliasnameDogDog-aliasname
> 
> 
> 
> While this process is similar to what the XW:Localization
> framework does when finding messages, there are some subtle
> differences. The most important difference is that validation rules are
> discovered from the parent downwards.
> //how do i enable ValidationInterceptor in my webapp?
>     <package name="example">
>         <interceptors>
>             <interceptor name="validator" 
>                 class="com.opensymphony.xwork.validator.ValidationInterceptor"/>
>         </interceptors>
> 
> a worthwhile read to understanding xwork validation framework is available athttp://www.opensymphony.com/xwork/wikidocs/Validation%20Framework.html
> 
> Martin Gainty 
> ______________________________________________ 
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
>  
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.
> 
> 
> 
> 
>> Date: Wed, 27 May 2009 06:18:36 -0400
>> From: newton.dave@yahoo.com
>> To: user@struts.apache.org
>> Subject: Re: SV: RequiredString Validation doesn't work and AbstractValidationActionSupport 	is missing?
>>
>> Niklas Johansson wrote:
>>> P.S. AbstractValidationActionSupport doesn’t seem to be included in the
>>> Struts2 (2.1.6) framework anyhow, couldn’t find it in any jar. But there are
>>> quite a few so perhaps I missed it.
>> It's in the showcase application, like I said before.
>>
>>> Från: Martin Gainty [mailto:mgainty@hotmail.com] 
>>>> do NOT extend ActionSupport as ActionSupport doesnt contain Field Validation
>>>> Lofic
>> Here's the source for AbstractValidationActionSupport:
>>
>> public abstract class AbstractValidationActionSupport
>>                  extends ActionSupport {
>>      public String submit() throws Exception {
>>          return "success";
>>      }
>>      public String input() throws Exception {
>>          return "input";
>>      }
>> }
>>
>> Please explain to us what you mean, both how the above method adds field 
>> validation logic, and how ActionSupport doesn't.
>>
>> Dave
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
> 
> _________________________________________________________________
> Insert movie times and more without leaving Hotmail®.
> http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd1_052009

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


RE: SV: RequiredString Validation doesn't work and AbstractValidationActionSupport is missing?

Posted by Martin Gainty <mg...@hotmail.com>.
--assuming you have this validation setup for your username from /validation/fieldValidatorsExample.jsp
<validators>
	<field name="requiredValidatorField">
		<field-validator type="required">
			<message><![CDATA[ required ]]></message>
		</field-validator>
	</field>
</validators>
referencong doc from
http://struts.apache.org/2.0.14/docs/using-field-validators.html
//the abstract class determines navigation and flow (input being the first page)
//success and or error being the end result
    <package name="validationExamples" extends="struts-default" namespace="/validation" >        
        
        <!-- ======================== -->
        <!-- === Field Validators === -->
        <!-- ======================== -->
        <action name="showFieldValidatorsExamples" class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction" method="input">
            <result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
        </action>
        
        <action name="submitFieldValidatorsExamples" class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction" method="submit">
            <result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
            <result type="dispatcher">/validation/successFieldValidatorsExample.jsp</result>
        </action>

        <action name="submitFieldValidatorsExamples" class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction" method="submit">
            <result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>
            <result type="dispatcher">/validation/successFieldValidatorsExample.jsp</result>
        </action>

//determing where dispatcher mapped to is defined here
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>

/* <pre><!-- START SNIPPET: example -->
 * &lt;result name="success" type="dispatcher"&gt;
 *   &lt;param name="location"&gt;foo.jsp&lt;/param&gt;
 * &lt;/result&gt;
 * <!-- END SNIPPET: example --></pre>
 *
 * This result follows the same rules from {@link StrutsResultSupport}.
 *
 * @see javax.servlet.RequestDispatcher
 */
public class ServletDispatcherResult extends StrutsResultSupport {

    private static final long serialVersionUID = -1970659272360685627L;

    private static final Logger LOG = LoggerFactory.getLogger(ServletDispatcherResult.class);

    public ServletDispatcherResult() {
        super();
    }

    public ServletDispatcherResult(String location) {
        super(location);
    }

    /**
     * Dispatches to the given location. Does its forward via a RequestDispatcher. If the
     * dispatch fails a 404 error will be sent back in the http response.
     *
     * @param finalLocation the location to dispatch to.
     * @param invocation    the execution state of the action
     * @throws Exception if an error occurs. If the dispatch fails the error will go back via the
     *                   HTTP request.
     */
//if action returns input doExecute would take location of /validation/fieldValidatorsExample.jsp and route to
 //<result name="input" type="dispatcher">/validation/fieldValidatorsExample.jsp</result>

    public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Forwarding to location " + finalLocation);
        }

        PageContext pageContext = ServletActionContext.getPageContext();

        if (pageContext != null) {
            pageContext.include(finalLocation);
        } else {
            HttpServletRequest request = ServletActionContext.getRequest();
            HttpServletResponse response = ServletActionContext.getResponse();
            RequestDispatcher dispatcher = request.getRequestDispatcher(finalLocation);

            //add parameters passed on the location to #parameters
            // see WW-2120
            if (invocation != null && finalLocation != null && finalLocation.length() > 0
                    && finalLocation.indexOf("?") > 0) {
                String queryString = finalLocation.substring(finalLocation.indexOf("?") + 1);
                Map parameters = (Map) invocation.getInvocationContext().getContextMap().get("parameters");
                Map queryParams = UrlHelper.parseQueryString(queryString, true);
                if (queryParams != null && !queryParams.isEmpty())
                    parameters.putAll(queryParams);
            }

            // if the view doesn't exist, let's do a 404
            if (dispatcher == null) {
                response.sendError(404, "result '" + finalLocation + "' not found");

                return;
            }

            // If we're included, then include the view
            // Otherwise do forward
            // This allow the page to, for example, set content type
            if (!response.isCommitted() && (request.getAttribute("javax.servlet.include.servlet_path") == null)) {
                request.setAttribute("struts.view_uri", finalLocation);
                request.setAttribute("struts.request_uri", request.getRequestURI());

                dispatcher.forward(request, response);
            } else {
                dispatcher.include(request, response);
            }
        }
    }
}

//ServletDispatcherResult only handles navigation
//we still dont know how this validation is achieved until we look at /WEB-INF/classes/validators.xml
<!DOCTYPE validators PUBLIC 
          "-//OpenSymphony Group//XWork Validator 1.0.2//EN" 
          "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
    <validator name="required" class="com.opensymphony.xwork.validator.validators.RequiredFieldValidator"/>

how does the FieldValidatorsExampleAction-submitFieldValidatorsExamples-validation.xml get referenced?
To define validation rules for an Action, create a file named ActionName-validation.xml
in the same package as the Action. You may also create alias-specific
validation rules which add to the default validation rules defined in ActionName-validation.xml by creating another file in the same directory named ActionName-aliasName-validation.xml.  In both cases,  ActionName is the name of the Action class, and aliasName is the name of the Action alias defined in the xwork.xml configuration for the Action. 


The framework will also search up the inheritance tree of the Action
to find validation rules for directly implemented interfaces and parent
classes of the Action. This is particularly powerful when combined with
ModelDriven Actions and the VisitorFieldValidator.  Here's an example of how validation rules are discovered.  Given the following class structure:


interface Animal;interface Quadraped extends Animal;class AnimalImpl implements Animal;class QuadrapedImpl extends AnimalImpl implements Quadraped;class Dog extends QuadrapedImpl;


The framework method will look for the following config files if Dog is to be validated:


AnimalAnimal-aliasnameAnimalImplAnimalImpl-aliasnameQuadrapedQuadraped-aliasnameQuadrapedImplQuadrapedImpl-aliasnameDogDog-aliasname



While this process is similar to what the XW:Localization
framework does when finding messages, there are some subtle
differences. The most important difference is that validation rules are
discovered from the parent downwards.
//how do i enable ValidationInterceptor in my webapp?
    <package name="example">
        <interceptors>
            <interceptor name="validator" 
                class="com.opensymphony.xwork.validator.ValidationInterceptor"/>
        </interceptors>

a worthwhile read to understanding xwork validation framework is available athttp://www.opensymphony.com/xwork/wikidocs/Validation%20Framework.html

Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Date: Wed, 27 May 2009 06:18:36 -0400
> From: newton.dave@yahoo.com
> To: user@struts.apache.org
> Subject: Re: SV: RequiredString Validation doesn't work and AbstractValidationActionSupport 	is missing?
> 
> Niklas Johansson wrote:
> > P.S. AbstractValidationActionSupport doesn’t seem to be included in the
> > Struts2 (2.1.6) framework anyhow, couldn’t find it in any jar. But there are
> > quite a few so perhaps I missed it.
> 
> It's in the showcase application, like I said before.
> 
> > Från: Martin Gainty [mailto:mgainty@hotmail.com] 
> >> do NOT extend ActionSupport as ActionSupport doesnt contain Field Validation
> >> Lofic
> 
> Here's the source for AbstractValidationActionSupport:
> 
> public abstract class AbstractValidationActionSupport
>                  extends ActionSupport {
>      public String submit() throws Exception {
>          return "success";
>      }
>      public String input() throws Exception {
>          return "input";
>      }
> }
> 
> Please explain to us what you mean, both how the above method adds field 
> validation logic, and how ActionSupport doesn't.
> 
> Dave
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

_________________________________________________________________
Insert movie times and more without leaving Hotmail®.
http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd1_052009

Re: SV: RequiredString Validation doesn't work and AbstractValidationActionSupport is missing?

Posted by Dave Newton <ne...@yahoo.com>.
Niklas Johansson wrote:
> P.S. AbstractValidationActionSupport doesn’t seem to be included in the
> Struts2 (2.1.6) framework anyhow, couldn’t find it in any jar. But there are
> quite a few so perhaps I missed it.

It's in the showcase application, like I said before.

> Från: Martin Gainty [mailto:mgainty@hotmail.com] 
>> do NOT extend ActionSupport as ActionSupport doesnt contain Field Validation
>> Lofic

Here's the source for AbstractValidationActionSupport:

public abstract class AbstractValidationActionSupport
                 extends ActionSupport {
     public String submit() throws Exception {
         return "success";
     }
     public String input() throws Exception {
         return "input";
     }
}

Please explain to us what you mean, both how the above method adds field 
validation logic, and how ActionSupport doesn't.

Dave

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


SV: RequiredString Validation doesn't work and AbstractValidationActionSupport is missing?

Posted by Niklas Johansson <ni...@gmail.com>.
Hello,

Thanks for your reply! 

Now it’s getting a bit messy for me. I got some replies from Dave Newton
before, saying that AbstractValidationActionSupport is not needed, extending
ActionSupport should be enough. Actually, I did get it working without
AbstractValidationActionSupport with the example I found somewhere on
Internet. Similar setup as in my included code below. Looking at other
examples on Internet, it also extends ActionSupport (e.g.
http://www.struts2.org/form-validation-in-struts2-basic-server-side-validati
on-example/ ).

Any clue?

Regards,
Niklas

P.S. AbstractValidationActionSupport doesn’t seem to be included in the
Struts2 (2.1.6) framework anyhow, couldn’t find it in any jar. But there are
quite a few so perhaps I missed it. 
D.S.

Från: Martin Gainty [mailto:mgainty@hotmail.com] 
Skickat: den 26 maj 2009 23:32
Till: nicssoft@gmail.com
Ämne: RE: RequiredString Validation doesn't work and
AbstractValidationActionSupport is missing?

Niklas-
This is how Field Validation is performed using Struts2 (note there no Form
Classes)
you must follow these examples explicitly especially where your class
extends AbstractValidationActionSupport
do NOT extend ActionSupport as ActionSupport doesnt contain Field Validation
Lofic

struts-validation.xml contents:
<!-- === Field Validators === -->
<!-- define the Action class -->
<action name="showFieldValidatorsExamples"
class="org.apache.struts2.showcase.validation.FieldValidatorsExampleAction"
method="input">
     <result name="input"
type="dispatcher">/validation/fieldValidatorsExample.jsp</result>

<!-- 2 schools of thought deliver a small Error message back to input.jsp
-->
<!-- or toss a ERROR which will deliver ERROR Result back -->
<!-- since we are using s:fielderror with the param of
requiredValidatorField we will bypass-->
    <!-- result name="success"
type="dispatcher">/validation/fieldValidatorsExample.jsp</result -->
    <!-- result name="error" >/validation/fieldValidatorsExample.jsp</result
-->
</action>

/*********code *********/
public class FieldValidatorsExampleAction extends
AbstractValidationActionSupport 
{
    private static final long serialVersionUID = -4829381083003175423L;
    private String requiredValidatorField = null;

    public String getRequiredValidatorField() 
    {
        return requiredValidatorField;
    }
    public void setRequiredValidatorField(String requiredValidatorField) {
        this.requiredValidatorField = requiredValidatorField;
    }
   public String execute() throws Exception 
   { 
    if(requiredValidatorField==null) return ERROR;
    else                                    return SUCCESS;
   } 
}

fieldValidatorsExample.jsp
<h3>All Field Errors Will Appear Here</h3>
<s:fielderror />
<hr/>
<h3>Field Error due to 'Required Validator Field' Will Appear Here</h3>
<s:fielderror>
    <s:param value="%{'requiredValidatorField'}" />
</s:fielderror>
<hr/>
    
<s:form action="submitFieldValidatorsExamples" namespace="/validation"
method="POST" theme="xhtml">
    <s:textfield label="Required Validator Field"
name="requiredValidatorField" />
    <s:submit label="Submit" />
</s:form>

<!-- validators.xml (requisite validation elments for
requiredValidatorField) --> 
<validators>
	<field name="requiredValidatorField">
		<field-validator type="required">
			<message><![CDATA[ required ]]></message>
		</field-validator>
	</field>
</validators>
Whereabouts is your office?
Martin Gainty
______________________________________________ 
Jogi és Bizalmassági kinyilatkoztatás/Verzicht und
Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Ez az üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy
jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának készítése
nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és semmiféle jogi
alkalmazhatósága sincs.  Mivel az electronikus üzenetek könnyen
megváltoztathatóak, ezért minket semmi felelöség nem terhelhet ezen üzenet
tartalma miatt.

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene
Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte
Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht
dient lediglich dem Austausch von Informationen und entfaltet keine
rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von
E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le
destinataire prévu, nous te demandons avec bonté que pour satisfaire
informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie
de ceci est interdite. Ce message sert à l'information seulement et n'aura
pas n'importe quel effet légalement obligatoire. Étant donné que les email
peuvent facilement être sujets à la manipulation, nous ne pouvons accepter
aucune responsabilité pour le contenu fourni.





> Date: Tue, 26 May 2009 21:58:24 +0200
> Subject: Re: RequiredString Validation doesn't work and
AbstractValidationActionSupport is missing?
> From: nicssoft@gmail.com
> To: user@struts.apache.org
> 
> This ain't going to well, I am sorry for taking your time! However, I
> must be close to the solution since I found an example on Internet
> which I managed to get to work, more or less like I want it to work.
> 
> But when going back to my own code, it still doesn't work, even though
> I tried to do exactly as the example I found and made work. It looks
> like the validation is never performed and, hence, no message returned
> to the client about what information is missing/incorrect. I do write
> something in the execute() of the RegisterQAFormAction class and it is
> written to the console even though I don't have any text in required
> inputfields.
> 
> Regarding the default interceptor stack; I think I do use it, because
> as far as I understand I haven't defined anything else.
> 
> I found one comment that "<s:head/>" is needed in the jsp, is it
> required or just for formatting?
> 
> I include my updated code here:
> 
> RegisterQAFormAction class:
> 
> package org.nicsoft.application.mobiletraining.qa;
> 
> import com.opensymphony.xwork2.ActionSupport;
> 
> public class RegisterQAFormAction extends ActionSupport {
> 
> private String heading;
> private String answer;
> 
> 
> public String execute() throws Exception {
> 
> System.out.println("INSIDE EXECUTION***************** ");
> return SUCCESS;
> } 
> 
> public void setHeading(String heading){
> this.heading = heading;
> }
> 
> public String getHeading(){
> return this.heading;
> }
> 
> public void setAnswer(String answer){
> this.answer = answer;
> }
> 
> public String getAnswer(){
> return this.answer;
> }
> }
> 
> ReqisterQAFormAction-validation.xml:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!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="heading">
> <field-validator type="requiredstring">
> <param name="trim">true</param>
> <message>Heading is required</message>
> </field-validator>
> </field>
> 
> <field name="answer">
> <field-validator type="requiredstring">
> <param name="trim">true</param>
> <message>Answer is required</message>
> </field-validator>
> </field>
> 
> </validators>
> 
> part of struts.xml:
> 
> <package name="org.nicsoft.application.mobiletraining.qa"
> extends="struts-default">
> <action name="postRegisterQAForm"
> class="org.nicsoft.application.mobiletraining.qa.RegisterQAFormAction">
> <result name="input">/jsp/forms/registerqa.jsp</result> 
> <result>/jsp/forms/registerqa.jsp</result>
> </action>
> <action name="getRegisterQA">
> <result>/jsp/forms/registerqa.jsp</result>
> </action> 
> </package>
> 
> 
> registerqa.jsp:
> 
> 
> <%@ page language="java" contentType="text/html; charset=UTF-8"
> pageEncoding="UTF-8"%>
> <%@ taglib prefix="s" uri="/struts-tags" %>
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/html4/loose.dtd">
> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
> <link rel="stylesheet" href="../resources/css/mobiletrainingstyle.css"
> type="text/css" media="screen">
> <title>Insert title here</title>
> <s:head/>
> </head>
> 
> <body>
> 
> <h3 class="redtext"><s:property value="message" /></h3>
> 
> <s:form action="postRegisterQAForm.action"> 
> <s:textfield name="heading" label="Fråga" required="true"/>
> <s:textfield name="answer" label="Svar" required="true"/> 
> <s:submit value="Spara" align="center"/>
> </s:form>
> </body>
> </html>
> 
> Thanks again!
> 
> Regards,
> Niklas
> 
> 2009/5/25 Dave Newton <ne...@yahoo.com>:
> > Niklas Johansson wrote:
> >>
> >> I want to use Requieredstring validator. The problem is that my
> >> application is not complaining if I do leave the input field empty.
> >
> > Are you using the default interceptor stack?
> >
> >> Can anyone tell me what is the problem?
> >
> > I don't see anything immediately obvious, but I'm sleepy.
> >
> >> Q: "why you're using ParameterAware" ... "it's generally cleaner to
> >> just use the action properties"
> >>
> >> A: The reason is because I found the instructions on the struts
> >> homepage. Using the action properties, I assume I need to define those
> >> in the struts.xml, correct?
> >
> > Define what in the struts.xml? The "struts homepage" doesn't have
> > instructions for doing *anything*, so you'll have to be more specific as
to
> > what you were reading so we can correct it.
> >
> > The probable answer to your question is "no". One of the main features
(IMO)
> > of S2 is that it eliminates a lot of back-and-forth between HTML forms
and
> > actions, meaning your code could be written follows, getters and setters
> > elided. (And why make the action properties public if you have
> > getters/setters for them?)
> >
> > public class RegisterQAFormAction extends ActionSupport {
> >
> >    private String message;
> >    private String heading;
> >
> >    public String execute() throws Exception {
> >        System.out.println(heading);
> >        System.out.println(answer);
> >
> >        // Don't know what this is trying to do, so ignoring.
> >        //QAHandler handleQA = new QAHandler();
> >        //handleQA.storeQA(param);
> >
> >        setMessage("Ärende " + heading + " registrerat");
> >        if (getHeading() == null) {
> >            return ERROR;
> >        }
> >
> >        return SUCCESS;
> >    }
> >
> > }
> >
> > Note that heading won't be null if the user doesn't enter a value--it
will
> > be an empty string, so in all probability this is a bug in your code.
> >
> >> Q: "That class is part of the showcase app, not part of Struts itself."
> >>
> >> A: So what is the solution? The instructions wasn't that clear about
> >> where the class came from on the instruction page:
> >> http://struts.apache.org/2.1.6/docs/using-field-validators.html
> >
> > Solution to what problem? You don't need that class to use the
validation as
> > you've written it above.
> >
> > Dave
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
________________________________________
Insert movie times and more without leaving Hotmail®. See how.


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


Re: RequiredString Validation doesn't work and AbstractValidationActionSupport is missing?

Posted by Niklas Johansson <ni...@gmail.com>.
This ain't going to well, I am sorry for taking your time! However, I
must be close to the solution since I found an example on Internet
which I managed to get to work, more or less like I want it to work.

But when going back to my own code, it still doesn't work, even though
I tried to do exactly as the example I found and made work. It looks
like the validation is never performed and, hence, no message returned
to the client about what information is missing/incorrect. I do write
something in the execute() of the RegisterQAFormAction class and it is
written to the console even though I don't have any text in required
inputfields.

Regarding the default interceptor stack; I think I do use it, because
as far as I understand I haven't defined anything else.

I found one comment that "<s:head/>" is needed in the jsp, is it
required or just for formatting?

I include my updated code here:

RegisterQAFormAction  class:

package org.nicsoft.application.mobiletraining.qa;

import com.opensymphony.xwork2.ActionSupport;

public class RegisterQAFormAction extends ActionSupport {

	private String heading;
	private String answer;

	
	public String execute() throws Exception {
		
		System.out.println("INSIDE EXECUTION***************** ");
    	      return SUCCESS;
    }	

    public void setHeading(String heading){
    	this.heading = heading;
    }

    public String getHeading(){
    	return this.heading;
    }

    public void setAnswer(String answer){
    	this.answer = answer;
    }

    public String getAnswer(){
    	return this.answer;
    }
}

ReqisterQAFormAction-validation.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!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="heading">
    <field-validator type="requiredstring">
      <param name="trim">true</param>
      <message>Heading is required</message>
    </field-validator>
  </field>

   <field name="answer">
    <field-validator type="requiredstring">
      <param name="trim">true</param>
      <message>Answer is required</message>
    </field-validator>
  </field>

</validators>

part of struts.xml:

<package name="org.nicsoft.application.mobiletraining.qa"
extends="struts-default">
     	<action name="postRegisterQAForm"
class="org.nicsoft.application.mobiletraining.qa.RegisterQAFormAction">
     			<result name="input">/jsp/forms/registerqa.jsp</result>	      		
            	<result>/jsp/forms/registerqa.jsp</result>
        </action>
     	<action name="getRegisterQA">
            <result>/jsp/forms/registerqa.jsp</result>
        </action>	
</package>


registerqa.jsp:


<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
    <%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../resources/css/mobiletrainingstyle.css"
type="text/css" media="screen">
<title>Insert title here</title>
<s:head/>
</head>

<body>

<h3 class="redtext"><s:property value="message" /></h3>

	<s:form action="postRegisterQAForm.action">			
    		<s:textfield name="heading" label="Fråga" required="true"/>
    		<s:textfield name="answer" label="Svar" required="true"/>    		
       		<s:submit value="Spara" align="center"/>
  	</s:form>
</body>
</html>

Thanks again!

Regards,
Niklas

2009/5/25 Dave Newton <ne...@yahoo.com>:
> Niklas Johansson wrote:
>>
>> I want to use Requieredstring validator. The problem is that my
>> application is not complaining if I do leave the input field empty.
>
> Are you using the default interceptor stack?
>
>> Can anyone tell me what is the problem?
>
> I don't see anything immediately obvious, but I'm sleepy.
>
>> Q: "why you're using ParameterAware" ... "it's generally cleaner to
>> just use the action properties"
>>
>> A: The reason is because I found the instructions on the struts
>> homepage. Using the action properties, I assume I need to define those
>> in the struts.xml, correct?
>
> Define what in the struts.xml? The "struts homepage" doesn't have
> instructions for doing *anything*, so you'll have to be more specific as to
> what you were reading so we can correct it.
>
> The probable answer to your question is "no". One of the main features (IMO)
> of S2 is that it eliminates a lot of back-and-forth between HTML forms and
> actions, meaning your code could be written follows, getters and setters
> elided. (And why make the action properties public if you have
> getters/setters for them?)
>
> public class RegisterQAFormAction extends ActionSupport {
>
>    private String message;
>    private String heading;
>
>    public String execute() throws Exception {
>        System.out.println(heading);
>        System.out.println(answer);
>
>        // Don't know what this is trying to do, so ignoring.
>        //QAHandler handleQA = new QAHandler();
>        //handleQA.storeQA(param);
>
>        setMessage("Ärende " + heading + " registrerat");
>        if (getHeading() == null) {
>            return ERROR;
>        }
>
>        return SUCCESS;
>    }
>
> }
>
> Note that heading won't be null if the user doesn't enter a value--it will
> be an empty string, so in all probability this is a bug in your code.
>
>> Q: "That class is part of the showcase app, not part of Struts itself."
>>
>> A: So what is the solution? The instructions wasn't that clear about
>> where the class came from on the instruction page:
>> http://struts.apache.org/2.1.6/docs/using-field-validators.html
>
> Solution to what problem? You don't need that class to use the validation as
> you've written it above.
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


Re: RequiredString Validation doesn't work and AbstractValidationActionSupport is missing?

Posted by Dave Newton <ne...@yahoo.com>.
Niklas Johansson wrote:
> I want to use Requieredstring validator. The problem is that my
> application is not complaining if I do leave the input field empty.

Are you using the default interceptor stack?

> Can anyone tell me what is the problem?

I don't see anything immediately obvious, but I'm sleepy.

> Q: "why you're using ParameterAware" ... "it's generally cleaner to
> just use the action properties"
> 
> A: The reason is because I found the instructions on the struts
> homepage. Using the action properties, I assume I need to define those
> in the struts.xml, correct?

Define what in the struts.xml? The "struts homepage" doesn't have 
instructions for doing *anything*, so you'll have to be more specific as 
to what you were reading so we can correct it.

The probable answer to your question is "no". One of the main features 
(IMO) of S2 is that it eliminates a lot of back-and-forth between HTML 
forms and actions, meaning your code could be written follows, getters 
and setters elided. (And why make the action properties public if you 
have getters/setters for them?)

public class RegisterQAFormAction extends ActionSupport {

     private String message;
     private String heading;

     public String execute() throws Exception {
         System.out.println(heading);
         System.out.println(answer);

         // Don't know what this is trying to do, so ignoring.
         //QAHandler handleQA = new QAHandler();
         //handleQA.storeQA(param);

         setMessage("Ärende " + heading + " registrerat");
         if (getHeading() == null) {
             return ERROR;
         }

         return SUCCESS;
     }

}

Note that heading won't be null if the user doesn't enter a value--it 
will be an empty string, so in all probability this is a bug in your code.

> Q: "That class is part of the showcase app, not part of Struts itself."
> 
> A: So what is the solution? The instructions wasn't that clear about
> where the class came from on the instruction page:
> http://struts.apache.org/2.1.6/docs/using-field-validators.html

Solution to what problem? You don't need that class to use the 
validation as you've written it above.

Dave

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