-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
 
Hello Márcio*,

*thanks for your quick answer. Yes, that will work, you're right.
Unfortunately is is not exactly what i would want. You are doing your
validation in the method that is called.
I would prefer the framework to call *validate()* before (!) my method
(in that case "save" ) is called.
This should happen when I subclass from ActionSupport and implement
validate(), but it only seems to work
when the method execute() is called.

I could call validate() from the method save in it's beginning (that's
in fact what I do now), but that not the intention
of the interfaces Validatable/ValidationAware. So I hope, anyone can
give me a hint as I like to write clean, readable
code and do not want to create "workarounds" all the time ;)

Anyway, thanks for the effort.

  Volker

*
*Márcio Gurgel schrieb:
> Hi Volker,
>
> You can do it with struts xml validator:
>
> Include a xml into your action package like this:
>
> ActionName - alias from action -  validation.xml
> Example:
> ActionName-save-validation.xml
>
> * Note that "save" is the name of action in your struts.xml
>
> Nothing better than a real example:
>
> struts.xml -------------------------------------------------------
> <action name="salvar" method="salvar"
>             class="br.com.sgvdba.actions.usu.UsuAction">
>             <result name="success" type="redirectAction">
>                 <param name="idUsu">${currentUsu.cd}</param>
>                 <param name="actionName">abrirDados</param>
>                 <param name="namespace">/usuario</param>
>             </result>
>             <result type="tiles" name="input">default.usu</result>
>         </action>
>
> UsuAction (Action class) -----------------------------------------
> /**
>      * Persiste determinado usuário no banco de dados
>      * *     Para inserir um usuário deve ser confirmada a não-existência
>      *         de outro registro com o mesmo nome de usuário.
>      * @return
>      */
>     public String salvar(){
>         //Verifica se a tela possui erros
>         if (hasFieldErrors() || hasErrors()){
>             return Action.INPUT;
>         }
>
>         try {
>             if (!getUsuFacade().isSenhaValid(currentUsu.getSenha(),
> senhaConf)){
>                 addActionError("As senhas informadas devem ser iguais");
>                 return Action.INPUT;
>             }
>             else
>                 if (!getUsuFacade().isChvValid(currentUsu.getChv())){
>                     addActionError("Já existe um usuário com este nome,
> favor informar um nome diferente");
>                     return Action.INPUT;
>             }
>             else {
>                 NvlAcso nvlAcso =
> getNvlAcsoFacade().recuperaPorId(idNvlAcso);
>                 getUsuFacade().incluir(currentUsu, nvlAcso);
>                 setIdUsu(currentUsu.getCd());
>             }
>
>         } catch (Exception e) {
>             addActionError(SgvdbaConstants.ERRO_DEFAULT + e.getMessage());
>             return Action.INPUT;
>         }
>
>         return Action.SUCCESS;
>     }
>
> UsuAction-salvar-validation.xml (VALIDATION)
> -------------------------------------------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator
1.0//EN"
> "http://www.opensymphony.com/xwork/xwork-validator-1.0.dtd";>
>     <validators>
>
>         <field name="currentUsu.chv">
>             <field-validator type="requiredstring">
>                 <message>Favor inserir um nome de usuário</message>
>             </field-validator>
>         </field>
>
>         <field name="currentUsu.email">
>             <field-validator type="requiredstring">
>                 <message>Favor inserir um e-mail</message>
>             </field-validator>
>             <field-validator type="email">
>                 <message>Favor informar um e-mail válido</message>
>             </field-validator>
>         </field>
>
>         <field name="currentUsu.senha">
>             <field-validator type="requiredstring">
>                 <message>Favor inserir uma senha</message>
>             </field-validator>
>             <field-validator type="stringlength">
>                 <param name="minLength">4</param>
>                 <param name="maxLength">12</param>
>                 <param name="trim">true</param>
>                 <message>A senha deve conter no mínimo ${minLength} e no
> máximo ${maxLength}</message>
>             </field-validator>
>         </field>
>
>     </validators>
>
>
> Hope this can help you.
> Sorry by text in portuguese on my code, but I guess it's gona be easy to
> understand.
>
> []'s
>
> 2008/4/23, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>> Hello y'all,
>>
>> i have quite an interesting problem again.
>> In my struts.xml i have defined a method to call for my action
>> (method="save")
>>
>> Every time my action class is called, the method validate() is executed.
>> The same action class used with struts.xml-parameter method="save" is also
>> executed as expected, but validate is never called.
>> I thought, i could exclude methods from validation, but how do i include
>> one ?
>>
>> this
>> <interceptor-ref name="validation">
>>   <param name="includeMethods">save</param>
>> </interceptor-ref>
>>
>> does not work.
>>
>> thanks in advance
>>
>>   Volker
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iD8DBQFID3Dax4KjH6Tk4MMRAloBAJ92MhmLRMSDvtKDfE8KBbcH60dr/gCfbYbE
w7bSzJSLamxDA+LPjNNpU2k=
=sy2F
-----END PGP SIGNATURE-----

Reply via email to