You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Anjib Mulepati <an...@hotmail.com> on 2012/07/31 18:09:07 UTC

Form data lost [S 1.3.8]

Hi All,

I am using large form to input data. I have some validation code as well 
as I have condition where if something goes wrong in execution of action 
it will take the user back to the form.
My problem is when validation fail or form returned from action 
execution all my form data are lost. How can I have form retain its data 
even after fail?
I am using struts tag for form and session scope for form.

     <html:form styleId="createAgentForm" action="createAgent" 
focus="agentVersion">

         <label for="agentVersion" class="formLabel"><bean:message 
key="label.agentVersion" />*</label>
         <html:text property="agentVersion" size="10" 
styleId="agentVersion" tabindex="1" titleKey="title.agentVersion" 
value="" />
         <br />

        ........

         <html:submit styleClass="submitbutton" tabindex="11" 
value="Create Agent" title="Create Agent" />

     </html:form>


   <action path="/createAgent"
type="com.anjib.actions.agencyadmin.CreateAgentAction"
                 input="/showCreateAgent.do"
                 name="CreateAgentForm"
                 scope="session" >
             <forward name="createAgentForm" path="/showCreateAgent.do"/>
         </action>


<action path="/showCreateAgent"
type="com.anjib.actions.agencyadmin.ShowCreateAgentAction">
             <forward name="success" path="createAgentPage"/>
         </action>


public class CreateAgentForm extends org.apache.struts.action.ActionForm {
     ..............................

     public ActionErrors validate(ActionMapping mapping, 
HttpServletRequest request) {
         ActionErrors errors = new ActionErrors();
         if (getAgentName() == null || getAgentName().length() < 1) {
             errors.add("createAgent", new 
ActionMessage("error.agentName.required"));
         }
        .................................................
         return errors;
     }
}

Thanks,
Anjib

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


Re: Form data lost [S 1.3.8]

Posted by Anjib <an...@hotmail.com>.
  aren't default scope is session??
i am wondering if I am missing any other point other than scope.

On 7/31/2012 6:20 PM, Paul Benedict wrote:
> I think you're losing the data because you're unintentionally creating
> a new form. Make sure both actions refer to the form with the same
> scope.
>
> On Tue, Jul 31, 2012 at 11:09 AM, Anjib Mulepati<an...@hotmail.com>  wrote:
>> Hi All,
>>
>> I am using large form to input data. I have some validation code as well as
>> I have condition where if something goes wrong in execution of action it
>> will take the user back to the form.
>> My problem is when validation fail or form returned from action execution
>> all my form data are lost. How can I have form retain its data even after
>> fail?
>> I am using struts tag for form and session scope for form.
>>
>>      <html:form styleId="createAgentForm" action="createAgent"
>> focus="agentVersion">
>>
>>          <label for="agentVersion" class="formLabel"><bean:message
>> key="label.agentVersion" />*</label>
>>          <html:text property="agentVersion" size="10" styleId="agentVersion"
>> tabindex="1" titleKey="title.agentVersion" value="" />
>>          <br />
>>
>>         ........
>>
>>          <html:submit styleClass="submitbutton" tabindex="11" value="Create
>> Agent" title="Create Agent" />
>>
>>      </html:form>
>>
>>
>>    <action path="/createAgent"
>> type="com.anjib.actions.agencyadmin.CreateAgentAction"
>>                  input="/showCreateAgent.do"
>>                  name="CreateAgentForm"
>>                  scope="session">
>>              <forward name="createAgentForm" path="/showCreateAgent.do"/>
>>          </action>
>>
>>
>> <action path="/showCreateAgent"
>> type="com.anjib.actions.agencyadmin.ShowCreateAgentAction">
>>              <forward name="success" path="createAgentPage"/>
>>          </action>
>>
>>
>> public class CreateAgentForm extends org.apache.struts.action.ActionForm {
>>      ..............................
>>
>>      public ActionErrors validate(ActionMapping mapping, HttpServletRequest
>> request) {
>>          ActionErrors errors = new ActionErrors();
>>          if (getAgentName() == null || getAgentName().length()<  1) {
>>              errors.add("createAgent", new
>> ActionMessage("error.agentName.required"));
>>          }
>>         .................................................
>>          return errors;
>>      }
>> }
>>
>> Thanks,
>> Anjib
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>


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


Re: Form data lost [S 1.3.8]

Posted by Paul Benedict <pb...@apache.org>.
I think you're losing the data because you're unintentionally creating
a new form. Make sure both actions refer to the form with the same
scope.

