Hi, 

Do you know of the reason why in my case the form data in Struts Form class does not 
get passed to the Action class? When the user clicks on a Submit button, I need to set 
the value in the action and view hidden fields, and submit that HTML form to a Struts 
Action class. But for some reasons, when I retrieve the data from the Struts Form, it 
returned null. 

Below is my code and Struts config file for that form. 

Thanks!
Tuan

---- struts-config.xml ---------

    <!-- Process workflow status tab -->
    <action path="/approveSubmit"
            type="com.phs.ezhr.presentation.action.ApproveSubmitAction"
            validate="false"
            input="/MainMenu.jsp"
            name="approveSubmitForm"
            scope="request" >
            <set-property property="loginRequired" value="true" />
            <forward name="success" path="/MainMenu.jsp" />
            <forward name="failure" path="/login.do" />
    </action>

---- Form class -----

public final class ApproveSubmitForm extends ActionForm
                                     implements IConstants {
  /**
   * User's selected view
   */
  private String view;
  /**
   * submit action
   */
  private String action;

  public void setView( String aView ) {
    this.view = aView;
  }

  public String getView() {
    return this.view;
  }

  public void setAction( String anAction ) {
    this.action = anAction;
  }

  public String getAction() {
    return this.action;
  }

  public void reset( ActionMapping mapping,
                     HttpServletRequest request ) {
    action = null;
    view = null;
  }

  public ActionErrors validate( ActionMapping mapping,
                                HttpServletRequest request ) {
    ActionErrors errors = new ActionErrors();

    return errors;
  }
}

----- Action class  -----------

public final class ApproveSubmitAction extends Action
                                       implements IConstants {
  public ActionForward perform( ActionMapping mapping,
                                ActionForm form,
                                    HttpServletRequest request,
                                HttpServletResponse response )
    throws IOException, ServletException {

    ///
    // ... other code logic
    //

    // get the form handler
    ApproveSubmitForm approveSubmitForm = (ApproveSubmitForm)form;

    // PROBLEM: both of these variables returned null
    String selectedView = approveSubmitForm.getView();
    String selectedAction = approveSubmitForm.getAction();

    // Forward to the appropriate View
    return ( mapping.findForward( target ) );
  }
}



----- JSP (View) ------


<SCRIPT LANGUAGE="JavaScript">
  function saveApproveReject( theForm ) {
     theForm.view.value = theForm.view.options[theForm.view.selectedIndex].value;
     theForm.action.value = 'submit';
     theForm.submit();
  }
</SCRIPT>

<html:form action="/approveSubmit"
           name="approveSubmitForm"
           type="com.phs.ezhr.presentation.form.ApproveSubmitForm"
           method="POST"
           target="_parent">
<input type="hidden" name="action" value="">
<input type="hidden" name="view" value="">

</html:form>

<<winmail.dat>>

--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>

Reply via email to