Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.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 primefaces中的分页行值_Jsf_Primefaces_Datatable_Paginator - Fatal编程技术网

动态更改jsf primefaces中的分页行值

动态更改jsf primefaces中的分页行值,jsf,primefaces,datatable,paginator,Jsf,Primefaces,Datatable,Paginator,在这种情况下,我需要在Datatable中持久化rows属性的值,并需要从托管bean中更改它。我目前正在使用JSF3.4.1 考虑下面的示例代码 <p:dataTable var="car" value="#{dtPaginatorView.cars}" rows="10" paginator="true" paginatorTemplate="{CurrentPageReport} {FirstPage

在这种情况下,我需要在Datatable中持久化rows属性的值,并需要从托管bean中更改它。我目前正在使用JSF3.4.1

考虑下面的示例代码

<p:dataTable var="car" value="#{dtPaginatorView.cars}" rows="10"
                     paginator="true"
                     paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                     rowsPerPageTemplate="5,10,15">

我希望它像

 <p:dataTable var="car" value="#{dtPaginatorView.cars}" rows="#{dtPaginatorView.rows}"
                     paginator="true"
                     paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                     rowsPerPageTemplate="5,10,15">

因此,我可以将“rows”值绑定到托管bean变量,我可以根据逻辑条件对其进行更改。也可以跟踪当前选择的“rowsPerPageTemplate”值


非常感谢您对此提供的任何帮助。

根据OP的要求,我现在就做这件事。我为每个用户存储行,这样我的应用程序的每个用户都可以设置自己的“行”值并将其持久化

XHTML:

<p:dataTable var="row" 
             rowKey="#{row.id}" filterEvent="enter"
             value="#{auditTrailDatatable.values}"
             filteredValue="#{auditTrailDatatable.filteredValues}" 
              paginatorTemplate="#{appmsg['datatable.paginator']}" 
              paginator="true" 
              rows="#{applicationUser.rowsPerPage}" 
              rowsPerPageTemplate="#{appmsg['datatable.rowsperpage']}">
public class ApplicationUser  {

   /** How many rows per page to display in datatables */
   @Column(name = "ROWS_PER_PAGE", length = 19, nullable = false)
   @Min(value = 5)
   private Integer rowsPerPage;

   public final Integer getRowsPerPage() {
      return rowsPerPage;
   }

   public final void setRowsPerPage(final Integer rowsPerPage) {
      this.rowsPerPage = rowsPerPage;
   }

}
@SessionScoped
public class ApplicationUserProvider implements Serializable {

   /** Logger for this class */
   private static final Logger LOG = LoggerFactory.getLogger(ApplicationUserProvider.class);
   private static final long serialVersionUID = 1L;

   /** Servlet request for this invocation */
   @Inject
   HttpServletRequest request;

   /** The DAO used to update the local application user entity */
   @Inject
   ApplicationUserRepository applicationUserRepository;

   /** State Variable: Cached copy of the current ApplicationUser record */
   private ApplicationUser applicationUser;

   /**
    * Called on user session initialization. Ensures that we have an Application
    * user record for the current user.
    */
   @PostConstruct
   public void init() {
      try {
         final Principal currentUser = request.getUserPrincipal();
         final String userName = StringUtils.upperCase(currentUser.getName());

         // attempt to locate our ApplicationUser record for the currently
         // authenticated User
         applicationUser = applicationUserRepository.find(userName);
         if (applicationUser == null) {
            applicationUser = ApplicationUser.createApplicationUser(userName);
            applicationUser.setLastLoginTime(DateTime.now().toDate());
            applicationUserRepository.persist(applicationUser);
         } else {
            applicationUser.setLastLoginTime(DateTime.now().toDate());
            applicationUser = applicationUserRepository.merge(applicationUser);
         }

         LOG.info("User '{}' logged in.", userName);
      } catch (final Exception ex) {
         LOG.error("Unexpected Exception with UserPrincipal: {}", ExceptionUtils.getRootCauseMessage(ex), ex);
         throw ex;
      }
   }

   /**
    * The currently logged in {@link ApplicationUser} being provided for
    * injection in other classes and exposed on the UI with @Named.
    *
    * @return the {@link ApplicationUser} object representing the currently
    *         logged in user.
    */
   @Produces
   @Named
   @LoggedIn
   public ApplicationUser getApplicationUser() {
      return applicationUser;
   }

}
UI提供程序:

<p:dataTable var="row" 
             rowKey="#{row.id}" filterEvent="enter"
             value="#{auditTrailDatatable.values}"
             filteredValue="#{auditTrailDatatable.filteredValues}" 
              paginatorTemplate="#{appmsg['datatable.paginator']}" 
              paginator="true" 
              rows="#{applicationUser.rowsPerPage}" 
              rowsPerPageTemplate="#{appmsg['datatable.rowsperpage']}">
public class ApplicationUser  {

   /** How many rows per page to display in datatables */
   @Column(name = "ROWS_PER_PAGE", length = 19, nullable = false)
   @Min(value = 5)
   private Integer rowsPerPage;

   public final Integer getRowsPerPage() {
      return rowsPerPage;
   }

   public final void setRowsPerPage(final Integer rowsPerPage) {
      this.rowsPerPage = rowsPerPage;
   }

}
@SessionScoped
public class ApplicationUserProvider implements Serializable {

   /** Logger for this class */
   private static final Logger LOG = LoggerFactory.getLogger(ApplicationUserProvider.class);
   private static final long serialVersionUID = 1L;

   /** Servlet request for this invocation */
   @Inject
   HttpServletRequest request;

   /** The DAO used to update the local application user entity */
   @Inject
   ApplicationUserRepository applicationUserRepository;

   /** State Variable: Cached copy of the current ApplicationUser record */
   private ApplicationUser applicationUser;

   /**
    * Called on user session initialization. Ensures that we have an Application
    * user record for the current user.
    */
   @PostConstruct
   public void init() {
      try {
         final Principal currentUser = request.getUserPrincipal();
         final String userName = StringUtils.upperCase(currentUser.getName());

         // attempt to locate our ApplicationUser record for the currently
         // authenticated User
         applicationUser = applicationUserRepository.find(userName);
         if (applicationUser == null) {
            applicationUser = ApplicationUser.createApplicationUser(userName);
            applicationUser.setLastLoginTime(DateTime.now().toDate());
            applicationUserRepository.persist(applicationUser);
         } else {
            applicationUser.setLastLoginTime(DateTime.now().toDate());
            applicationUser = applicationUserRepository.merge(applicationUser);
         }

         LOG.info("User '{}' logged in.", userName);
      } catch (final Exception ex) {
         LOG.error("Unexpected Exception with UserPrincipal: {}", ExceptionUtils.getRootCauseMessage(ex), ex);
         throw ex;
      }
   }

   /**
    * The currently logged in {@link ApplicationUser} being provided for
    * injection in other classes and exposed on the UI with @Named.
    *
    * @return the {@link ApplicationUser} object representing the currently
    *         logged in user.
    */
   @Produces
   @Named
   @LoggedIn
   public ApplicationUser getApplicationUser() {
      return applicationUser;
   }

}

在rows=“dtPaginatorView.rows”周围缺少大括号,它应该是rows=“#{dtPaginatorView.rows}”。我在我所有的应用程序中都这样做,并保留行。它工作正常。对不起,我在键入时错过了它。当我使用大括号时,值是持久的,但分页不起作用。您能否将您的示例与XHTML文件和相关的托管bean共享