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 <mgai...@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.d...@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:mgai...@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-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@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-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org



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

Reply via email to