jsf bean not working -
this xhtml:
<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>keep alive</title> </h:head> <f:metadata> <f:viewparam name="value" id="value" value="#{mybean.val}" ></f:viewparam> </f:metadata> <h:body> hello.<h:form><h:outputlabel value="#{mybean.val}"></h:outputlabel></h:form> </h:body> </html>
and bean:
import javax.faces.bean.requestscoped; import javax.faces.bean.managedbean; import javax.persistence.entitymanager; import javax.persistence.persistencecontext; @requestscoped @managedbean public class mybean { @persistencecontext(unitname = "mypuhere") private entitymanager em; /** * creates new instance of mybean */ public mybean() { system.out.println("mybeanload"); if (getwaarde() == "yes") { system.out.println("it works!!"); } } private string val; public string getval() { system.out.println("getting value"); return val; } public void setval(string value) { system.out.println("setting value " + value); this.val = value; } }
my bean not respond this, don't see here? not display value enter in url, nor displays outputlabel.
so, you're retrieving raw jsf source code in browser instead of generated html output. browsers don't understand jsf code (like doesn't understand jsp/php/asp/etc code), understands html code. can happen when facesservlet
hasn't been invoked, it's namely 1 responsible jsf works.
perhaps facesservlet
based on tutorial or ide-autogenerated code been mapped on url pattern different *.xhtml
, such *.jsf
or *.faces
. in case, you've 2 options:
fix request url in browser's address bar match url pattern. so, assuming it's
*.jsf
, don't open page byhttp://localhost:8080/context/index.xhtml
but instead by
http://localhost:8080/context/index.jsf
fix url pattern
*.xhtml
directly. wasn't possible in jsf 1.xfacesservlet
otherwise call in infinite loop, quite possible in jsf 2.x , lot of books/tutorials/resources/ides didn't take account.<url-pattern>*.xhtml</url-pattern>
Comments
Post a Comment