Thomas Heller wrote:

[ posted to struts-user but i just realized struts-dev might be a better
place for this]

... actually, it's a struts-user question.

Hi there,

I'm trying to create a form with some pre-filled which either come from a
cookie or a database. i browsed the archive and found a comment from Craig
where he says the best way to do this is by routing the specified request
into a action and populate the form there. IMHO this way would complicate
the Actions execute method unnecessary complicat cause it must have a
"action-case" for "prepopulate".

That's the way it's done.

IMHO the best way to handle what i would want to do would be done like this.

1. introduce a "prepare(HttpServletRequest request)" method info
"ActionForm"
2. invoke this method in "RequestUtils.createActionForm(...)" right after
"instance.setServlet(servlet)" in line 638

Forms are just a conduit by which data is transferred from the user to an action. In addition, you may wish to use the same form with different actions (and have it contain different data). The forms should be as stupid as possible - your suggestions don't allow that. Of course, if you really insist on this behavior ... you have the source :-)

inside the Forms "prepare" (populate or some other name) Method i could
prepare all fields like i want including setting values from session,
request, cookies, context, db, etc since i get the current request as a
method param.

You can do that in your action :-) and since you can associate a form with many different actions you have the flexibility to populate it in different ways depending on the action that actually populates it ;-)

dunno how to submit patches to struts but it would look something like this:

http://issues.apache.org/bugzilla <--- Our bug database. Create a "bug" and then attach your code as a "cvs diff -u".

class: org.apache.struts.action.ActionForm
[snip]

   /**
    * Prepare the form before it gets displayed first.
    * <p>
    * The default implementation does nothing.  Subclasses can
   * override this method to insert values from a DB/Cookie into
   * the form
    *
    * @param request The servlet request we are processing
    */
   public void prepare(HttpServletRequest request) {

       ;       // Default implementation does nothing

   }
[/snip]

All forms written before this method would still work and it eases the work
of setting form values by cookies alot.

I don't really see how it does anything but limit the use of the form. You would have no additional functionality available to you in the proposed "prepare" method compared to what you can do in an action's "execute" method. Again, if you wish to make your forms so specfic, there's nothing to keep you from doing it - the source if freely available, and there's nothing that keeps you from modifying it to suit your own needs.

Comments welcome ...

thanks,
Thomas Heller

--
Eddie Bush





--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to