On Tue, Jul 31, 2012 at 11:09 AM, Anjib Mulepati <an...@hotmail.com> wrote:
> Hi All,
>
> I am using large form to input data. I have some validation code as well as
> I have condition where if something goes wrong in execution of action it
> will take the user back to the form.
> My problem is when validation fail or form returned from action execution
> all my form data are lost. How can I have form retain its data even after
> fail?
> I am using struts tag for form and session scope for form.
>
>     <html:form styleId="createAgentForm" action="createAgent"
> focus="agentVersion">
>
>         <label for="agentVersion" class="formLabel"><bean:message
> key="label.agentVersion" />*</label>
>         <html:text property="agentVersion" size="10" styleId="agentVersion"
> tabindex="1" titleKey="title.agentVersion" value="" />
>         <br />
>
>        ........
>
>         <html:submit styleClass="submitbutton" tabindex="11" value="Create
> Agent" title="Create Agent" />
>
>     </html:form>
>
>
>   <action path="/createAgent"
> type="com.anjib.actions.agencyadmin.CreateAgentAction"
>                 input="/showCreateAgent.do"
>                 name="CreateAgentForm"
>                 scope="session" >
>             <forward name="createAgentForm" path="/showCreateAgent.do"/>
>         </action>
>
>
> <action path="/showCreateAgent"
> type="com.anjib.actions.agencyadmin.ShowCreateAgentAction">
>             <forward name="success" path="createAgentPage"/>
>         </action>
>
>
> public class CreateAgentForm extends org.apache.struts.action.ActionForm {
>     ..............................
>
>     public ActionErrors validate(ActionMapping mapping, HttpServletRequest
> request) {
>         ActionErrors errors = new ActionErrors();
>         if (getAgentName() == null || getAgentName().length() < 1) {
>             errors.add("createAgent", new
> ActionMessage("error.agentName.required"));
>         }
>        .................................................
>         return errors;
>     }
> }
>
> Thanks,
> Anjib
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

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


Re: Form data lost [S 1.3.8]

Posted by Anjib Mulepati <an...@hotmail.com>.
I mean when form data are invalid, user get the message on top of the 
form but all data in filed get lost. It shows blank form with error 
message. i want to show previously entered data so that user can correct 
only invalid field.

On 7/31/2012 3:09 PM, Martin Gainty wrote:
> could you define your intentions..?
>
> when form validation fails you want to save the data?
> what happens when form validation succeeds..do you invalidate the session?
>
> Martin
> ______________________________________________
> Verzicht und Vertraulichkeitanmerkung
>
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene 
> Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede 
> unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. 
> Diese Nachricht dient lediglich dem Austausch von Informationen und 
> entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten 
> Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den 
> Inhalt uebernehmen.
>
>
>
> > Date: Tue, 31 Jul 2012 12:09:07 -0400
> > From: anjibcs@hotmail.com
> > To: user@struts.apache.org
> > Subject: Form data lost [S 1.3.8]
> >
> > Hi All,
> >
> > I am using large form to input data. I have some validation code as 
> well
> > as I have condition where if something goes wrong in execution of 
> action
> > it will take the user back to the form.
> > My problem is when validation fail or form returned from action
> > execution all my form data are lost. How can I have form retain its 
> data
> > even after fail?
> > I am using struts tag for form and session scope for form.
> >
> > <html:form styleId="createAgentForm" action="createAgent"
> > focus="agentVersion">
> >
> > <label for="agentVersion" class="formLabel"><bean:message
> > key="label.agentVersion" />*</label>
> > <html:text property="agentVersion" size="10"
> > styleId="agentVersion" tabindex="1" titleKey="title.agentVersion"
> > value="" />
> > <br />
> >
> > ........
> >
> > <html:submit styleClass="submitbutton" tabindex="11"
> > value="Create Agent" title="Create Agent" />
> >
> > </html:form>
> >
> >
> > <action path="/createAgent"
> > type="com.anjib.actions.agencyadmin.CreateAgentAction"
> > input="/showCreateAgent.do"
> > name="CreateAgentForm"
> > scope="session" >
> > <forward name="createAgentForm" path="/showCreateAgent.do"/>
> > </action>
> >
> >
> > <action path="/showCreateAgent"
> > type="com.anjib.actions.agencyadmin.ShowCreateAgentAction">
> > <forward name="success" path="createAgentPage"/>
> > </action>
> >
> >
> > public class CreateAgentForm extends 
> org.apache.struts.action.ActionForm {
> > ..............................
> >
> > public ActionErrors validate(ActionMapping mapping,
> > HttpServletRequest request) {
> > ActionErrors errors = new ActionErrors();
> > if (getAgentName() == null || getAgentName().length() < 1) {
> > errors.add("createAgent", new
> > ActionMessage("error.agentName.required"));
> > }
> > .................................................
> > return errors;
> > }
> > }
> >
> > Thanks,
> > Anjib
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >