Hi,
I have a page where I let user to select a state from a selection list of 50
states and after the selection, a school district selection is populated
based on the state selected. The user then proceeds to select a school
district. After a district is selected , a table display of schools from
that district is shown which should allow user to page through if there are
multiple pages. The problem I ran into is that the paging and sorting of
table columns does not work and it also messes up the selection as well.
Source code is attached here (Schools.java and school.htm
Schools.java
------------------------
import java.sql.SQLException;
import java.util.List;
import net.sf.click.control.Column;
import net.sf.click.control.Form;
import net.sf.click.control.PageLink;
import net.sf.click.control.Select;
import net.sf.click.control.Table;
import net.sf.click.extras.control.LinkDecorator;
import net.sf.click.extras.control.TableInlinePaginator;
import org.apache.commons.lang.StringUtils;
import us.myschoolusa.entity.School;
import us.myschoolusa.service.DataManager;
import us.myschoolusa.util.Helper;
/**
*
* @author wangj6
*/
public class Schools extends WebSiteTemplate {
public Table schTable;
public PageLink viewLink;
public School school;
public Form form;
private Select stateSelect;
private Select districtSelect;
public Schools() {
form = new Form("selectForm");
stateSelect = new Select("state", "");
stateSelect.setAttribute("onchange",
"handleChange('selectForm_district', selectForm)");
form.add(stateSelect);
districtSelect = new Select("district", "");
districtSelect.setAttribute("onchange", "selectForm.submit()");
form.add(districtSelect);
schTable = new Table("schTable");
schTable.setClass(Table.CLASS_SIMPLE);
schTable.setHoverRows(true);
schTable.setPageSize(25);
schTable.setShowBanner(true);
schTable.setSortable(true);
schTable.setPaginator(new TableInlinePaginator(schTable));
schTable.setPaginatorAttachment(Table.PAGINATOR_INLINE);
Column name = new Column("fullName", "School Name");
schTable.addColumn(name);
schTable.addColumn(new Column("city"));
schTable.addColumn(new Column("state"));
Column action = new Column("Action", "");
viewLink = new PageLink("view", SchoolDetail.class);
viewLink.setParameter("referrer", "/schools.htm");
action.setDecorator(new LinkDecorator(schTable, viewLink,
"schoolId"));
action.setSortable(false);
schTable.addColumn(action);
}
public void onInit(){
super.onInit();
populateSelect();
}
private void populateSelect() {
try {
stateSelect.setOptionList(Helper.getOptionForStates());
} catch (SQLException e) {
e.printStackTrace();
form.setError("error.");
}
stateSelect.bindRequestValue();
if (StringUtils.isEmpty(stateSelect.getValue())) {
// No state selected, exit early
return;
}
try {
districtSelect.setOptionList(Helper.getOptionForDistrictsByState(stateSelect.getValue()));
districtSelect.bindRequestValue();
if (StringUtils.isEmpty(districtSelect.getValue())) {
// No district selected, exit early
return;
}
List<School> schList =
DataManager.selectSchoolsByDistrictId(Integer.parseInt(districtSelect.getValue()));
schTable.setRowList(schList);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
schools.htm
----------------------------------
<h2>School Directory</h2>
<br/>
$selectForm<br/>
#if (${schTable.getRowList().size()} > 0)
$schTable
#end
<script type="text/javascript">
function handleChange(id, form) {
var select=document.getElementById(id);
if(select != null) {
select.selectedIndex=-1;
}
form.submit();
}
</script>
--
View this message in context:
http://n2.nabble.com/need-help-on-select-and-table-controls-tp2222256p2222256.html
Sent from the click-user mailing list archive at Nabble.com.