Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 如何将JSF Ajax与可添加书签的视图结合起来?_Jsf 2 - Fatal编程技术网

Jsf 2 如何将JSF Ajax与可添加书签的视图结合起来?

Jsf 2 如何将JSF Ajax与可添加书签的视图结合起来?,jsf-2,Jsf 2,我有一个p:dataTable和许多控件,可以更改其内容,如页码、排序和筛选参数。这些控件调用AJAX交互,以便每次更改都会向后端调用SQL查询,但只更新客户端浏览器中的表。应该是这样的,对吧 我搞不清楚的是使视图书签成为可编辑的最佳实践。将书签参数放入支持bean中非常容易,例如: <f:metadata> <f:viewParam name="orderNo" value="#{bean.orderNo}" />

我有一个p:dataTable和许多控件,可以更改其内容,如页码、排序和筛选参数。这些控件调用AJAX交互,以便每次更改都会向后端调用SQL查询,但只更新客户端浏览器中的表。应该是这样的,对吧

我搞不清楚的是使视图书签成为可编辑的最佳实践。将书签参数放入支持bean中非常容易,例如:

        <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>

假设我添加一个radioButton控件来更改排序器。可能是这样的:

<p:selectOneRadio value="#{bean.sortOrder}">
   <p:ajax update="@form" />
   <f:selectItem itemLabel="xxx" itemValue="1" />
      (etc)
</p:selectOneRadio>

(等)
第一个问题:当启动这个支持AJAX的控件时,是否有任何方法可以保留其他参数,例如orderNo,而不必求助于ViewScoped bean

第二个问题:如何更新浏览器的URL栏,以便在用户为页面添加书签时,保留所有当前表查询参数


非常感谢您的帮助。

您可以使用
将参数添加到任何组件,并从请求范围的支持bean中读取参数。您可以使用OmniFaces
Components.getParams(UIComponent)
函数

<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>

从请求bean中的组件检索参数:

public void reload()
{
    final FacesContext context = FacesContext.getCurrentInstance();
    final UIComponent component = UIComponent.getCurrentComponent(context);

    List<ParamHolder> params = Components.getParams(component);

    // extract orderNo param and reload your datasource
}
public void reload()
{
final FacesContext context=FacesContext.getCurrentInstance();
最终UIComponent=UIComponent.getCurrentComponent(上下文);
List params=Components.getParams(component);
//提取orderNo参数并重新加载数据源
}
要更新浏览器URL,您可以执行GET请求而不是ajax,也可以使用javascript历史API对其进行操作

第一部分,您可以在ajax或命令组件中使用这个实用程序请求bean函数

/**
 * Redirects to the given outcome by building a bookmarkable URL using all
 * child UIParameter's of the 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);
}
/**
*通过使用all构建可书签的URL重定向到给定结果
*当前组件的子参数。
*
*@param结果
*@param includeViewParam
*
*@返回
*/
公共void性能参数(最终字符串结果,布尔includeDeviceParam)
{
final FacesContext context=FacesContext.getCurrentInstance();
最终UIComponent=UIComponent.getCurrentComponent(上下文);
List params=Components.getParams(component);
字符串url=FacesLocal.getBookmarkableURL(上下文、结果、参数、includeViewParam);
重定向(上下文,url);
}