struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cliff" <cl...@reinfo.com.hk>
Subject Re: HOw to avoid validations for certain submit buttons on a single form?
Date Wed, 05 Jan 2005 01:46:04 GMT
Hi,

You may get the reference from the Cancel Button in CancelTag.

The Tag will set a parameter in the request to block the validation in the
servlet.


Good Luck
Cliff

----- Original Message ----- 
From: "Krishna Mohan Radhakrishnan" <KrishnaMohan_R@infosys.com>
To: "Struts Users Mailing List" <user@struts.apache.org>
Sent: Wednesday, January 05, 2005 12:27 AM
Subject: HOw to avoid validations for certain submit buttons on a single
form?


Hi all,



I have a jsp called Plan.jsp. The name of the ActionForm is
PlanActionForm.

There is a action class called PlanAction.java. From this
PlanAction.java it is forwarding to Plan.jsp.



In the Plan.jsp there are 2 buttons and one text field.

Text field name is txtboxTitle and the 2 buttons are "Add New Service
Level" and "Inactivate Plan". Both are buttons of type submit.



When I am clicking "Add New Service Level", the PlanActionForm is being
submitted to PlanAction.java. But when I am clicking the "Inactivate"
button the same form is submitted to InactivatePlanAction.java.







InactivatePlanAction.java is like this



public class InactivatePlanAction extends ValidationAction {



    public InactivatePlanAction() {

        super();

        super.setFormBean(new PlanActionForm());

        super.setFormName("PlanActionForm");

    }

    protected void doCustomValidation(ActionForm form, SessionState
state) {

      PlanActionForm planForm = (PlanActionForm) form;


      super.addError("Error happened");

    }

    protected ActionForward doExecute(ActionMapping mapping, ActionForm
form, SessionState state) {

        PlanActionForm planForm = (PlanActionForm) form;

        String forwardTo = "success";

        return mapping.findForward(forwardTo);

    }

}



The validator-rules.xml will look like this.

<form name="PlanActionForm">

                  <field property="txtboxTitle" depends="maxlength">

                  <msg name="maxlength" key="errors.offers.maxlength"/>

                  <arg1 name="maxlength" key="${var:maxlength}"
resource="false"/>

                  <var>

                        <var-name>maxlength</var-name>

                        <var-value>64</var-value>

                  </var>

                  </field>

</form>



Struts-config.xml will look like this



<form-bean

          name="PlanActionForm"

            type="actionform.PlanActionForm"/>



<action

            path=" /InactivatePlanAction"

                  type=" action.InactivatePlanAction"

            scope="request"

            name="PlanActionForm" >

                <forward name="success" path /Plan.jsp"/>

                <forward name="ValidationError" path="/Plan.jsp" />


            </action>





Here there is a text field validation for maximum length.

What I want is that when I am clicking the Inactivate button, it should
not do any form validations that is given in the validator-rules.xml. It
should directly go to the InactivatePlanAction.java and display the
error message "Error happened".



But when I am clicking the "Add New Service Level" button the form has
to be validated according to that given in the validator-rules.xml.



Now what is happening is when I am clicking the Inactivate button, it is
doing the form validations too.



Does any body have any idea how to do it?



I think one solution is to put Inactivate in another ActionForm.



But can I achieve the result in a single Actionform.



Regards,

Krishna Mohan



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


Mime
View raw message