Thanks you all for the help!
I found it hard to implement and decided to let go the paging and sorting of
my table. This way I have no issue. My page size typically is less than 200.
I am good for now.
Jay Wang.


florin.g wrote:
> 
> I looks like I needed to know this myself:
> 
> table.getControlLink().setParameter("companyId", companyId); 
> 
> For this case, it is the way to go.
> 
> 
> 
> sabob wrote:
>> 
>> Hi Jay,
>> 
>> As Florin suggested you can use a stateful Page, or add the state and 
>> district parameters to the Table controlLink.
>> 
>> See here for details: 
>> http://incubator.apache.org/click/docs/click-api/net/sf/click/control/Table.html#paging-and-sorting
>> 
>> Another option is to store the Page state in the session for example:
>> 
>> public class SchoolPageState implements Serializable {
>>   public String state;
>>   public String district;
>> }
>> 
>> public class Schools extends WebSiteTemplate {
>>   public void onInit() {
>>     super.onInit();
>>     restoreState();
>>     ...
>>   }
>> 
>>   public void saveState() {
>>     // store the state in the session
>>   }
>> 
>>   public void restoreState() {
>>     // retrieve the state from the session
>>   }
>> 
>>   public void onRender() {
>>     saveState();
>>   }
>> }
>> 
>> kind regards
>> 
>> bob
>> 
>> 
>> florin.g wrote:
>>> By default, your page is stateless - hence your selections are lost as
>>> you
>>> navigate the table for the first time.
>>>
>>> You need to either use a stateful page [ setStateful(true) in the page
>>> constructor ] or do some footwork with the url parameters.
>>>
>>> To continue use a stateless page, you need to pass the choices made in
>>> your
>>> lists as url parameters back to the page when you set the district and
>>> then
>>> when you navigate the table. I'd use a client side library such as
>>> jQuery to
>>> capture the values of the select objects and append these values to the
>>> previous/next table navigation urls. When back to the page, you must use
>>> those values to re-configure your lists (state, district and schools).
>>> Sounds like a lot of work. Go with the stateful page.
>>>
>>>  
>>>
>>> Jay Wang wrote:
>>>   
>>>> 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-tp2222256p2265932.html
Sent from the click-user mailing list archive at Nabble.com.

Reply via email to