You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by "Wang, Sherwin X." <Sh...@gs.com> on 2006/09/01 21:42:30 UTC

De-select sticky options doesn't work

Hi Struts dev team,

I am using Struts 1.2.9 and html:select and html:optionsCollection tags
to render a "sticky" select box. It works great except for one case. If
de-select all pre-selected options using control-click, all options are
still selected after the page comes back.

In RequestUtils.java, method populate (line 459) uses
request.getParameterNames to get all parameters. But if all
pre-selection are de-selected, the parameter of the select box will not
be sent though request. In this case, the values of that property stay
and the de-select fails.

Since the framework fails in this case, I have to reset the properties
in the application as a work around. Shouldn't Struts be enhanced to
support this capability if there wasn't one?

Thanks,
Sherwin

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


Re: De-select sticky options doesn't work

Posted by Sherwin Wang <sh...@yahoo.com>.
Thanks for the tip. I tried Struts 1.3.5 beta, the
latest, with the reset in the form-property. It resets
the options when the form element doesn't present in
the request.

However, as I expected, the solution fails if the dyna
form bean is used by multiple requests. For instance,
if I navigate to next page and come back, the
pre-selected options are gone. I need them to stay
unless I de-select them.

As I suggested earlier in this thread, the information
in HTML tag can be used to reset the options no more
and no less.

Sherwin

--- Sherwin Wang <sh...@yahoo.com> wrote:

> We are using Struts 1.2.9. I'll try 1.3 reset
> property
> later. No, we are not using DynaXForms. Why
> DynaXForms
> supports property reset, assuming it does, but
> ActionForm doesn't?
> 
> To me, ActionForm can be converted to DynaXForms by
> reflection. Whatever way used in DynaXForms can be
> also used in ActionForm. Correct me if I am wrong.
> 
> Sherwin


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: De-select sticky options doesn't work

Posted by Sherwin Wang <sh...@yahoo.com>.
We are using Struts 1.2.9. I'll try 1.3 reset property
later. No, we are not using DynaXForms. Why DynaXForms
supports property reset, assuming it does, but
ActionForm doesn't?

To me, ActionForm can be converted to DynaXForms by
reflection. Whatever way used in DynaXForms can be
also used in ActionForm. Correct me if I am wrong.

Sherwin

--- Paul Benedict <pb...@apache.org> wrote:

> I am jumping in here late in the game. But if Struts
> 1.3 adds the new 
> reset property, doesn't this get you what you want?
> Or is it because it 
> only covers DynaXForms which you're not using?
> 
> Paul


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: De-select sticky options doesn't work

Posted by Paul Benedict <pb...@apache.org>.
I am jumping in here late in the game. But if Struts 1.3 adds the new 
reset property, doesn't this get you what you want? Or is it because it 
only covers DynaXForms which you're not using?

Paul

Sherwin Wang wrote:
> For the case you described, "looping through form bean
> properties to set or reset their values" will not
> work. But the solution can be improved to cover this
> case. 
> 
> Let's keep the "looping for request parameters to set
> form bean properties" unchanged. In HTML tag
> implementation add logic to create a request to a set
> of property names mapping. Later, loop for all
> property names for the request, if the value is not
> presented in the request, reset the property. This
> way, the properties will be set no more (cover your
> case) and no less (cover the missing support in
> Struts)
> 
> The de-select all options in a form when using a
> session scoped static form bean can be supported by
> Struts. Application developers are no need to struggle
> with different kinds of work around.
> 
> --- Wendy Smoak <ws...@gmail.com> wrote:
> 
>> But let's say we did it the way you describe.  What
>> happens when I use
>> a single session scoped form bean across my entire
>> application, and
>> each form only uses a subset of the form bean's
>> properties?
>>
>> -- 
>> Wendy
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
> 
> 

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


Re: De-select sticky options doesn't work

Posted by Sherwin Wang <sh...@yahoo.com>.
For the case you described, "looping through form bean
properties to set or reset their values" will not
work. But the solution can be improved to cover this
case. 

Let's keep the "looping for request parameters to set
form bean properties" unchanged. In HTML tag
implementation add logic to create a request to a set
of property names mapping. Later, loop for all
property names for the request, if the value is not
presented in the request, reset the property. This
way, the properties will be set no more (cover your
case) and no less (cover the missing support in
Struts)

The de-select all options in a form when using a
session scoped static form bean can be supported by
Struts. Application developers are no need to struggle
with different kinds of work around.

--- Wendy Smoak <ws...@gmail.com> wrote:

> But let's say we did it the way you describe.  What
> happens when I use
> a single session scoped form bean across my entire
> application, and
> each form only uses a subset of the form bean's
> properties?
> 
> -- 
> Wendy


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: De-select sticky options doesn't work

