You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Aaron Longwell <li...@newmedialogic.com> on 2003/07/14 17:00:53 UTC

Please Help: ActionForm Re-Population

I am on the last leg of a web application, and I've run into problems 
adding validation to the mix.

I have an "edit" Action that retrieves a database record, a list of 
drop-down options, and then populates the "editor" ActionForm. Works 
great, and I LOVE STRUTS!

Now I've implemented validation (through the Validator Framework, but I 
think my problem is with validate() in general).

After the user clicks submit, their post is sent to my "update" action.

If they do not break any validation rules, all goes well. The problem 
occurs when a validation rule is broken.... They are returned to the 
form... but the drop-downs (which are populated in the "edit" Action) 
are empty. I have set breakpoints in the code... and I see that the page 
neither my "edit" Action code (the part where the drop-down data is 
retrieved), nor my "update" Action code is actually running.

Question.... between pressing submit and returning the "edit" JSP with a 
populated ActionErrors object. Where is "validate()" actually called? 
Where can I insert code to populate a drop-down with a set of values so 
that it will appear both when the form is presented the first time, and 
after a validation error?

Thank you for your help,
Aaron Longwell


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


Re: Please Help: ActionForm Re-Population

Posted by Aaron Longwell <li...@newmedialogic.com>.
Dirk,

Thank you, thank you thank you thank you.

It was almost too easy. I just changed the input attribute to point to 
my action instead of my JSP and the problem is solved.

Thanks again,
Aaron

Dirk Markert wrote:

>Hello Aaron,
>
>  
>
>***************************************************************
>
>AL> I am on the last leg of a web application, and I've run into problems 
>AL> adding validation to the mix.
>
>AL> I have an "edit" Action that retrieves a database record, a list of 
>AL> drop-down options, and then populates the "editor" ActionForm. Works 
>AL> great, and I LOVE STRUTS!
>
>AL> Now I've implemented validation (through the Validator Framework, but I 
>AL> think my problem is with validate() in general).
>
>AL> After the user clicks submit, their post is sent to my "update" action.
>
>AL> If they do not break any validation rules, all goes well. The problem 
>AL> occurs when a validation rule is broken.... They are returned to the 
>AL> form... but the drop-downs (which are populated in the "edit" Action) 
>AL> are empty. I have set breakpoints in the code... and I see that the page 
>AL> neither my "edit" Action code (the part where the drop-down data is 
>AL> retrieved), nor my "update" Action code is actually running.
>
>AL> Question.... between pressing submit and returning the "edit" JSP with a 
>AL> populated ActionErrors object. Where is "validate()" actually called?
>
>After the RequestProcessor has populated your action form, validate is
>called. This happens before your action is called.
>
>AL> Where can I insert code to populate a drop-down with a set of values so 
>AL> that it will appear both when the form is presented the first time, and 
>AL> after a validation error?
>
>You have at least 2 choices.
>
>1) You can put your drop-down values into session scope.
>
>2) You can set the input attribute of your action mapping to your edit
>action.
>
>AL> Thank you for your help,
>AL> Aaron Longwell
>
>
>AL> ---------------------------------------------------------------------
>AL> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>AL> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>Regards,
>Dirk
>
>+------- Quality leads ---------------------------------------+
>| Dirk Markert                     dirk.markert@dr-markert.de |
>| Dr. Markert Softwaretechnik AG                              |
>| Joseph-von-Fraunhofer-Str. 20                               |
>| 44227 Dortmund                                              |
>+---------------------------------->>>>>>> to success! <<<<<<-+ 
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
>  
>


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


Re: Please Help: ActionForm Re-Population

Posted by Aaron Longwell <li...@newmedialogic.com>.
Oops, spoke too soon.

You discussed 2 options:

1) All drop-down list data goes into session
2) "input" attribute for the update event goes back to "edit" Action 
instead of "edit" JSP

I went with #2 and that brings up a new issue. Doing that causes all of 
the current values for the fields to be lost (i.e. the user inputs a bad 
number format in a field.... they click submit and receive the JSP with 
a list of errors at the top) Because the process went through the "edit" 
action again, the Action re-queried the database and updated the 
ActionForm with database values, overwriting all the user's values 
(including ones that were correctly edited and contained no errors).

To avoid this I have to insert code in the "edit" Action to check for a 
populated ActionForm before querying the database. This feels a little 
messy.

