It's not a stupid question. I'm not sure if it's off-topic or not. :-)

The JSP fragment you posted suggests that your JSP is being invoked 
directly. That is, the URL coming from the browser references the JSP, and 
not a Struts Action (e.g. doSomthing.do). If this is the case, then I don't 
think Struts can help you much, since it won't have a chance to touch the bean.

In a typical Struts application, the request will be handled by the 
controller servlet, which will parse the request and populate a form bean 
with the parameters. An Action will then process the request and forward to 
a JSP for displaying the results to the user. In this scenario, since 
Struts populated form bean for you, there is usually no need to use the 
useBean/setProperty mechanism you have.

Also - and this is the piece you need - the controller servlet will call 
the reset() method on your form bean immediately before populating it with 
the values from the new request. That gives you the chance to clear out the 
old values, so that they are not left in the form bean if there is no 
corresponding value in the request.

Hope this helps.

--
Martin Cooper
Tumbleweed Communications


At 10:42 PM 2/27/01 +0800, Kan Leung, MK wrote:
>Sorry if you find if this is a bit off topic. ;)
>
>Hi all,
>
>Hope this is not a FAQ. (I spent 2 hours to do net search but didn't
>get a good answer)
>
>8<
><jsp:useBean name="abc" scope="session" .... />
><jsp:setProperty name="abc" property="*"/>
>8<
>
>Introspection magic makes the property setters called if they match the
>input parameters by GET or by POST.
>
>e.g. URL?address1=a&address2=&address3=
>
>
>There are exceptions: setters of some parameters which have no value
>won't get called. In the above string, the later two are not called
>because they have no values assigned. Suppose my bean has session scope.
>Values kept unchanged.
>
>My question is: how can the web users clear a text field if the field is
>incorrectly filled?
>
>I suppose the introspection magic is a life-saver. I just don't want to
>check the return value of request.getParameter("address2) for each input
>to determine if it's empty.
>
>Can anybody give me a good alternative to clear unwanted fields easily?
>
>--
>Kan LEUNG, M K
>email: [EMAIL PROTECTED]
>Digital Empires Company Limited


Reply via email to