You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by hernan gonzalez <hg...@gmail.com> on 2008/01/11 18:07:27 UTC

s2 : checkbox and checkboxlist : dynamic lists

Disclaimer: I'm fairly new to Struts2, so I may me wrong. But:

I feel the behaviour of checkbox tag lacking. I dont think there is a
straighforward way to do a common web-application case: a form with a
dynamic list of N "records" (rows), each of which can be selected by
the user by a checkbox. (Example: a webmail). The UI checkbox tag of
struts does not seem to cope well with this.

I know of checkboxlist; but this does not seem the right answer.
checkboxlist is thought as a macro-input component, very similar to a
select box with multiple selection. That is, its idea is one checkbox
tag instance which loops over all the N set of selections. I know
there are some twists to adapt it to my situation (N instances of the
checkboxlist tag, each of which has a list of only one element). This
can be worked, but I feel it hacky/dirty, and has some limitations
(BTW: I found the checkboxlist tag somewhat impredecible; the valueKey
and valueList work inconsistently, the label is used even with the
simple theme, etc).

For my situacion, I believe, one should be able to use the checkbox
tag (after all, one is trying to output one checkbox , not a list).
And the original html specification copes ok with this, and it has
been done for ages in web programming. In fact, the present struts
implementation of the checkbox tag severly limits the usefullnes of
the "fieldvalue" attribute: practically only the "true" and "false"
values seems to be expected.

My question/proposal: the checkbox UI tag should accept (and expect)
to be backed (via the "name" attribute) not only to a Boolean field,
but also to a Collection. In this case, the parameter interceptor
would work similarly than for a multiple-select: add the value to the
collection, and check for its existence.
Is there some catch for this not being implemented in that way?


Hernán J. González
http://hjg.com.ar/

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


Re: s2 : checkbox and checkboxlist : dynamic lists

Posted by Rubbinio <rs...@n-able.com>.
Struts 2.0.11
Nope, no documentation just many attempts until we got it to work.

The class looks like this:

public class OurAction extends ActionSupport implements SessionAware,
ParameterAware, ParameterNameAware {
.....
private String[] selectedGroup;
.....

public void setSelectedGroup(String[] selectedGroup) {
      this.selectedGroup = selectedGroup;
}

The JSP:

<s:form action="ourAction" id="ourForm">
.....
   <s:iterator id="rowData" value="myList">
          .....
          <s:checkbox name="selectedGroup"
fieldValue="%{id}_%{nextCell.label}" theme="simple"/>
          .....
    </s:iterator>
.....
</s:form>


The mapping in struts.xml

<action name="*ourAction" class="package.ourAction" method="{1}">
    <interceptor-ref name="defaultStack"/>
    .....
    results set here
    .....
</action>

-- 
View this message in context: http://www.nabble.com/s2-%3A-checkbox-and-checkboxlist-%3A-dynamic-lists-tp14760993p14812186.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: s2 : checkbox and checkboxlist : dynamic lists

Posted by hernan gonzalez <hg...@gmail.com>.
Does not work for me.
Does that work on struts 2.0.x ? Did you find documented somewhere ?
Some special interceptor o configuration ?

Hernán J. González

On Jan 11, 2008 4:23 PM, Rubbinio <rs...@n-able.com> wrote:
>
> Actually you can do something like this
>
> <s:checkbox name="selectedGroup" fieldValue="%{id}_%{nextCell.label}" />
>
> And in the action class you can have:
>
> private String[] selectedGroup;
>
> Which will be populated back with what you have selected. It works fine in
> our application.
> --
> View this message in context: http://www.nabble.com/s2-%3A-checkbox-and-checkboxlist-%3A-dynamic-lists-tp14760993p14762264.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



--

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


Re: s2 : checkbox and checkboxlist : dynamic lists

Posted by Rubbinio <rs...@n-able.com>.
Actually you can do something like this

<s:checkbox name="selectedGroup" fieldValue="%{id}_%{nextCell.label}" />

And in the action class you can have:

private String[] selectedGroup;

Which will be populated back with what you have selected. It works fine in
our application. 
-- 
View this message in context: http://www.nabble.com/s2-%3A-checkbox-and-checkboxlist-%3A-dynamic-lists-tp14760993p14762264.html
Sent from the Struts - User mailing list archive at Nabble.com.


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