Results 1 to 2 of 2
  1. #1
    tronied is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default JSF with linked h:dataTable blank

    Hello,

    As a beginner, I am trying to work on an example MessageBoard example. So far, I have a login page with a backing bean which works fine. If it finds my user in persistence, it allows me onto the next page (called threads.xhtml). In this, I am trying to use a h:dataTable to list the threads, but no matter what I try it always lists as a blank table with the headers showing. I have a singleton initial bean which adds some threads, so I know its not blank.

    Here is the threads.xml.
    Java Code:
            <h1>Welcome #{authorize.username}!</h1>
            <h:outputText value="List is empty" rendered="#{listThreads.listEmpty}"/>
            <h:dataTable value="#{listThreads.allThreads}" var="userThread" rendered="#{!listThreads.listEmpty}">
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="User" />
                    </f:facet>
                    <h:outputText value="#{userThread.ownerUser}" />
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Title" />
                    </f:facet>
                    <h:outputText value="#{userThread.title}" />
                </h:column>
                <h:column>
                    <f:facet name="header">
                        <h:outputText value="Posts" />
                    </f:facet>
                    <h:outputText value="#{userThread.postsCount}" />
                </h:column>
            </h:dataTable>
    One thing you may notice is that if it finds the list is blank, I display a label. Unforunately, neither the label or any data shows. I tried printing a simple "hello world" message from a function in the bean, but it comes back as blank. The backing code is pretty simple:

    Java Code:
    @Stateless
    @Named
    @Path("/threads/")
    public class ListThreads {
        @PersistenceContext
        private EntityManager em;
        private List<UserThread> allThreads;
        private Logger logger = Logger.getLogger("messageboard.ejb.ListThreads");
    
        public List<UserThread> getAllThreads() {
            logger.info("Calling getAllThreads");
            this.allThreads = (List<UserThread>) em.createNamedQuery(
                        "messageboard.entity.UserThread.getAllThreads")
                                                    .getResultList();
    
            if (this.allThreads.equals(null)) {
                logger.warning("No current events!");
            }
    
            return this.allThreads;
        }
        
        public boolean isListEmpty() {
            return allThreads.isEmpty();
        } 
    }
    I don't think I need the path in there as I am not making any jax-rs calls, but was trying to use the rsvp from the tutorial as an example. I have tried to debug on the getAllThread(), but it never gets called (which is the problem). Netbeans knows about my bean class as it lists the various properties in the code completion. I can't see anything wrong, and am getting a bit stuck now on things to try.

    Can any of you spot the reason why the stateless bean would not initialize / work? Sorry if its a simple fix, but I am new to this.

    Thanks in advance :)

  2. #2
    tronied is offline Member
    Join Date
    Mar 2011
    Posts
    7
    Rep Power
    0

    Default

    Ok, after playing around a bit more I can't get the getAllThreads() method to be called automatically. However, what I have done is to make the class a managed bean, and call the getAllThreads() from the isListEmpty() which gets called upon page load e.g.

    Java Code:
        public boolean isListEmpty() {
            getAllThreads();
            return allThreads.isEmpty();
        }
    This is probably not the way its supposed to be done, but its working at least. I am a bit confused though as in the rsvp example, the StatusBean which was almost a replica of mine had its getAllCurrentEvents() called automatically when the page was loaded. My bean wasn't even loaded by the looks and remained null and returned blanks when it was called. Maybe I am missing something from the web.xml or sun-web.xml :confused:

Similar Threads

  1. problem on refreshing h:dataTable
    By irakli_java_dev in forum JavaServer Faces (JSF)
    Replies: 4
    Last Post: 03-23-2011, 07:15 AM
  2. problem with delete row from <h:dataTable>
    By irakli_java_dev in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 01-21-2011, 06:36 AM
  3. Filtering data in a JSF dataTable
    By Iori Yagami in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 03-18-2010, 12:17 AM
  4. JSF datatable with calendar component
    By thilak in forum JavaServer Faces (JSF)
    Replies: 3
    Last Post: 06-25-2009, 08:53 AM
  5. Row id in datatable
    By nc_newie in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 06-26-2008, 12:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •