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:mgai...@hotmail.com] 
Skickat: den 26 maj 2009 23:32
Till: nicss...@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: nicss...@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 <newton.d...@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-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
> 
________________________________________
Insert movie times and more without leaving Hotmail®. See how.


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

Reply via email to