Resetting ActionForm

Hi all,
First of all i had lot of trouble searching for this topic (if anyone as posted this topic already or not?).
Anyways i have two forms "emp.jsp" and "empconform.jsp", what is happening is in "empconform.jsp" you can save data to Database or if you find something wrong you can go back to previous page i.e. "emp.jsp" with all the fields populated. This i am doing using struts so that when i visit the "emp.jsp" after "empconfirm.jsp" struts automatically populates the fields (Great!).
But the trouble is now i can not reset my form , initially ie. when first time you visit "emp.jsp" you can very well reset this form using javascript but once Actionform related to this page gets populated then you can not reset it .
I don't know how to reset the action form.Can anybody clear my idea on how the above things should be.It'll be great help, i am wondering for this from long time.
thanx in advance.
Neelesh

I usually do it differntly ways:
1. Scope the action as request than session
2. Write a method to perform the Reset operation.

Similar Messages

  • ActionForm keeps resetting when i click submit

    package com.ubs.onboarding.formbeans;
    import javax.servlet.http.HttpServletRequest;
    import org.apache.struts.action.ActionError;
    import org.apache.struts.action.ActionErrors;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;
    import...
    import...
    import...
    public class FormEmployeeInfo extends FormNewHire {
         private boolean action_reset = false;
         private String uuname;      private String ssn; private String nme_pre;
         private String fn;     private String mn; private String ln;
         private String nme_suf;     private String pref_bs_ln; private String pref_bs_fn;
         private String dob;      private String frmr_ln;    private String h_street;
         private String h_city;     private String h_county;     private String h_zip;
         private String h_state;     private String h_phone;     private String prsnl_cell;
         private String w_phone;     private String prsnl_pager;
         public String getUuname()             {     return uuname;          }
         public String getSsn()             {      return ssn;          }
         public String getNme_pre()        {     return nme_pre;     }
         public String getMn()                    {     return mn;               }
         public String getFn()                  {     return fn;               }
         public String getLn()                  {     return ln;               }
         public String getNme_suf()        {     return nme_suf;     }
         public String getPref_bs_ln()      {     return pref_bs_ln;     }
         public String getPref_bs_fn()      {     return pref_bs_fn;     }
         public String getDob()                {     return dob;          }
         public String getFrmr_ln()           {     return frmr_ln;     }
         public String getH_street()      {     return h_street;     }
         public String getH_city()           {     return h_city;          }
         public String getH_zip()           {     return h_zip;          }
         public String getH_county()      {     return h_county;     }
         public String getH_state()       {     return h_state;     }
         public String getH_phone()       {     return h_phone;     }
         public String getPrsnl_cell()      {     return prsnl_cell;     }
         public String getW_phone()           {     return w_phone;     }
         public String getPrsnl_pager()  {     return prsnl_pager;}
         public String getTimeStamp ()  {return timeStamp; }
         public long getId()               {return id; }     
         //public void setTimeStamp(String ts) {timeStamp = ts; }
         //public void setId(long id)           {this.id = id; }
         public void setUuname(String u)      {uuname = u;     }
         public void setSsn(String s)         {ssn = s;          }
         public void setNme_pre(String n)      {nme_pre = n;     }
         public void setFn(String f)           {fn = f;          }
         public void setMn(String m)           {mn = m;          }
         public void setLn(String l)               {ln = l;          }
         public void setNme_suf(String n)      {nme_suf = n;          }
         public void setPref_bs_ln(String p) {     pref_bs_ln = p;     }
         public void setPref_bs_fn(String p) {     pref_bs_fn = p;     }
         public void setDob(String d)          {     dob = d;          }
         public void setFrmr_ln(String f)      {     frmr_ln = f;     }
         public void setH_street(String h)   {     h_street = h;     }
         public void setH_city(String h)      {     h_city = h;          }
         public void setH_county(String h)   {     h_county = h;     }
         public void setH_zip(String h)      {     h_zip = h;          }
         public void setH_state(String h)      {     h_state = h;     }
         public void setH_phone(String h)      {     h_phone = h;     }
         public void setPrsnl_cell(String p) {     prsnl_cell = p;     }
         public void setW_phone(String w)      {     w_phone = w;     }
         public void setPrsnl_pager(String p) {prsnl_pager = p; }
         public FormEmployeeInfo() {
              super();
         private void resetFields() {
              id = -1;
              timeStamp = null;
              uuname = null;
              ssn = null;
              nme_pre = null;
              fn = null;
              mn = null;
              ln = null;
              nme_suf = null;
              pref_bs_ln = null;
              pref_bs_fn = null;
              dob = null;
              frmr_ln = null;
              h_street = null;
              h_city = null;
              h_county = null;
              h_zip = null;
              h_state = null;
              h_phone = null;
              prsnl_cell = null;
              w_phone = null;
              prsnl_pager = null;
         public void clearData() {
              action_reset = true;
              resetFields();
              action_reset = false;
         public void reset(ActionMapping mapping, HttpServletRequest request) {
              resetFields();
              // Reset values are provided as samples only. Change as appropriate.
              ldebug("\n A form reset has occurred !!!");
         public ActionErrors validate(
              ActionMapping mapping,
              HttpServletRequest request) {
              ActionErrors errors = new ActionErrors();
              if (action_reset) return errors;
              if (ssn.trim().length() != 9) {
                   errors.add("ssn", new ActionError("InvalidSocialSecurityNumber"));
                   ldebug("Invalid Soc Sec: "+ ssn);
              if (dob.trim().equalsIgnoreCase(""))
                   errors.add("dob", new ActionError("InvalidHireDate"));
              if (fn.trim().equalsIgnoreCase(""))
                   errors.add("First Name", new ActionError("RequiredField","First Name"));
              if (ln.trim().equalsIgnoreCase(""))
                   errors.add("Last Name", new ActionError("RequiredField","Last Name"));
              if (uuname.trim().equalsIgnoreCase(""))
                   errors.add("UU Name ", new ActionError("RequiredField","UU Name"));
              // if ((field == null) || (field.length() == 0)) {
              //   errors.add("field", new ActionError("error.field.required"));
              return errors;
    }

    Without seeing the HTML and the struts-config file, it's hard to diagnose so here is what is supposed to happen. Could you post the relevant info?
    1. I'm not sure exactly what you mean by the "reset button image". If it is a true reset function, then it should impact the browser only. If it generates a form submit, then it will call the ActionForm.reset() method like all form submits.
    2. The logic path for an ActionForm is reset(), populate, validate(). The validate() method is only called if specified in struts-config (aka struts-default). If there are errors at that point, then the "input" forward in struts-config is followed - does that specify the appropriate JSP? If no errors, then the Action execute() method is invoked.

  • How to reset values in a Data Form Bean?

    I have created an ADF application that has a search facility in it. The architecture is as follows:
    DataPage (search.jsp) --> DataAction (validateSearch) -->DataAction (refreshCollection) --> DataPage (results.jsp)
    I have successfully created a data form bean to hold the data that is submitted in the search and bind it to the refresh method of the collection. I have also successfully overridden the validate method, which catches and throws and displays appropriate ActionErrors on the search.jsp page.
    I have added a link back to the search.jsp page from the results.jsp page (as a user may wish to perform another search), the ActionErrors are resetting ok but I have not managed to work out how to reset the values of the actual data form bean.
    I have tried several different ways of overriding the reset method within the data form bean but so far have been unsuccessful - I would appreciate any assistance with this matter.
    Shown here is a basic example of a form bean that I have been trying different things out with - I can not get the reset method to even be called - please help!
    package uk.dmf.eg02;
    import javax.servlet.http.HttpServletRequest;
    import org.apache.struts.action.ActionError;
    import org.apache.struts.action.ActionErrors;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;
    public class searchForm extends ActionForm
    String search;
    public setupForm()
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
    ActionErrors errors = new ActionErrors();
    if (search.trim().length()==0)
    errors.add("search", new ActionError("error.search"));
    return errors;
    public void reset(ActionMapping mapping, HttpServletRequest request)
    System.err.println("EXECUTING RESET METHOD");
    this.search = "";
    public void setSearch(String search)
    this.search = search;
    public String getSearch()
    return search;

    If you run in request scope the reset method is called, however in session scope is't only called once (or never?). See documentation of method reset():
    public void reset(ActionMapping mapping,
    javax.servlet.http.HttpServletRequest request)
    Reset bean properties to their default state, as needed. This method is called before the properties are repopulated by the controller.
    The default implementation does nothing. In practice, the only properties that need to be reset are those which represent checkboxes on a session-scoped form. Otherwise, properties can be given initial values where the field is declared.
    If the form is stored in session-scope so that values can be collected over multiple requests (a "wizard"), you must be very careful of which properties, if any, are reset. As mentioned, session-scope checkboxes must be reset to false for any page where this property is set. This is because the client does not submit a checkbox value when it is clear (false). If a session-scoped checkbox is not proactively reset, it can never be set to false.
    This method is not the appropriate place to initialize form value for an "update" type page (this should be done in a setup Action). You mainly need to worry about setting checkbox values to false; most of the time you can leave this method unimplemented.

  • Using Validate Method of ActionForm to validate JSP

    Hi...
    Am working on a struts application in which i have a struts jsp page which will contain a table of records that am populating while loading the page itself, each record of the table will have a check box associated with it.
    my requirement is that, i must select atleast one checkbox from the list of records before going for further processing from the page ie. i must validate whether the the user had selected any one of the check boxes. i am not usings struts validation plugin for this, instead am going for overrideing the validate method of ActionForm in my form bean.
    Now comes my problem:
    When i tried to validate the page without selecting any of the check boxes,the validate method is being called and its checking the values and returning the error message to my jsp page, but by the time the msg comes back to the jsp page the page is getting refreshed and all the previous list of records i had displayed in the page is lost giving me an error msg on jsp that "collection not found". The application scope is set to request and not to session. So i tried with setting the scope to session (which was not permissible by my requirements, still just for testing) but still am geting the same error
    i am stuck up with this problem for a long time and i couldnt find out any one who could solve it, and i have to use the Validate method of Action Form
    Please any one can explain whats the problem and what should i do
    Thanks in advance
    Rens

    ok, i'm going to try and make this short and sweet. let me know if you run into problems.
    first off, you may need to add apache commons-collections to your project.
    #1
    you will need to make a new bean class to represent your 'line' object. so if it was a Person we'd make a Person class with a String name, int age... blah blah blah.
    #2
    in your ActionForm class, add a
    java.util.List personList;and make a normal setter and getter for it
    #3
    this is the only tricky part, make (or add this to) your reset( ) function in your ActionForm...
    public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
         personList = ListUtils.lazyList(new java.util.ArrayList(), new Factory() {
              public Object create() { return new Person(); }
    }but replace the 'new Person()' part with whatever the bean class you made in Step 1 is
    #4
    now, in your Action class build the list of objects from the database, and set it into your form.
    #5
    in your .jsp code you will need to use the nested tags like so
    <nested:iterate id="personLine" property="personList">
              <TR>
                   <td><nested:write property="name"/></td>
                   <nested:hidden property="age"/>
              </TR>
    </nested:iterate>
    #6
    then back in your validate code or in your Action class you can access the list by calling yourForm.getPersonList() and validating it. if you find a problem and return with an error all the values will remain without having to talk to the database again.
    hope that helps.

  • Reset function in form bean

    Hi, i m new to jsp . i m a bit confused bout the functionality of reset function in form bean class that extends ActionForm. Does this function resets the specified fields on client side or it requires a reset function in the action class too , to reset fields on server side

    Sorry to be a bugger about this, but isn't there a Struts forum somewhere these Struts specific questions could go? I'm tired of clicking on these stupid things to find it's not even a JSP question.
    Sorry, I feel better now.

  • Struts - initialize ActionForm

    Hey,
    What I need to do:
    I need to implement a search form, which gives the user the ability to put in some search criteria. These search criteria include 3 comboboxes (html:select). These comboboxes should be populated with database values.
    I've created an ActionForm object to store the user's search criteria. I suppose that I need the same object to populate my comboboxes. I found that I could populate these dynamically, using the following construction:
    <html:form action="search.do>
    <html:select property="artGroup">
    <html:options property="artGroups" labelProperty="artGroups"/>
    </html:select><br>
    <html:submit/>
    <html:reset/>
    </html:form>
    The property artGroups is mapped to an ArrayList object of the ActionForm object.
    To query the correct values (from the database) for populating the comboboxes I need a parameter that is passed by as a request parameter.
    Now, my question is: how can I pass this request parameter to my ActionForm object, before any getters are executed to build the HTML form object.
    Thank you very much for your help

    The simplest solutions might be to access that parameter from inside your ActionForm constructor
    e.g.
    public class MyForm extends ActionForm{
         MyForm(){
             super();
             // here goes a call to get that parameter
    }Or you can subclass RequestProcessor, and override processActionForm(request, response, mapping). Do something like
    protected ActionForm processActionForm (HttpServletRequest req,
                                            HttpServletResponse res,
                                            ActionMapping mapping){
           ActionForm form = super.processActionForm(req, res, mapping);
           // ensure that "form" is actually instance of MyForm
           // if it is not, simply return form
           // if it is, get the parameter you need for your form and again
           // return it.
    }

  • When the ActionForm class will be instantiate in struts

    Hi all,
    I am new to this group.
    I've one doubt in struts.If any one know please help me.
    when the ActionForm class will be instantiate in struts ?
    Thanks
    Srilue

    Hi harsha,
    here is my emp.jsp code
    <%@ page language="java"%>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
    <html>
         <head>
              <title>JSP for empform form</title>
         </head>
         <body>
              <html:form action="/emp">
                   edept : <html:text property="edept"/><html:errors property="edept"/><br/>
                   eid : <html:text property="eid"/><html:errors property="eid"/><br/>
                   ename : <html:text property="ename"/><html:errors property="ename"/><br/>
                   <html:submit/><html:cancel/>
              </html:form>
         </body>
    </html>in struts-config.xml code for this empbean is
    <form-beans >
    <form-bean name="empform" type="Emp.EmpForm" />
       </form-beans>
    <action-mappings >
          validate="false" />
          <action
             attribute="empform"
             input="emp.jsp"
             name="empform"
             path="/emp"
             scope="request"
             type="Emp.EmpAction"
             validate="false" />
       </action-mappings>and code for EmpForm.java is
    package Emp;
    import javax.servlet.http.HttpServletRequest;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;
    public class EmpForm extends ActionForm {
         private Integer edept;
         private String ename;
         private Integer eid;
         public void reset(ActionMapping mapping, HttpServletRequest request) {
              System.out.println("in emp reset");
         public Integer getEdept() {
              return edept;
         public void setEdept(Integer edept) {
              this.edept = edept;
         public String getEname() {
              return ename;
         public void setEname(String ename) {
              this.ename = ename;
         public Integer getEid() {
              return eid;
         public void setEid(Integer eid) {
              this.eid = eid;
    }and the code for EmpAction.java is
    package Emp;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    public class EmpAction extends Action {
         public ActionForward execute(
              ActionMapping mapping,
              ActionForm form,
              HttpServletRequest request,
              HttpServletResponse response) {
              EmpForm empform = (EmpForm) form;
              throw new UnsupportedOperationException(
                   "Generated method 'execute(...)' not implemented.");
    }this is my total application.
    Here after starting the tomcat server when we click onto the emp.jsp,
    automatically the statement will be displayed , i had written in the System.out.println() in reset() method.
    Thanks
    Srilue

  • Populate jsp with ActionForm

    Hi!
    I have the following code that works:
    MyForm.java:
    public class MyForm extends ActionForm{
    public void reset (ActionMapping mapping, HttpServletRequest request){
      ArrayList testData = loadTestData(request);
      request.setAttribute("filInfoArray", testData);
    <other methods....>
    }MyJspFile.jsp:
    <c:forEach items="${filInfoArray}" var="name">
      <c:out value="${name.filId}" />
    </c:forEach>The Apache Struts API says that the reset()-method is not the appropriate place to initialize form value. So I was wondering if it is possible to pass on the ArrayList "filInfoArray" to the jsp without using the "setAttribute()" method? I have tried using a "getFilInfoArray()" method, but it is never invoked. Can I somehow accomplish my goal by using the ActionForm constructor? Any comments will be greatly appreciated. Thank you.
    Message was edited by:
    odorf

    Thanks for replying, but I am not quite sure what you are suggesting here. I want the data to be loaded the first time my jsp file is requested (a GET request, not a POST). I do not need to reset the form at any time, but the reset-method was the only way I could get hold of the HttpServletRequest variable in order to invoke the "setAttribute" method.
    If I create my own "resetVals()" method, should it have the parameters "ActionMapping" and "HttpServletRequest"? Could you elaborate more on your suggestion? Thanks

  • Struts (ActionForm beans)

    Does anyone have any information on the
    public void reset(ActionMapping, HttpServletRequest)
    method that ActionForm classes have.
    To be more specific at what points will the Struts framework call this method and why?
    Basically I have set the ActionForm with a scope of session and implemented the reset method to reset all my form variables.
    Yet every time the associated Action class is called the data is reset.
    I assumed this would only happen if I had set the scope as request.
    Should this be happening or should I not be implementing the reset method in the ActionForm bean?

    I checked out the source code and the main ActionServlet calls the ActionForm reset method on each request. I'm not sure what you mean by "set the ActionForm with a scope of session", but ActionServlet does not check anything, it just calls reset() as part of processPopulate().
    I think the idea is that the ActionForm reflects whatever is coming in from the request and a bean would perform persistence. If you are using the ActionForm to save across requests, you may need special logic in reset() to determine which elements to reset and when.
    Hope this helps. By the way, if you are doing a lot of Struts work, I recommend downloading the source code for research purposes and for customizing.

  • Error while resetting a cleared document

    Hi everyone,
    I am getting an error while resetting a cleared invoicing document 'Document xxxxxxxxxxx with origin R4 can not be reversed'. Please guide me how can we reset the clearing of this document.
    Thanks and Regards

    Hi,
    You need to reset all clearing for the corresponding FICA document for the print document.
    Reset the clearing for the document no. mentioned in the output for EA13 execution.
    You need to reset all the clearing for the document, before reversing the same.
    To get all the clearing document, go to DFKKOP table, enter the FICA document no. (for the print document on FPL9). Get all AUGBL documents,
    Alternatively, you can go on to FPL9 screen, double click on the consumption document, in the basic data you will see the clearing date (if it is cleared), expand the view their (click on + sign), you will se the clearing document no,
    Pass the above clearing document no, to FP07, and once all the clearing is reset for the invoice, you can reverse the corresponding invoice through EA13.
    Regards,
    Rajesh Popat

  • Global data getting reset when running under IIS?

    We have a scenario using IIS with an ASP.NET web service written in VB.NET. When a call to the web service is made, the web service calls a native dll (written in C, compiled using VS2010) using platform invoke, which in turn calls into our product API:
    VB.NET web service -> native library (p/invoke) -> native API ....
    Web service requests are successfully completed and the system runs without problem for hours. A trace of the native API shows it is being called by multiple processes and multiple threads within those processes.
    The main native API dll contains a static global variable used to detect whether it is the first time it has been called and run initialization logic if it is. This dll is itself linked to a second dll that contains a global variable used to detect if it is
    the first time it has been called.
    After some hours the trace shows that the native API is invoked by an existing process but that the initialization logic is being exercised again, even though the global variable was set to indicate not first time and is never reset.  One theory was that
    the first process has ended and a new process has started almost instantaneously using the same process ID. However this is not the case as existing thread IDs from the same process are seen to write to the trace again after the first time logic has executed
    for the second time, indicating the process has not restarted. The problem occurs regularly.
    It is as though the process's global data has been initialized again and malloc'ed memory freed while the processing is still running. Is there any way this is possible when running under IIS?
    There is an internal thread which waits on a blocking read of a named pipe (via ReadFile), and when the problem occurs, the ReadFile call ends with ERROR_NO_ACCESS, which appears to indicate the malloc'ed buffer is no longer valid, again implying something
    has happened to the memory allocated to the process.

    Suggestting you asking it on:
    http://forums.iis.net/

  • I've just found that three movies I've bought from iTunes on on my iPad are not showing up on Apple TV or anywhere other than that iPad.  What's up with that and will I lose these films if I reset this iPad?

    I've just found that three movies I've bought from iTunes on on my iPad are not showing up on Apple TV or anywhere other than that iPad.  What's up with that and will I lose these films if I reset this iPad?

    Thanks.  The reason this has become an issue is that I recently bought a new Macbook Air that the iPad is not synced to.  The one is was synced to was stolen.  If I want to sync this iPad to the new Air, won't it be wiped before I'm able to copy these films or am I wrong about that?

  • HT4623 My account wont let me download apps ive reseted two times and it says i havent enterted right and i dont know what else to do??

    My apps wont download its really bothering me

    Define "won't let me."
    What type of reset did you do?

  • Hi, I am trying to update an iPhone 4 from iOS 4.3.3 to iOS 7.0.4, and every time I try to update it comes up with an error message saying that there was a problem because the network connection was reset. Is there any way I can get past this and update?

    The full message said:
    There was a problem downloading the software for the iPhone "Judy's iPhone 4". The network connection was reset.
    Make sure your network settings are correct and your network connection is active, or try again later.
    I am trying to update the iPhone for my grandmother, Judy, as I am leaving for Paris on Wednesday night and we want to have Facetime installed on her iPhone before then, so we can stay in contact with each other. It is the simplest way for this to happen but the program simply will not allow me to update her iPhone.
    Is there any way to get past this error and update her iPhone? Any help will be greatly appreciated.

    Dear Jody..jone5
    Good for you that can't update your iphone because I did it and my iphone dosen't work for example I can't download any app like Wecaht or Twitter..
    Goodluck
    Atousa

  • Reset Cleared Documents and Vendor Open Items Report FBL1N

    Hi all,
    I have following scenario:
    - In last month, we had 2 documents (invoice and payment) cleared against each other. We created open items report as well as open items correspondence sent to Vendor. Obviously, the docs were not included in report.
    - In this month, we have reset and reverse clearing document of the documents. We create report again with the open key date as in last month. It should not include the 2 docs but it did with whichever key date we chose.
    Is there any setting that open item report doesn't include cleared item at the key date when we run report for previous month?
    Thanks and Regards,
    Dau

    Hi Dau,
    If i understand you correctly then you posted and paid invoice in Jan 2012 and generated the open line item report for Jan which correctly did not include this cleared invoice.
    Now in Feb 2012 you reset and reversed this payment document.
    The issue is when you execute the report FBL1N again then you get the open line item for this invoice correct. Please confirm what is the open item key date that you are using here for generating this report
    If you keep it 31.01.2012 then definetly this invoice should not appear in the report but if you keep that 29.12.2012 then this line item would for sure appear.
    The importance of key date is to limit the report to certain date. The system selects all items posted up to and including the specified key date and open for this period.
    so I think your issue is with the key date.
    Hope this helps you.
    Regards,
    Prasad

Maybe you are looking for