Posted by Wendy Smoak <ws...@gmail.com>.
On 9/1/06, Wang, Sherwin X. <Sh...@gs.com> wrote:

> Could this approach resolve this problem so that make Struts more
> powerful? Instead of "looping through parameters in a request" and
> setting the form bean properties, could the logic "loop through the form
> bean properties" and set them by retrieving the values from the request?
> For a certain property, if the value doesn't present in the request,
> reset this property.

I thik the behavior you are describing can be achieved by changing
your form bean to request scope.  They you start with an empty form
bean every time, and only the values present in the request will be
populated.

But let's say we did it the way you describe.  What happens when I use
a single session scoped form bean across my entire application, and
each form only uses a subset of the form bean's properties?

-- 
Wendy

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


RE: De-select sticky options doesn't work

Posted by "Wang, Sherwin X." <Sh...@gs.com>.
Wendy,

Yes, you could blame HTML spec for sending only successful form
elements. But I'd use a little more positive attitude to address this
problem. :)

Could this approach resolve this problem so that make Struts more
powerful? Instead of "looping through parameters in a request" and
setting the form bean properties, could the logic "loop through the form
bean properties" and set them by retrieving the values from the request?
For a certain property, if the value doesn't present in the request,
reset this property.

I am using the "not present in a request" condition to trigger an
individual property reset as a work around. I am also using the
"recommended" approach to reset entire session scoped form bean. If the
said approach is used, both these resets are not necessary. Application
developers will much happier to use Struts.

Thanks,
Sherwin

-----Original Message-----
From: Wendy Smoak [mailto:wsmoak@gmail.com] 
Sent: Friday, September 01, 2006 4:04 PM
To: Struts Developers List
Subject: Re: De-select sticky options doesn't work

On 9/1/06, Wang, Sherwin X. <Sh...@gs.com> wrote:

> Since the framework fails in this case, I have to reset the properties

> in the application as a work around. Shouldn't Struts be enhanced to 
> support this capability if there wasn't one?

http://struts.apache.org/1.x/struts-taglib/faq.html#checkbox

As you mention, the real issue is that browsers only submit successful
form elements, and an unchecked checkbox is not a successful form
element.  Using the reset method of a session scoped form to clear
checkboxes has long been the recommended approach.  I'd argue that you
are working around the limits of the HTML specification, not Struts.
:)

If you are using dynamic form beans configured in struts-config.xml,
Struts 1.3 introduces a 'reset' attribute for <form-property>.  I just
recently discovered it and haven't tried it yet.

http://struts.apache.org/1.x/struts-core/dtddoc/org/apache/struts/resour
ces/struts-config_1_3.dtd.html#form-property

reset  - The flag that indicates when this property should be reset to
its "initial" value when the form's "reset()" method is called.  If this
is set to "true", the property is always reset when "reset()" is called.
This can also be set to one or more HTTP methods, such as GET or POST.
In such a case, the property will be reset only when the HTTP method
used for the request being processed is included in this attribute's
value(s). Multiple HTTP methods can be specified by separating them with
whitespace or commas.

Here's a related JIRA issue:
https://issues.apache.org/struts/browse/STR-2265

HTH,
--
Wendy

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

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


Re: De-select sticky options doesn't work

Posted by Wendy Smoak <ws...@gmail.com>.
On 9/1/06, Wang, Sherwin X. <Sh...@gs.com> wrote:

> Since the framework fails in this case, I have to reset the properties
> in the application as a work around. Shouldn't Struts be enhanced to
> support this capability if there wasn't one?

http://struts.apache.org/1.x/struts-taglib/faq.html#checkbox

As you mention, the real issue is that browsers only submit successful
form elements, and an unchecked checkbox is not a successful form
element.  Using the reset method of a session scoped form to clear
checkboxes has long been the recommended approach.  I'd argue that you
are working around the limits of the HTML specification, not Struts.
:)

If you are using dynamic form beans configured in struts-config.xml,
Struts 1.3 introduces a 'reset' attribute for <form-property>.  I just
recently discovered it and haven't tried it yet.

http://struts.apache.org/1.x/struts-core/dtddoc/org/apache/struts/resources/struts-config_1_3.dtd.html#form-property

reset  - The flag that indicates when this property should be reset to
its "initial" value when the form's "reset()" method is called.  If
this is set to "true", the property is always reset when "reset()" is
called. This can also be set to one or more HTTP methods, such as GET
or POST. In such a case, the property will be reset only when the HTTP
method used for the request being processed is included in this
attribute's value(s). Multiple HTTP methods can be specified by
separating them with whitespace or commas.

Here's a related JIRA issue:  https://issues.apache.org/struts/browse/STR-2265

HTH,
-- 
Wendy

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