Save State of Checkbox in form table apache click

469 Views Asked by At

I have a apache click page having a form table with action links and a checkbox. Table also have paginator. once user select some entries from table by selecting checkboxes he can perform operations by selecting submit button on form. But checkboxes are not preserving their state when user move from one table page to other. I tried saving selected entries in static arraylist but it is not getting populated.

2

There are 2 best solutions below

0
On

Click is a stateless framework. Quoting the documentation:

Control state is not saved and restored automatically by Click. Instead, state saving and restoring is under full control of the developer through a public API.

As you can see from the Stateful interface's doc, several controls implements that contract and using the "Search Table Page" example as a reference you can implement your use case.

Hth,

Gilberto

0
On

Try following steps:
1. make a hidden field on java page. add it to the form.
2. onclick of every checkbox set the value of hiddenfield using javascript function.
3. add dummy form to you htm page with dummy hidden submit. like

<form name="dummyForm" action="" method="POST" >
<input type="hidden" name="dummyHiddenCBSelected" value="" />
</form>

4. on java page table paging link call the javascript function to submit the above dummy form. eg: table.getControlLink().setAttribute("onclick", "tableAction(this); return false;");

and javascript function like:

function tableAction(_anchorObj) {


  var linkHref;  
  linkHref = _anchorObj.getAttribute("href");


  //Set the value in hidden field
  var hiddenCBSelected = document.getElementById('your hiddenfield');
  document.getElementsByName("dummyHiddenCBSelected")[0].value = hiddenCBSelected.value;

  //Set the form href and submit form
  document.getElementsByName('dummyForm')[0].action = linkHref;
  document.getElementsByName('dummyForm')[0].submit();

}