I'm trying to create a page similar to the searchable table example.
I have a form which have a fieldset and a submit button, the fieldset
includes two fields,a CheckList and a Select.
the form's state will be saved when the submit button is clicked, as well as
in a tables ActionListener(when paging and sorting).
And on init, the page will restore the saved fields from the form and
retrieve database record based on the field values.
I found some interesting behaviors when saving the form's state.
1.if the form is declared with @Bindable, the submit botton will save the
form's value and populate the table. if form is added using addModel instead
of @Bindable. field value will be cleared after button click and the table
will be empty.
2. table paging will not save the state of the form, if i try to go to the
next page. the form will be cleared and table showing no records.
I have another page does similar things, the only different is that that
form only includes a text field, a select and submit button without
fieldset.
Currently my work around is setting the page back to stateful again, seems
working fine.
here are some relevant code snippet in the page.
on init method:
public void onInit()
{
super.onInit();
Context context = getContext();
// Restore form and table state from the session
form.restoreState(context);
table.restoreState(context);
table.getControlLink().setActionListener(new ActionListener() {
public boolean onAction(Control source) {
form.saveState(getContext());
table.saveState(getContext());
return true;
}
});
buttons listener method:
public boolean onSubmitClicked(){
try{
form.saveState(getContext());
return true;
}catch(Exception e)
{
msg = " Failed due to: " + e.toString();
getContext().setFlashAttribute("flash", msg);
}
return false;
}