You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Struts Newsgroup (@Basebeans.com)" <st...@basebeans.com> on 2002/05/22 03:25:01 UTC
Nesting Objects In ActionForm are reset()
Subject: Nesting Objects In ActionForm are reset()
From: Brandon Knitter <kn...@blandsite.org>
===
Hey there, I'm struggling through this and just need an answer, or if
there isn't one perhaps an explanation. I may be using the Struts model
entirely wrong, so if so, please clue me in! :)
I noticed that before an ActionForm is handed to an Action servlet that
it's reset method is called. This would seem like a good idea except in
the case where you have nested classes (objects) on the Action that are
set to null by default.
For instance, if I have an EditUserForm ActionForm bean that has a User
(variable: user) object in it, it's very cool that I can refer to the
properties of the User in my jsp as "user.firstname" for instance.
The problem is that when an ActionForm is populated from the actual jsp,
first reset() is called which blows everything away. This seems like a
bad approach as that really should be called init() and only called
after instantiation of the ActionForm bean. Unless I'm mistaken, the
ActionForm is never reused (whereas an Action servlet is), so reset
shouldn't need to be called unless desired.
My workaround is to add some logic to the reset() method which will not
blow away the variables of the ActionForm when it is called from a
submit on a form, for instance.
If you are simply just using things such as a bunch of String vars, for
instance, this would seem like an okay trend, but since I am using other
objects, it kinda screws things up.
Now this brings up another point, if you do not reset the variables, and
you go ahead and reset all the vars, there is a large chance for a
thread conflict. For instance, if I have two browser windows open on
the same session, whatever the last populated ActionForm was, it will be
updated. This could cause some other serious issues, including data
copying from on User to another, and in my case a security risk becuase
someone could accidentally copy permissions from one user to another.
Please advise me if I'm using things incorrectly here. It would seem as
though I'm not as even the Wrox book states that this should work (they
have a reset() method blowing away their data), but alas it will
probably fail on their test code as it too sets the variables to new User().
Thanks,
--
-bk
knitterb@blandsite.org
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>