0

I am using jsf version 2.2.12 in Netbeans 8.2. The project is to take information from a database: Database setup for reference. Using MySQL in phpmyadmin with WAMP Currently, everything runs fine if I right click index, and run it. Image of webpage working properly However, if I run the whole project, the page loads in basic html, with no bean functions, etc.Picture of problem

We are learning to use the info from the database to populate a template fragment, so that there doesn't need to be a page for every item.

Here is my bean that pretty much runs everything:

    String curProduct;
    String curDesc;
    String curImage;
    double curPrice;
    int curQty;

    public String getCurProduct() {
        return curProduct;
    }

    public void setCurProduct(String curProduct) {
        this.curProduct = curProduct;
    }

    public String getCurDesc() {
        return curDesc;
    }

    public void setCurDesc(String curDesc) {
        this.curDesc = curDesc;
    }

    public String getCurImage() {
        return curImage;
    }

    public void setCurImage(String curImage) {
        this.curImage = curImage;
    }

    public double getCurPrice() {
        return curPrice;
    }

    public void setCurPrice(double curPrice) {
        this.curPrice = curPrice;
    }

    public int getCurQty() {
        return curQty;
    }

    public void setCurQty(int curQty) {
        this.curQty = curQty;
    }


    public void changeProduct(String click) throws SQLException, IOException {
        Connection con = connection();
        if (con == null) {
            System.out.println("Cannot connect to database");
            return;
        } else {
            try {
                Statement stmt = con.createStatement();
                ResultSet result = stmt.executeQuery("Select itemName, itemDesc, qty, price, image FROM inventory WHERE itemId = '" + click +"'");
                ResultSetMetaData rsmd = result.getMetaData();
                int columnsNumber = rsmd.getColumnCount();
                while (result.next()) {
                    for (int i = 1; i <= columnsNumber;) {
                        curProduct = result.getString(i);
                        curDesc = result.getString(i + 1);
                        curQty = result.getInt(i + 2);
                        curPrice = result.getDouble(i + 3);
                        curImage = result.getString(i + 4);
                        i += 5;
                    }
                }
                FacesContext.getCurrentInstance().getExternalContext().redirect("product.xhtml");
            } finally {
                con.close();
            }
        }
    }

and here is the product.xhtml page:

<?xml version='1.0' encoding='UTF-8' ?>
<!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://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f5="http://xmlns.jcp.org/jsf/passthrough"
      xmlns:p="http://primefaces.org/ui">

    <h:head>
        <title></title>
    </h:head>
    <h:body>
        <ui:composition template="template/layout.xhtml">     

            <ui:param name="wrapperWidth" value="1055px"/>

            <ui:define name="title">
                Electronics Emporium Store Page
            </ui:define>

            <ui:define name="login">
                <h:form style="#{loginBean.loginBarStyles}">
                    <h:inputText styleClass="inputs" value="#{loginBean.userName1}" f5:type="email" f5:placeholder="E-mail"/>            
                    <h:inputSecret  styleClass="inputs" value="#{loginBean.password1}" f5:placeholder="Password"/>            
                    <h:commandButton styleClass="lbutton" value="Login" action="#{loginBean.login()}"/>
                </h:form>
                <p id="login_bar" style="#{loginBean.loginInfoStyles}">Welcome #{loginBean.userName1}!</p>
            </ui:define>

            <ui:param name="search" value="true"/>
            <ui:define name="search">
                <h:form>
                    <h:inputText styleClass="inputs" value="#{itemsBean.searchTerm}" f5:type="search" f5:placeholder="Search"/>
                    <h:commandButton styleClass="lbutton" value="Search" action="#{itemsBean.search()}"/>
                </h:form>
            </ui:define>

            <ui:define name="logo"/>

            <ui:define name="top">     
                .:Best Supplier of Phones and Computers!:.
            </ui:define>

            <ui:define name="menu">
                <ui:include src="rafaMenu.xhtml" />
            </ui:define>

            <ui:param name="leftWidth" value="200px"/>
            <ui:define name="left">
                <ui:include src="tieredMenu.xhtml"/>
            </ui:define>

            <ui:param name="right" value="false"/>
            
            <ui:define name="content">               
                <hr/>
                <h:outputText value="#{itemsBean.curProduct}"/>
                <h:panelGrid columns="2">
                    <p:panel>
                        <h:graphicImage value="#{itemsBean.curImage}"/>
                    </p:panel>
                    <p:panel>
                        <h:outputText value="#{itemsBean.curDesc}"/>
                    </p:panel>
                </h:panelGrid>
                <h:outputText value="#{itemsBean.curPrice}"/>
                <h:outputText value="'Stock Left: ' + #{itemsBean.curQty}"/>
                <hr/>
            </ui:define>
            
            <ui:define name="bottom">
                SLCC ASDV © 2018. All Rights Reserved.
            </ui:define>

        </ui:composition>
    </h:body>
</html>

All my other pages are running correctly. I can just suffer through just running the index file, but my teacher will not. Also there is no errors, just no formatting of bean functions.

  • I've got two related remarks... [mcve] and https://stackoverflow.com/tags/jsf/info (especially the database part) – Kukeltje Feb 01 '20 at 20:46
  • Thanks for the advice, edited to fit current context. – Michael George Feb 01 '20 at 20:59
  • 1: this is not a [mcve] by a long shot 2: it won't compile, 3: still way to many template stuff referenced (don't think it is part of the problem at all) 4: if you see `#{...}` in the code, it is not CSS related but rather that JSF is not active at all https://stackoverflow.com/questions/3112946/jsf-returns-blank-unparsed-page-with-plain-raw-xhtml-xml-el-source-instead-of-re – Kukeltje Feb 02 '20 at 09:35
  • Does this answer your question? [JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output](https://stackoverflow.com/questions/3112946/jsf-returns-blank-unparsed-page-with-plain-raw-xhtml-xml-el-source-instead-of-re) – Kukeltje Feb 02 '20 at 09:35

0 Answers0