Of course I could use the session solution (#1), but I like to avoid 
using sessions unless absolutely necessary. In addition, these drop 
downs could have 100's of items in them, I'd like to keep big chunks of 
data like that in the request.

So the alternative, I guess, is to have another action that NEVER 
queries the database, but just prepares a blank form. I actually already 
have one of these... it's my "create" action.

This appears to be the best practice in this situation.... anyone else 
have any feedback?

Thanks again,
Aaron


Dirk Markert wrote:

>Hello Aaron,
>
>  
>
>***************************************************************
>
>AL> I am on the last leg of a web application, and I've run into problems 
>AL> adding validation to the mix.
>
>AL> I have an "edit" Action that retrieves a database record, a list of 
>AL> drop-down options, and then populates the "editor" ActionForm. Works 
>AL> great, and I LOVE STRUTS!
>
>AL> Now I've implemented validation (through the Validator Framework, but I 
>AL> think my problem is with validate() in general).
>
>AL> After the user clicks submit, their post is sent to my "update" action.
>
>AL> If they do not break any validation rules, all goes well. The problem 
>AL> occurs when a validation rule is broken.... They are returned to the 
>AL> form... but the drop-downs (which are populated in the "edit" Action) 
>AL> are empty. I have set breakpoints in the code... and I see that the page 
>AL> neither my "edit" Action code (the part where the drop-down data is 
>AL> retrieved), nor my "update" Action code is actually running.
>
>AL> Question.... between pressing submit and returning the "edit" JSP with a 
>AL> populated ActionErrors object. Where is "validate()" actually called?
>
>After the RequestProcessor has populated your action form, validate is
>called. This happens before your action is called.
>
>AL> Where can I insert code to populate a drop-down with a set of values so 
>AL> that it will appear both when the form is presented the first time, and 
>AL> after a validation error?
>
>You have at least 2 choices.
>
>1) You can put your drop-down values into session scope.
>
>2) You can set the input attribute of your action mapping to your edit
>action.
>
>AL> Thank you for your help,
>AL> Aaron Longwell
>
>
>AL> ---------------------------------------------------------------------
>AL> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>AL> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>Regards,
>Dirk
>
>+------- Quality leads ---------------------------------------+
>| Dirk Markert                     dirk.markert@dr-markert.de |
>| Dr. Markert Softwaretechnik AG                              |
>| Joseph-von-Fraunhofer-Str. 20                               |
>| 44227 Dortmund                                              |
>+---------------------------------->>>>>>> to success! <<<<<<-+ 
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
>  
>


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


Re: Please Help: ActionForm Re-Population

Posted by Dirk Markert <di...@dr-markert.de>.
Hello Aaron,

  

***************************************************************

AL> I am on the last leg of a web application, and I've run into problems 
AL> adding validation to the mix.

AL> I have an "edit" Action that retrieves a database record, a list of 
AL> drop-down options, and then populates the "editor" ActionForm. Works 
AL> great, and I LOVE STRUTS!

AL> Now I've implemented validation (through the Validator Framework, but I 
AL> think my problem is with validate() in general).

AL> After the user clicks submit, their post is sent to my "update" action.

AL> If they do not break any validation rules, all goes well. The problem 
AL> occurs when a validation rule is broken.... They are returned to the 
AL> form... but the drop-downs (which are populated in the "edit" Action) 
AL> are empty. I have set breakpoints in the code... and I see that the page 
AL> neither my "edit" Action code (the part where the drop-down data is 
AL> retrieved), nor my "update" Action code is actually running.

AL> Question.... between pressing submit and returning the "edit" JSP with a 
AL> populated ActionErrors object. Where is "validate()" actually called?

After the RequestProcessor has populated your action form, validate is
called. This happens before your action is called.

AL> Where can I insert code to populate a drop-down with a set of values so 
AL> that it will appear both when the form is presented the first time, and 
AL> after a validation error?

You have at least 2 choices.

1) You can put your drop-down values into session scope.

2) You can set the input attribute of your action mapping to your edit
action.

AL> Thank you for your help,
AL> Aaron Longwell


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



Regards,
Dirk

+------- Quality leads ---------------------------------------+
| Dirk Markert                     dirk.markert@dr-markert.de |
| Dr. Markert Softwaretechnik AG                              |
| Joseph-von-Fraunhofer-Str. 20                               |
| 44227 Dortmund                                              |
+---------------------------------->>>>>>> to success! <<<<<<-+ 


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