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 

Reply via email to