Please see the LocaleList component in the Workbench (the Table tab in
the example application bundled with the Tapestry distributions). It
does exactly, and if you look at the comments you will see a second way
to do that as well.
Ashish Raniwala wrote:
Hi,
This worked as long as I am on same page of the table. If I use pagenation
in table component, selected rows gets cleared.
Any idea on how to preserve selected set during pagenation.
Thanks,
Ashish
-----Original Message-----
From: Hensley, Richard [mailto:[EMAIL PROTECTED]
Sent: Wednesday, September 28, 2005 4:58 PM
To: Tapestry users
Subject: RE: Table with checkbox
This is from a sample application I teach from. The basic premise is to
allow the user to do something with a set of selected Locales. Why Locales,
because when teaching the fewer dependencies the better.
This works by maintaining a set of locales. It uses the getter during the
render cycle to set the checked property. It uses the setter during the
rewind cycle to maintain the set based on user selection.
.page file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE page-specification PUBLIC
"-//Apache Software Foundation//Tapestry Specification 3.0//EN"
"http://jakarta.apache.org/tapestry/dtd/Tapestry_3_0.dtd">
<!-- generated by Spindle, http://spindle.sourceforge.net -->
<page-specification class="com.mckesson.lab.sample.page.Page2">
<description>add a description</description>
<property-specification name="loopLocale" type="java.lang.Object" />
<property-specification name="selectedLocales" type="java.util.Set" />
</page-specification>
.html file
<html jwcid="@Border" title="Page 2">
<form jwcid="@Form" listener="ognl:listeners.listenerSubmit">
<ul>
<li jwcid="@Foreach"
source="ognl:@[EMAIL PROTECTED]()"
value="ognl:loopLocale" element="li">
<label>
<input jwcid="@Checkbox"
selected="ognl:isLocaleSelected" />
<span jwcid="@Insert"
value="ognl:loopLocale.displayName" />
</label>
</li>
</ul>
<input type="submit" />
</form>
</html>
package com.mckesson.lab.sample.page;
import java.util.HashSet;
import java.util.Set;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.event.PageEvent;
import org.apache.tapestry.event.PageRenderListener;
import org.apache.tapestry.html.BasePage;
public abstract class Page2 extends BasePage implements PageRenderListener {
public void listenerSubmit(IRequestCycle cycle) {
Page1 p = (Page1) cycle.getPage("Page1");
p.setLocales(getSelectedLocales());
cycle.activate(p);
}
public boolean getIsLocaleSelected() {
return getSelectedLocales().contains(getLoopLocale());
}
public void setIsLocaleSelected(boolean value) {
if (value) {
getSelectedLocales().add(getLoopLocale());
}
else if (getSelectedLocales().contains(getLoopLocale())) {
getSelectedLocales().remove(getLoopLocale());
}
}
public void pageBeginRender(PageEvent event) {
if (getSelectedLocales() == null) {
setSelectedLocales(new HashSet());
}
}
public abstract Set getSelectedLocales();
public abstract void setSelectedLocales(Set value);
public abstract Object getLoopLocale(); } -----Original Message-----
From: Ashish Raniwala [mailto:[EMAIL PROTECTED]
Sent: Wednesday, September 28, 2005 4:50 PM
To: 'Tapestry users'
Subject: Table with checkbox
Hi,
This must be a common question in forum, sorry for asking again.
How to create multi select checkboxes in table ? I need to include a
checkbox in each table row and save the selected records.
Should I create a HashMap of ids and bind the checkbox with map Or what is
the best way to do this ?
Thanks,
Ashish
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]