0

I have a primeface table that shows data from an database stored in a List called notificationList based on a search from. I want the table to be displayed after the submit button is clicked however after I add the rendered attribute the table not displaying at all. Can someone tell what I'm doing wrong and how to fix it? I've tried two methods to do this.

  1. Using rendered=#{not empty notificationSearchBean.results.notificationList} which didn't work even though the list isn't empty (I know bc I printed out the results in the console)
  2. Creating a boolean called visible like in this post "Want to show a data table populated with data after a button click". This also isn't displaying the table regardless of whether visible is set to true or false. What's weird is that I've tried initializing visible with true and the table is still not being rendered.

This is my code for the table:

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

And code for the submit button:

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

And the 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";
    }
}

And also the ResultSet class:

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;   
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Jenna Deng
  • 31
  • 1
  • 10
  • It should be "rows" in the datatable. Also you seem to be mixing jsf beans and CDI beans, depending on server replace "@ManagedBean" with "@Named" and check up on which package "@SessionScoped" import is from (and btw. normally it would be "@ViewScoped") – Jaqen H'ghar Dec 04 '15 at 19:14
  • What do you mean by rows?And I've tried replacing it with `@viewScope` and `@Named` but it still doesn't work :-/ – Jenna Deng Dec 04 '15 at 19:38
  • row="15" is wrong. add rows="15" – Mahendran Ayyarsamy Kandiar Dec 04 '15 at 22:10

0 Answers0