struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fredrik Boström <fredrik.bost...@helsinki.fi>
Subject Re: Losing form values after validating
Date Wed, 09 Mar 2005 17:46:23 GMT
Just for completeness, I'll post some more relevant information about 
the application.


newForm.jsp (partly)
--------------------
<logic:equal parameter="action" value="thread">
<!-- Create new thread -->
   <h1>New Thread</h1>

   <html:form action="/CreateThread">
     <html-el:hidden property="author" value="${user.nickname}"/>
     <html-el:hidden property="categoryId" value="${param.category}"/>
     Topic: <html:text property="topic" value="" size="20" 
maxlength="40" /><br/>
     Message: <html:textarea property="message" value="" cols="60" 
rows="10" /><br/>
     <html:submit value="Create" />
   </html:form>
</logic:equal>


struts-config.xml (partly)
-------------------------
     <!-- Multi purpose form for creating stuff -->
     <form-bean   name="createForm"
 
type="org.apache.struts.validator.DynaValidatorActionForm">
       <form-property  name="author"
                       type="java.lang.String" />
       <form-property  name="categoryId"
                       type="java.lang.Integer" />
       <form-property  name="threadId"
                       type="java.lang.Integer" />
       <form-property  name="topic"
                       type="java.lang.String" />
       <form-property  name="message"
                       type="java.lang.String" />
       <form-property  name="replyto"
                       type="java.lang.Integer" />
       <form-property  name="categoryName"
                       type="java.lang.String" />
       <form-property  name="categoryDescription"
                       type="java.lang.String" />
     </form-bean>
   </form-beans>

<!-- Display new user|category|thread|message form -->
<action    path="/NewForm"
            forward=".view.newForm" />

<!-- Process new Category -->
<action    path="/CreateCategory"
            type="manegen.forum.CreateCategoryAction"
            name="createForm"
            scope="session"
            input="input">
   <forward name="input" path="/NewForm.do?action=category" />
   <forward name="success" path="/Home.do"/>
</action>

tiles-defs.xml (partly)
-----------------------
<tiles-definitions>

   <!-- main layout -->
   <definition name=".layout.main" path="/layout/layout.jsp">
     <put name="title" value="Manegen Forum"/>
     <put name="body" value=""/>
   </definition>

   <!-- views = extensions to the main layout -->
   <definition name=".view.newForm" extends=".layout.main">
     <put name="body" value="/newForm.jsp" />
   </definition>

</tiles-definitions>



This is really bothering me, so any ideas would help.


Best regards,
Fredrik




Fredrik Boström wrote:
> Hi all.
> 
> I'm working on a small message-forum project and have stumbled upon many 
> problems along the way, most of which I've been able to more or less 
> solve. To the most recent problem, though, I haven't found any solution 
> despite lots of googling.
> 
> I'm using a DynaValidatorActionForm to validate input from a form 
> (actually several forms). The form is one of three forms in the same 
> jsp-page. The form to be used is determined by a logic-tag that looks 
> for an action-parameter and ckecks its value. If the value is "thread" 
> the thread-form is displayed. So the URI to display the thread-form 
> would be /NewForm.do?action=thread.
> 
> I also have to pass another parameter to the thread-form, namely to 
> which category the thread belongs. This parameter's value is inserted 
> into a hidden field in the form. So, the final URI would be 
> /NewForm.do?action=thread&category=1.
> 
> Other fields in the form are
>  - a hidden username field, value from user session bean
>  - thread topic (input type="text")
>  - message (input type="textarea")
> 
> So, the populated form (but not yet filled in by the user) would look 
> like this:
> 
> <form name="createForm" method="post" action="/forum_dev/CreateThread.do">
>  <input type="hidden" name="author" value="Joe"> <-- from bean
>  <input type="hidden" name="categoryId" value="1"> <-- from request 
> parameter
>  Topic: <input type="text" name="topic" maxlength="40" size="20" 
> value=""><br/>
>  Message: <textarea name="message" cols="60" rows="10"></textarea><br/>
>  <input type="submit" value="Create">
> </form>
> 
> When submitting the form, I want it to be validated and if the 
> validation fails, the user is returned to the same page with 
> error-messages displayed. This is currently done by using the following 
> action (which is the action the form submits to):
> 
>       <action    path="/CreateThread"
>                  type="manegen.forum.CreateThreadAction"
>                  name="createForm"
>                  scope="request"
>                  input="input">
>         <forward name="input"   path="/NewForm.do?action=thread" />
>         <forward name="success" path="/ShowMessages.do" />
>         <forward name="failure" path="/ShowThreads.do" />
>       </action>
> 
> Validation works fine (when it's failing :), the validator returns to 
> the right page with the right form visible, messages display as they 
> should and everythings seems to be a-ok.
> 
> But, the problem is that when the validation fails, all form values 
> (except "author" which comes from the session bean) are lost. This is 
> surely due to the fact that control passes through another action before 
> getting back to the form page. The values somehow get lost on the way.
> 
> Is there any way to keep the form data through this process? I've tried 
> putting scope="session" in the /CreateThread action but with no success. 
> Another alternative would be to maintain a session bean which contains 
> fields for the current category, thread etc, but that bean would demand 
> lots of updating all the time. Any simple solution to this problem?
> 
> Grateful for any suggestions.
> 
> Regards, Fredrik
> 
> ---------------------------------------------------------------------
> 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


Mime
View raw message