0

I want to send a mysql request and display the results in a datatable.

I'm using jsf 2.2 and Glassfish server 4.1.1. I've checked several threads in this website but didn't manage to find what I'm doing wrong, which started trying to adapt the project of this website:

http://www.java2s.com/Tutorials/Java/JSF/1900__JSF_DataTable_Add_Delete.htm

So basically I used the code in the UserBean.java but instead of using the demo.xhtml I'm using my own xhtml which is based in it as well:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"   
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
    </h:head>
    <h:body>


        <h:dataTable value="#{book.bookList}" var="o"
                     styleClass="book-table"
                     headerClass="book-table-header"
                     rowClasses="book-table-odd-row,book-table-even-row">
            <h:column>
                <f:facet name="header">Book No</f:facet>#{o.bookNo}
            </h:column>
            <h:column>
                <f:facet name="header">Product Name</f:facet>#{o.productName}
            </h:column>
            <h:column>
                <f:facet name="header">Price</f:facet>#{o.price}
            </h:column>
            <h:column>
                <f:facet name="header">Quantity</f:facet>#{o.qty}
            </h:column>
            <h:column>
                <f:facet name="header">Action</f:facet>
                <h:commandLink value="Delete" action="#{book.deleteAction(o)}" />
            </h:column>
        </h:dataTable>

    </h:body>
</html>

But instead of displaying the table like this:

Book No Product Name    Price     Quantity      Action
1       CSS             123.12    1             Delete
2       HTML            321.12    2             Delete
3       SQL             12333.3   8             Delete
4       Javascript      1233.33   3             Delete
5       Web             123.22    10            Delete

I get this:

Book No#{o.bookNo} Product Name#{o.productName} Price#{o.price} Quantity#{o.qty} Action

So I'm guessing I'm missing some jar or library? the project includes plenty of them while I only have this one: mysql-connector-java-8.0.15.jar.

For starters I'd like to know which libraries are required to do this operation, since I just don't want to copy/paste everything without knowing what it's used for.

Thanks in advance.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Jack M.
  • 51
  • 7
  • Do a view-source on the client and check if jsf is working at all (I doubt it is) and as a suggestion, go to the jsf tag page on stackoveflow and pick a modern tutorial – Kukeltje Jun 05 '19 at 07:14
  • @Kukeltje I don't know if you mean this, but I checked on chrome and the code was there without any error or anything unusual. Also I've been browsing through this [link](https://stackoverflow.com/tags/jsf/info.) and I can't seem to find any tutorial. There's a mention to the libraries but I still don't know for sure which ones should I use in my case, so can you be more specific? sorry for the inconvenience, there's just tons of information and I can't find what I'm looking for. – Jack M. Jun 06 '19 at 16:36
  • Seriously? NO tutorial in there? There is whole section on 'online tutorials' in there. And 'all the code was there' meaning an `h:datatable` too? – Kukeltje Jun 06 '19 at 18:00
  • @Kukeltje First, no need to be rude. Secondly, I'm not blind, I did see the 'Online tutorials' section, I eyed quickly the one I need (Java EE 7 tutorial - JSF 2.2) and couldn't find what I need. That's what I meant by 'can't seem to find any tutorial'. And yes, including `h:datatable` too. As I said before, I downloaded that project example, it works well and I can display the table, but when I copy and adapt the UserBean.java and demo.xhtml code into my own it doesn't work, probably because I need some library or my project lacks something I don't know what it is. – Jack M. Jun 06 '19 at 19:21
  • I was not being 'rude' I was surprised. Being a developer means being specifoc and if you state you did not find any tutorial I assume that is 'specific' and am surprised. you did not find any. And if you seriously see and `h:datatable` then please start with a JSF 'helloworld' exaple since most likely a basic `h:outputText` won't do anytihng either. https://stackoverflow.com/questions/3112946/jsf-returns-blank-unparsed-page-with-plain-raw-xhtml-xml-el-source-instead-of-re – Kukeltje Jun 06 '19 at 20:40
  • @Kukeltje sorry for not bing more specific, I will take it into account. I've been doing some tests and noticed that if I used 'Run file' in the file itself I could see the table, but I couldn't see it when I get to that same file by navigating from index.xhtml. `h:outputText` worked, but I checked your link and I saw my problem wasn't the libraries but that I had the `` and `` wrong, so changing the `` from `/faces/*` to `*.xhtml` did the trick. Thank you very much! – Jack M. Jun 09 '19 at 22:01
  • Great it works! Congrats.Those are in modern jsf the defaults btw and do not need to be configured (as a decent jsf 2.2 tutorial will tell you) – Kukeltje Jun 10 '19 at 05:43

0 Answers0