PrimeFaces数据表的渲染属性不起作用

时间:2015-12-04 17:59:00

标签: post jsf-2 primefaces javabeans rendered-attribute

我有一个primeface表,根据搜索结果显示存储在名为notificationList的List中的数据库中的数据。我希望在单击提交按钮后显示表格但是在我添加渲染属性之后表格根本不显示。有人可以告诉我我做错了什么以及如何解决它?我尝试了两种方法来做到这一点。

  1. 使用render = #{not empty notificationSearchBean.results.notificationList}即使列表不为空也无效(我知道bc我在控制台中打印出结果)
  2. 在此帖子“Want to show a data table populated with data after a button click”中创建一个名为visible的布尔值。无论visible是设置为true还是false,这也都不显示表。奇怪的是,我尝试使用true初始化visible,而表仍未呈现。
  3. 这是我的表格代码:

     <h:panelGroup id = "table-wrapper" styleClass="searchResults">
        <h:form id="result" >
            <p:dataTable id="notTable" var="notifications" value="#{notificationSearchBean.results.notificationList}"  row="15">
                <p:column headerText="Notification No.">
                    <h:outputText value="#{notifications.notificationNo}"/>
                </p:column>  
                <p:column headerText="Service">
                    <h:outputText value="#{notifications.srvce}"/>
                </p:column>  
                <p:column headerText="Operation">
                    <h:outputText value="#{notifications.oprtn}"/>
                </p:column>
                <p:column headerText="Service Version">         
                    <h:outputText value="#{notifications.srvceVrsn}"/>
                </p:column>
                <p:column headerText="Event Date">
                    <h:outputText value="#{notifications.evntDt}" >
                        <f:convertDateTime pattern="dd-MMM-yyyy 'at' HH:mm:ss.SSS" />
                    </h:outputText>
               </p:column>
            </p:dataTable>                              
        </h:form>
    </h:panelGroup>
    

    提交按钮的代码:

    <h:panelGrid align="center" columns="2">
        <p:commandButton value="Start Search" action="#{notificationSearchBean.getAllNotificationsForQuery}" update="table-wrapper"/> 
    </h:panelGrid>
    

    NotificationSearchBean:

    @ManagedBean(name = "notificationSearchBean" )
    @SessionScoped
    public class NotificationSearchBean implements Serializable {
    
        private static final long serialVersionUID = 1L;
        private TransactionsDao transactionsDao = (TransactionsDao)((Login)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("login")).getTransDao();
        @Inject
        private SearchCriteria search;
        @Inject 
        private ResultSet results; 
    
        @PostConstruct
        public void initialize() {
            //setting attributes for search form        
        }
    
        //getters and setters for search
    
        public ResultSet getResults() {
            return results;
        }
    
        public void setResults(ResultSet results) {
            this.results = results;
        }
    
        public String getAllNotificationsForQuery() {   
            List<NotificationLogT> notifications=transactionsDao.getAllNotifications(this.search);
            int temp=notifications.size();
            this.results.setNotificationList(notifications);
    
            if(temp==0){
                //prints out not results return message
            }
            return "success";
        }
    }
    

    还有ResultSet类:

    public class ResultSet implements Serializable {
        private List<NotificationLogT> notificationList;
        private boolean visible = false;
        //private Integer dataSize;
    
        public boolean isVisible() {
            return visible;
        }
    
        public void setVisible(boolean visible) {
            this.visible = visible;
        }
    
        public List<NotificationLogT> getNotificationList() {
            setVisible(true);
            return notificationList;
        }
    
        public void setNotificationList(List<NotificationLogT> notificationList) {
            this.notificationList = notificationList;   
        }
    }
    

0 个答案:

没有答案