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]
>
>

Reply via email to