struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From BHans...@powersystems.rockwell.com
Subject Re: Prepopulating DynaValidatorForm and validating
Date Wed, 07 Sep 2005 12:10:37 GMT

I have handled this in two different ways.

1.  Previously I had a preprocess action which populated the collection and
that was all it did.  In the struts-config, I set the preprocessAction.do
as the input page.  That way if the validation failed, struts will execute
the preprocessAction which will repopulate the list and redisplay the form
in tact.

2.  Resently, I have been using DWR (Ajax) project to load the select list
when the page is rendered.  I do this because my list is dynamic and can
change based on selections that the user enters on the page.




                                                                           
             Peter.Zoche@mater                                             
             na.de                                                         
                                                                        To 
             09/07/2005 05:20          user@struts.apache.org              
             AM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to         Prepopulating DynaValidatorForm and 
               "Struts Users           validating                          
               Mailing List"                                               
             <user@struts.apac                                             
                  he.org>                                                  
                                                                           
                                                                           
                                                                           




Hi all!

Googling and seraching the archive did not solve my problem, so
I will have a try. In my struts-config.xml, I have defined a
DynaValidatorForm and an action:

<form-bean name="editForm"
  type="org.apache.struts.validator.DynaValidatorForm">
  <form-property name="projectList" type="java.util.Collection"/>
  <form-property name="version" type="java.lang.String" initial=""/>
</form-bean>

<action path="/processEdit"
  type="com.materna.buc.buildmanager.actions.ProcessEditAction"
  scope="request"
  name="editForm"
  validate="true"
  input="/WEB-INF/jsp/edit.jsp">
  ...
</action>

As you can see, this form holds a list of projects in a collection,
which has to be populated before the corresponding jsp-page is shown.
So I have an Action which gets the (dynamic, not static) list of
projects from a database and puts it into the editForm like this:

public ActionForward execute( ... ) {

  DynaValidatorForm dynaForm = (DynaValidatorForm) form;

  // get list of projects from database
  Collection projectList = getDatabaseHandler().getProjectList();

  // put project list into DynaValidatorForm
  dynaForm.set( "projectList", projectList );

Everything works fine after showing my jsp-page with a combobox
populated with the data from my projectList - the user can choose
one project.
But on the same page there is a html:text field:

<html:text name="editForm" property="version"
  value="1.0" size="7" />

which corresponds to my editForms "version"-property.
When the user submits the form to processEdit, the version
property has to be validated to see if it is not empty.
So in my validation.xml I do the following:

<form name="editForm">
  <field property="version" depends="required">
    <arg0 key="edit.version" />

  </field>
</form>

If the user submits an empty version and validation fails,
he will be send back to the jsp-page, but it will not show
because the project list is not present any more. That seems
clear because the DynaValidatorForm is reset when the user
submits. I tried following workarounds:

1. I replaced the DynaValidatorForm with my own version
overwriting the reset - method to do nothing. Additionaly
set the scope to "session". But my project list gets still
lost (wondering why?)

2. Trying to pass my project list from one form to the other
like this

<html:hidden name="editForm" property="projectList"
  value="projectList"

in all variations always had to fail because the project list
will be send as a string and therefore can not be converted
back to a collection.

I considered to put my project list into application scope, but
as it is dynamic, large and not the only (dynamic and large) list
to be shown on my jsp-page (I only used it as an example in order
not to complicate my question), I am not sure if it is the right
way.

And writing an ActionForm with own validation and reset methods
is a lot of work and would not use the benefits of a
DynaValidatorForm...

So if you know a trick, solution or workaround, please help!

Thanks

Peter


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


Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message