I have a problem with loading Facelets pages from Javascript. I’m working with Netbeans 7.2, Glassfish 3.1.2 and Java EE 6.
I made a simple test page:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<script type="text/javascript">
window.location.href = "index.xhtml";
</script>
<title>winq match!</title>
</h:head>
<h:body>
<h1>WING MATCH!!</h1>
<h:form>
<h:commandButton id="Next" value="weiter" action="index"/>
</h:form>
</h:body>
The index.xhtml page that should be loaded with window.location.href is:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:outputText value="TestTestTestTestTest"/>
msg <h:inputText id="ema" value="#{testBean.inputValue}" maxlength="1" />
<h:commandButton id="but" value="Submit" action="index"/>
</h:form>
</h:body>
The page is loaded but not parsed and thus the h: tags are not interpreted by the browser. After searching the web on this it seems that I’m the only one with a problem like this. Maybe I´ve misunderstood some aspects of JSF. I hope to get some advise on this.
You need to make sure that the request URL matches the URL pattern of the
FacesServletas definied in webapp’sweb.xml. It’s namely the one responsible for performing all the JSF/Facelets works.For example, if you’ve mapped it on
*.jsf, then you should open the page on exactly that URL pattern so that theFacesServletis properly invoked and will locate theindex.xhtmlfile and do all the necessary stuff.Alternatively, you can also change the URL pattern of the
FacesServletto*.xhtml. This way you never need to worry about virtual URLs.See also: