jsf 2 - How do I combine JSF Ajax with Bookmark-able views? -


i have p:datatable , number of controls change content such page number, sort, , filter parameters. controls invoke ajax interaction each change invokes sql query end, updates table in client browser. that's way supposed be, right?

what can't figure out best practice making view bookmark-able. easy enough bookmark parameters backing bean such as:

        <f:metadata>             <f:viewparam name="orderno" value="#{bean.orderno}" />             <f:viewparam name="sortorder" value="#{bean.sortorder}" />             <f:viewparam name="showopenitems" value="#{bean.showopenitems}" />                        <f:viewparam name="page" value="#{bean.page}" />             <f:viewparam name="pagesize" vlaue="#{bean.pagesize}" />         </f:metadata> 

so add radiobutton control change sortorder. might this:

<p:selectoneradio value="#{bean.sortorder}">    <p:ajax update="@form" />    <f:selectitem itemlabel="xxx" itemvalue="1" />       (etc) </p:selectoneradio> 

first question: when ajax enabled control fired there way preserve other parameters such orderno without resorting viewscoped bean?

second question: how browser's url bar update if user bookmarks page, current table query parameters preserved?

much help.

you can add parameters component using <f:param> , reading request scoped backing bean. can use omnifaces components.getparams(uicomponent) function.

<p:selectoneradio value="#{bean.sortorder}">     <p:ajax listener="#{bean.reload()}" update="@form" />     <f:selectitem itemlabel="xxx" itemvalue="1" />      <f:param name="orderno" value="#{bean.orderno}"/> </p:selectoneradio> 

retrieve params component in request bean:

public void reload() {     final facescontext context = facescontext.getcurrentinstance();     final uicomponent component = uicomponent.getcurrentcomponent(context);      list<paramholder> params = components.getparams(component);      // extract orderno param , reload datasource } 

to update browser url can either perform get-requests instead of ajax or can manipulate using javascript history api.

for first part can use utility request bean function in ajax or command components.

/**  * redirects given outcome building bookmarkable url using  * child uiparameter's of current component.  *  * @param outcome  * @param includeviewparam  *  * @return  */ public void performactionparams(final string outcome, boolean includeviewparam) {     final facescontext context = facescontext.getcurrentinstance();     final uicomponent component = uicomponent.getcurrentcomponent(context);      list<paramholder> params = components.getparams(component);      string url = faceslocal.getbookmarkableurl(context, outcome, params, includeviewparam);     facescontextutils.redirect(context, url); } 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -