简体   繁体   中英

New .xhtml pages won't render any jsf tags but previously created ones still work fine in same project

I have a really weird and stupid problem that has be stopped dead. I have numerous xhtml pages that use forms and they all work fine. I created a new xhtml page called registerUser.xhtml. I created it by right clicking on "Web pages" folder and selecting new > xhtml page as I have done for the other half a dozen pages. I put in my code and when I go to view the page in a web browser, it shows nothing. If I view source, it shows the JSF tags, NOT the html. If I put any code or just plain text outside of the form tags, it displays so its something with the form tag. Even If i take a perfectly working page and copy/past into this new page, it still does not work.

Here's one thing that I noticed,

Typically when I create ac:, h: or f: tag for the first time in a page, I get an error saying its not bound, then I single click on it and hit alt-enter and it gives me the option to add something, which adds the xlmns:h to the html tag. I don't fully understand how that works but its something with namespaces...anyway, for whatever reason that option doesnt show up...the only option that shows up is "Remove surrounding tag" which obviously does not fix my problem if i actually click it.

So no big deal that it doesnt auto-add the xmlns, I can add that myself, copying exactly what I have on another page...but nope, still nothing. Why doesnt this work?

I've tried creating numerous new xhtml files in this project and the result is the same on form elements, nothing inside is rendered and it shows that error.

All my previous pages work fine. I've read on the internet about changing WEB-INF files but it doesnt make sense that I should have to since my already-existing pages work, its just new pages and nothing has changed recently that I'm aware of.

I should also point out that I did a right click copy/paste within the projects window of my index.xhtml file which works totally fine and then when I run the project, index.xhtml loads up fine but when I manually navigate to index_1.xhtml (which is the pasted version), none of the JSF is rendered.

registerUser.xhtml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <head>
        <title>Jadestar's PC Solutions</title>
    </head>
    <body>
        <h:form>
            <h:panelGrid>
            <h:outputLabel value="Username: " style="font-weight:bold" />
            <h:inputText value="#{CustomBuild.username}" />
            <br></br>
            <h:outputLabel value="Password: " style="font-weight:bold" />
            <h:inputSecret value="#{CustomBuild.password}" />
            <br></br>
            <h:outputLabel value="Name: " style="font-weight:bold" />
            <h:inputText value="#{CustomBuild.name}" />
            <br></br>
            <h:outputLabel value="Address " style="font-weight:bold" />
            <h:inputText value="#{CustomBuild.address}" />
            <br></br>
            <h:outputLabel value="Phone Number: " style="font-weight:bold" />
            <h:inputText value="#{CustomBuild.phone}" />
            <br></br>
            <h:outputLabel value="Email Address: " style="font-weight:bold" />
            <h:inputText value="#{CustomBuild.email}" />
            <br></br>
            </h:panelGrid>
            <h:commandButton id="register" value="Reigster" action="#{CustomBuild.registerUser()}"/>
        </h:form>
        <br></br>
        <h:form>
            <h:commandButton id="cancel" value="Cancel" action="index" />
        </h:form>
    </body>
</html>

So after copying and creating a ton of new projects and doing a lot of research, I found out that if I made a new web project, the index.xhtml page would also work fine but any new pages created in THAT project would also fail to render JSF tags. I finally found out the issue. In my web.xml in the WEB-INF directory, I was missing the following line.

    <url-pattern>*.xhtml</url-pattern>

Which is inside the tag.

So by adding this, suddenly my new jsf pages are now working...but my question remains, how are my current pages working without this tag and not new ones? It doesnt make sense.

Cache issue? Enabled console in chrome and "empty cache and hard reload" and still the same result so it can't be cache, can it?

I should mention that about half way through this project, I updated from Netbeans 7.xx, Java 7.x and Glassfish 3.x to Netbeans 8, Java 8 and GlassFish 4. Since everything was still working with my current pages after this upgrade, I assumed this wasn't the cause but perhaps something in there broke?

Would be nice to hear from someone who either has an explanation or had a similar problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM