You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Hilco Wijbenga <hi...@gmail.com> on 2010/01/22 02:40:18 UTC
Dynamicly Created Checkboxes
Hi all,
I am trying to get the submit results of a dynamic set of checkboxes
and I'm stumped.
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
<body>
<t:form>
<t:loop source="list" value="item">
<t:checkbox t:id="checkbox" t:value="checkbox"
t:context="item"/>${item}<br/>
</t:loop>
<t:submit/>
</t:form>
</body>
</html>
public class Test {
private final String[] list = new String[] { "Abc", "Defg", "Hijkl", "Mno" };
@Property private String item;
@Property private boolean checkbox;
public String[] getList() {
return list;
}
}
If I simply add "onSuccess()" I only get the result for "Mno". Adding
one or more parameters (for item and checkbox) doesn't seem to work. I
tried various other methods and combinations but nothing seems to do
the trick.
How do I do this?
Cheers,
Hilco
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Dynamicly Created Checkboxes
Posted by Jun Tsai <ju...@gmail.com>.
I think you should write own component to support that.
<t:loop source="list" value="item">
<inpu type="checkbox" id="${xx}" name="${xx}"
value="${item}"/>${item}<br/>
</t:loop>
processSubmit:
request.getParameters("xxx");
2010/1/22 Hilco Wijbenga <hi...@gmail.com>
> Hi all,
>
> I am trying to get the submit results of a dynamic set of checkboxes
> and I'm stumped.
>
> <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
> <body>
> <t:form>
> <t:loop source="list" value="item">
> <t:checkbox t:id="checkbox" t:value="checkbox"
> t:context="item"/>${item}<br/>
> </t:loop>
> <t:submit/>
> </t:form>
> </body>
> </html>
>
>
> public class Test {
> private final String[] list = new String[] { "Abc", "Defg", "Hijkl", "Mno"
> };
> @Property private String item;
> @Property private boolean checkbox;
> public String[] getList() {
> return list;
> }
> }
>
> If I simply add "onSuccess()" I only get the result for "Mno". Adding
> one or more parameters (for item and checkbox) doesn't seem to work. I
> tried various other methods and combinations but nothing seems to do
> the trick.
>
> How do I do this?
>
> Cheers,
> Hilco
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
regards,
Jun Tsai
Re: Dynamicly Created Checkboxes
Posted by Shing Hing Man <ma...@yahoo.com>.
I have a running example as described by Josh below.
http://lombok.demon.co.uk/tapestry5Demo/test/components/checkboxgroupdemo
Shing
--- On Sat, 23/1/10, Josh Canfield <jo...@thedailytube.com> wrote:
> From: Josh Canfield <jo...@thedailytube.com>
> Subject: Re: Dynamicly Created Checkboxes
> To: "Tapestry users" <us...@tapestry.apache.org>
> Date: Saturday, 23 January, 2010, 3:01
> > I am trying to get the submit
> results of a dynamic set of checkboxes
> > and I'm stumped.
>
> I'm not sure what you expect the value to be? Also, I don't
> see
> t:context in the checkbox documentation, does that do
> something?
>
> You are having trouble because you have a list of values
> going out,
> but only a single value coming back in. For each checkbox
> selected in
> the UI a value is passed back to the component. It calls
> the setter
> for each value, overwriting the previous value and leaving
> you with
> the last only the last one.
>
> Try adding a setter for your property and collect the
> checked values in a list.
>
> something like:
>
> <t:loop source="list" value="item"
> index="listIndex">
> <t:checkbox
> t:id="checkbox" t:value="checkbox"/>${item}<br/>
> </t:loop>
>
> /** keep track of loop iterations */
> private Integer listIndex;
>
> /** loaded with selected checkbox values */
> private List<String> selectedItems;
>
> /**
> * Called with the form is posted for every checkbox that
> is checked.
> * Use the listIndex to grab the right value from the
> original list.
> **/
> public void setCheckbox(boolean set) {
> if (selectedItems == null)
> selectedItems = new ArrayList<String>();
>
> selectedItems.add(list.get(listIndex));
> }
>
>
> Josh
>
> On Thu, Jan 21, 2010 at 5:40 PM, Hilco Wijbenga
> <hi...@gmail.com>
> wrote:
> > Hi all,
> >
> > I am trying to get the submit results of a dynamic set
> of checkboxes
> > and I'm stumped.
> >
> > <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
> > <body>
> > <t:form>
> > <t:loop source="list" value="item">
> > <t:checkbox t:id="checkbox"
> t:value="checkbox"
> > t:context="item"/>${item}<br/>
> > </t:loop>
> > <t:submit/>
> > </t:form>
> > </body>
> > </html>
> >
> >
> > public class Test {
> > private final String[] list = new String[] { "Abc",
> "Defg", "Hijkl", "Mno" };
> > @Property private String item;
> > @Property private boolean checkbox;
> > public String[] getList() {
> > return list;
> > }
> > }
> >
> > If I simply add "onSuccess()" I only get the result
> for "Mno". Adding
> > one or more parameters (for item and checkbox) doesn't
> seem to work. I
> > tried various other methods and combinations but
> nothing seems to do
> > the trick.
> >
> > How do I do this?
> >
> > Cheers,
> > Hilco
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
>
> --
> --
> TheDailyTube.com. Sign up and get the best new videos on
> the internet
> delivered fresh to your inbox.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Dynamicly Created Checkboxes
Posted by Josh Canfield <jo...@thedailytube.com>.
> I am trying to get the submit results of a dynamic set of checkboxes
> and I'm stumped.
I'm not sure what you expect the value to be? Also, I don't see
t:context in the checkbox documentation, does that do something?
You are having trouble because you have a list of values going out,
but only a single value coming back in. For each checkbox selected in
the UI a value is passed back to the component. It calls the setter
for each value, overwriting the previous value and leaving you with
the last only the last one.
Try adding a setter for your property and collect the checked values in a list.
something like:
<t:loop source="list" value="item" index="listIndex">
<t:checkbox t:id="checkbox" t:value="checkbox"/>${item}<br/>
</t:loop>
/** keep track of loop iterations */
private Integer listIndex;
/** loaded with selected checkbox values */
private List<String> selectedItems;
/**
* Called with the form is posted for every checkbox that is checked.
* Use the listIndex to grab the right value from the original list.
**/
public void setCheckbox(boolean set) {
if (selectedItems == null) selectedItems = new ArrayList<String>();
selectedItems.add(list.get(listIndex));
}
Josh
On Thu, Jan 21, 2010 at 5:40 PM, Hilco Wijbenga
<hi...@gmail.com> wrote:
> Hi all,
>
> I am trying to get the submit results of a dynamic set of checkboxes
> and I'm stumped.
>
> <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
> <body>
> <t:form>
> <t:loop source="list" value="item">
> <t:checkbox t:id="checkbox" t:value="checkbox"
> t:context="item"/>${item}<br/>
> </t:loop>
> <t:submit/>
> </t:form>
> </body>
> </html>
>
>
> public class Test {
> private final String[] list = new String[] { "Abc", "Defg", "Hijkl", "Mno" };
> @Property private String item;
> @Property private boolean checkbox;
> public String[] getList() {
> return list;
> }
> }
>
> If I simply add "onSuccess()" I only get the result for "Mno". Adding
> one or more parameters (for item and checkbox) doesn't seem to work. I
> tried various other methods and combinations but nothing seems to do
> the trick.
>
> How do I do this?
>
> Cheers,
> Hilco
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
--
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Dynamicly Created Checkboxes
Posted by Stephan Windmüller <st...@cs.tu-dortmund.de>.
Am 22.01.2010 02:40, schrieb Hilco Wijbenga:
> If I simply add "onSuccess()" I only get the result for "Mno". Adding
> one or more parameters (for item and checkbox) doesn't seem to work.
That sounds very familiar. Please have a look at this bug report:
https://issues.apache.org/jira/browse/TAP5-869
Try it set the defer parameter of your submit component to false.
Regards
Stephan
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org