I am new to JSF.
I have done everything right as far as I know but still getting this exception
javax.el.PropertyNotFoundException: /index.xhtml #22,55 value="#{navigator.pages}": Property 'pages' not found on type Navigator
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:174)
at javax.faces.component.UIInput.getValue(UIInput.java:291)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:456)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.PropertyNotFoundException: Property 'pages' not found on type Navigator
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:266)
at javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:243)
at javax.el.BeanELResolver.property(BeanELResolver.java:353)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:97)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 40 more
I have gone through lots of post regarding this exception and they all have mentioned about bean properties and their getters/setters which I have done correctly .
Here is my code:
1) Index.html
<!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">
<!-- When you make your own projects, copy and rename sample-file-with-form.xhtml
or sample-file-no-form.xhtml. Don't copy and rename THIS file, because
this file has too many extraneous things in it. -->
<h:head>
<title>JSF 2.2: Initial Learning Project</title>
<link href="./css/styles.css" rel="stylesheet" type="text/css"/>
</h:head>
<h:body>
<h1 class="title">JSF 2.2: Initial Learning Project</h1>
<div align="center">
<fieldset>
<legend>Selected Results Page</legend>
<h:form>
Please enter the page you want to see.
<br/>
<h:inputText id="pages" value="#{navigator.pages}" /><br />
<h:commandButton value="Go to Selected Page"
action="#{navigator.choosePage}"/>
</h:form>
</fieldset>
</div>
</h:body></html>
2) My bean class - Navigator.java
import javax.faces.bean.*;
#ManagedBean
public class Navigator {
private String pages;
public String getPages() {
return pages;
}
public void setPages(String pages) {
this.pages = pages;
}
public String choosePage() {
if(pages == "page1"){
return "page1";
} else if(pages == "page2"){
return "page2";
} else {
return "page3";
}
}
3) web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<description>State saving method: 'client' or 'server' (default). See JSF Specification section 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<!-- If you go to http://host/project/ (with no file name), it will
try index.jsf first, welcome.jsf next, and so forth.
-->
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
<welcome-file>welcome.jsf</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
4)faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<!-- Empty for now. There are many uses for faces-config.xml, but
the most common are navigation rules (instead of having
the return value of the "action" method be the base filename),
bean declarations (instead of using #ManagedBean), and
properties files (aka resource bundles).
If you are not using faces-config.xml, it is perfectly legal
to omit the file entirely. But, most people prefer to have
a blank one already in their project for later use.
From JSF 2 and PrimeFaces tutorial
at http://www.coreservlets.com/JSF-Tutorial/jsf2/ -->
</faces-config>
Please help me out on this.
try equals for String
public String choosePage()
{
if(pages.equals("page1")){
return "page1";
} else if(pages.equals("page2")){
return "page2";
} else {
return "page3";
}
}
Try with the below changes.
Change filename from index.html to index.xhtml and update the same file name as mentioned below.
<welcome-file>index.html</welcome-file>
Happy coding!
Related
This question already has answers here:
How to install and use CDI on Tomcat?
(2 answers)
Closed 4 years ago.
I started to test JSF 2.3 a short time ago. But I can't get one of the most important features to work. The use of ManagedBeans. I tried a lot, using different servlet containers (Tomcat 8&9, Jetty 9.2).But nothing helped. Hope somebody can see my failure in the resources. It's frustrating. I debugged but the bean is never reached. The primefaces component works fine(the primefaces lib is not the reason). But I never get bean data. PS. I'm using myfaces but with mojarra I've got the same problem.
my bean:
import javax.enterprise.context.RequestScoped;
import javax.faces.annotation.FacesConfig;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import java.io.Serializable;
#Named(value = "sampleBean")
#RequestScoped
#FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class SampleBean implements Serializable {
private String specTitle;
private String specVersion;
private String implTitle;
private String implVersion;
public SampleBean() {
Package facesPackage = FacesContext.class.getPackage();
specVersion = facesPackage.getSpecificationVersion();
specTitle = facesPackage.getSpecificationTitle();
implTitle = facesPackage.getImplementationTitle();
implVersion = facesPackage.getImplementationVersion();
}
public String info() {
return "hello from sampleBean!";
}
public String getSpecTitle() {
return specTitle;
}
public String getSpecVersion() {
return specVersion;
}
public String getImplTitle() {
return implTitle;
}
public String getImplVersion() {
return implVersion;
}
}
my configuration bean:
import javax.faces.annotation.FacesConfig;
#FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class ConfigurationBean {
}
my facelet:
<?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"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Hello JSF 2.3</title>
<style>
.col-1 { text-align: right; }
.col-2 { font-weight: bold; }
</style>
</h:head>
<h:body>
<div style="border-style: dashed" class="ui-g">
<p:calendar mode="inline"/>
</div>
<div style="border-style: double">
<h3>Hello from JSF 2.3!</h3>
<h:panelGrid columns="2" columnClasses="col-1, col-2">
<h:outputText value="Specification:"/>
<h:outputText value="#{sampleBean.specTitle}"/>
<h:outputText value="Specification version:"/>
<h:outputText value="#{sampleBean.specVersion}"/>
<h:outputText value="Implementation:"/>
<h:outputText value="#{sampleBean.implTitle}"/>
<h:outputText value="Implementation version:"/>
<h:outputText value="#{sampleBean.implVersion}"/>
</h:panelGrid>
<p>CDI injection support: <b>#{sampleBean.facesContextValue}</b></p>
<p>Running on: <b>#{application.serverInfo}</b></p>
</div>
my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"><!-- Use web-app_4_0.xsd, version=4.0 after update to Java EE 8 -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.ENABLE_CDI_RESOLVER_CHAIN</param-name>
<param-value>truet</param-value>
</context-param>
<context-param>
<param-name>javax.faces.ENABLE_WEBSOCKET_ENDPOINT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.validator.ENABLE_VALIDATE_WHOLE_BEAN</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>0</param-value> <!-- No Cache -->
</context-param>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
my build.gradle:
plugins {
id 'war'
id 'org.gretty' version '2.2.0'
}
group 'de.danri'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
gretty{
//servletContainer="tomcat8"
//servletContainer="tomcat9"
}
dependencies {
// https://mvnrepository.com/artifact/org.apache.myfaces.core/myfaces-impl
compile group: 'org.apache.myfaces.core', name: 'myfaces-impl', version: '2.3.1'
// https://mvnrepository.com/artifact/org.apache.myfaces.core/myfaces-api
compile group: 'org.apache.myfaces.core', name: 'myfaces-api', version: '2.3.1'
// https://mvnrepository.com/artifact/org.primefaces/primefaces
compile group: 'org.primefaces', name: 'primefaces', version: '6.2'
// https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api
compile group: 'javax.servlet.jsp', name: 'jsp-api', version: '2.2.1-b03'
// https://mvnrepository.com/artifact/javax.enterprise/cdi-api
compile group: 'javax.enterprise', name: 'cdi-api', version: '2.0.SP1'
// https://mvnrepository.com/artifact/javax.websocket/javax.websocket-api
compile group: 'javax.websocket', name: 'javax.websocket-api', version: '1.1'
// https://mvnrepository.com/artifact/javax.servlet/jstl
compile group: 'javax.servlet', name: 'jstl', version: '1.2'
// https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
// https://mvnrepository.com/artifact/javax.validation/validation-api
compile group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
</beans>
faces-config.xml:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.3"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd">
</faces-config>
Thank your maress. Good adress! Solution:
I added the /META-INF/context.xml
<Context>
<Resource name="BeanManager"
auth="Container"
type="javax.enterprise.inject.spi.BeanManager"
factory="org.jboss.weld.resources.ManagerObjectFactory" />
</Context>
I added weld-servlet shaded to my dependencies:
...
compile group: 'org.jboss.weld.servlet', name: 'weld-servlet-shaded', version: '3.0.5.Final'
...
Finally I used a local tomcat to run the artifact and not the gradle 'gretty' plugin.
It seems the plugin has problems with cdi.
I have an login example, its a page where you go to Admin or Operator login...
Both of this, even with the correct credentials, end up on a servlet exception : login failed...
Here it is, hope you can help me:
Error Log:
javax.servlet.ServletException: Login failed
at org.apache.catalina.authenticator.AuthenticatorBase.doLogin(AuthenticatorBase.java:1083)
at org.apache.catalina.authenticator.AuthenticatorBase.login(AuthenticatorBase.java:1060)
at org.apache.catalina.connector.Request.login(Request.java:2692)
at org.apache.catalina.connector.RequestFacade.login(RequestFacade.java:1073)
at br.edu.unisep.bean.LoginBean.entrar(LoginBean.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.el.parser.AstValue.invoke(AstValue.java:247)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:650)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
LoginBean.java
package br.edu.unisep.bean;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
#ManagedBean
#RequestScoped
public class LoginBean {
private String login;
private String senha;
public String entrar(){
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
try {
request.login(login, senha);
//VEREFICA SE O USUARIO LOGADO E POSSUI O PAPEL ADM
if (request.isUserInRole("ADMIN")){
return "admin/indexAdmin.jsf?faces-redirect=true";
} else {
return "sistema/indexSistema.jsf?faces-redirect=true";
}
} catch (ServletException e) {
e.printStackTrace();
return "login.jsf";
}
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>exemploAcesso</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>
/login.jsf
</form-login-page>
<form-error-page>
/erroLogin.jsf
</form-error-page>
</form-login-config>
</login-config>
<security-constraint>
<web-resource-collection>
<web-resource-name>Admin</web-resource-name>
<url-pattern>/admin/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>ADMIN</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>Operador</web-resource-name>
<url-pattern>/sistema/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>OPERADOR</role-name>
</auth-constraint>
</security-constraint>
<error-page>
<error-code>403</error-code>
<location>/proibido.jsf</location>
</error-page>
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
</web-app>
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="exemploAcesso">
<Realm className="org.apache.catalina.realm.JDBCRealm"
debug="4"
driverName="org.postgresql.Driver"
connectionURL="jdbc:postgresql://localhost:5434/controle_acesso"
connectionName="postgres"
connectionPassword="r4p4dur4"
userTable="usuarios"
userNameCol="id_usuario"
userCredCol="ds_senha"
userRoleTable="papeis_usuario"
roleNameCol="id_papel"
digest="MD5"
/>
</Context>
login.xhtml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<head>
<meta charset="utf-8" />
<title>Exemplo Acesso</title>
</head>
<body>
<h:form>
Login:
<h:inputText value="#{loginBean.login}"/> <br />
Senha:
<h:inputSecret value="#{loginBean.senha}"/> <br />
<h:commandButton value="Entrar" action="#{loginBean.entrar}"/>
</h:form>
</body>
</html>
I'm using Tomcat built in functions to do it and I'm using a simple jsp that
posts the results from the form to 'j_security_check'. Whereby the fieldname used for the username is 'j_username' and for the password it is 'j_password' (I'm using Tomcat 8).
<form action="j_security_check" method="POST">
<table>
<tr>
<td><label for="username">Login:</label></td>
<td><input id="username" type="text" name="j_username" value=""></td>
</tr>
<tr>
<td><label for="password">Senha:</label></td>
<td><input id="password" type="password" name="j_password"></td>
<td><input type="submit" value="Login"/></td>
</tr>
</table>
</form>
I am currently working on a web project with Java EE and I recently decided to improve my coding thanks to frameworks Hibernate-Spring-JSF. However I encountered a problem. When I try to display the content of a managed bean, nothing is printed.
Here is the code of my managedBean :
#ManagedBean( name = "moviesBean" )
#SessionScoped
public class MoviesBean implements Serializable {
#Autowired
private transient MoviesService moviesService;
private List<Movies> moviesList;
private Movies movie;
#ManagedProperty( value = "test" )
private String genre;
#PostConstruct
public void init() {
movie = moviesService.getById( 3502914 );
System.out.println( "Id : " + movie.getImdbid() );
}
public List<Movies> getMoviesList() {
return moviesList;
}
public void setMoviesList( List<Movies> moviesList ) {
this.moviesList = moviesList;
}
public Movies getMovie() {
return movie;
}
public void setMovie( Movies movie ) {
this.movie = movie;
}
}
And the code of my jsp :
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Movies detail</title>
</head>
<body>
<f:view>
<h:outputText value="#{moviesBean.genre }"/>
</f:view>
</body>
</html>
So, as you can see I just try to print the value of the field 'genre' of the bean MovieesBean, but all I have in return is a blank page. Am I doing something wrong ? Knowing that I have not any errors on the server side (I am using Tomcat 7). Here are the jars in the build path :
Build path libs
I googled this problem several times but didn't find any solution. Thanks in advance for your help !
Here is the code of my web.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>JavaServerFaces</display-name>
<!-- Add Support for Spring -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<!-- Change to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
You are not seeing genre because your expression is incorrect. Genre is Movies's attribute. Try instead:
<h:outputText value="#{moviesBean.movie.genre}"/>
i'm using Richfaces 3.3.4 final with JSF 1.2 on a SAP NetWeaver AS 7.31.
Now im facing some Issues with dynamically showing selected Nodes from a rich:tree in a h:outputText. The selectedNodeListener is invoked correctly and the Name of the Node is saved in a String, but my h:outputText only refreshes on Page Refresh and not on Selection like in the Example from the Showcases(http://showcase-rf3.richfaces.org/richfaces/tree.jsf?tab=model&cid=26981).
Does anyone know if this is a common Issue with the above Setup or am I just missing something? As far as I know SAP NetWeaver isnt in the List of supported Servers but its JEE5 compliant. Could this be the Reason?
I simplified the Example from the Richfaces Showcases to reproduce the Problem in a small Environment. Here is some Code:
SimpleTreeBean.java
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.richfaces.component.html.HtmlTree;
import org.richfaces.event.NodeSelectedEvent;
import org.richfaces.model.TreeNode;
import org.richfaces.model.TreeNodeImpl;
public class SimpleTreeBean {
private TreeNode rootNode = null;
private List<String> selectedNodeChildren = new ArrayList<String>();
private String nodeTitle;
private void loadTree() {
rootNode = new TreeNodeImpl();
TreeNodeImpl rt = new TreeNodeImpl();
rt.setData("Root");
rootNode.addChild(1, rt);
for(int i = 1; i <= 5; i++){
TreeNodeImpl child = new TreeNodeImpl();
child.setData("Child "+i);
rt.addChild(i, child);
}
}
public void processSelection(NodeSelectedEvent event) {
HtmlTree tree = (HtmlTree) event.getComponent();
nodeTitle = (String) tree.getRowData();
selectedNodeChildren.clear();
TreeNode currentNode = tree.getModelTreeNode(tree.getRowKey());
if (currentNode.isLeaf()) {
selectedNodeChildren.add((String) currentNode.getData());
} else {
Iterator<Map.Entry<Object, TreeNode>> it = currentNode
.getChildren();
while (it != null && it.hasNext()) {
Map.Entry<Object, TreeNode> entry = it.next();
selectedNodeChildren.add(entry.getValue().getData().toString());
}
}
}
public TreeNode getTreeNode() {
if (rootNode == null) {
loadTree();
}
return rootNode;
}
public String getNodeTitle() {
return nodeTitle;
}
public void setNodeTitle(String nodeTitle) {
this.nodeTitle = nodeTitle;
}
}
test.jsp:
<%#taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%#taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%#taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%#taglib uri="http://richfaces.org/rich" prefix="rich"%>
<html>
<head>
<title>TestTree</title>
</head>
<body>
<f:view>
<h:form>
<h:panelGrid columns="2" width="100%" columnClasses="col1,col2">
<rich:tree style="width:300px" nodeSelectListener="#{simpleTreeBean.processSelection}"
reRender="selectedNode" ajaxSubmitSelection="true" switchType="client"
value="#{simpleTreeBean.treeNode}" var="item" ajaxKeys="#{null}">
</rich:tree>
<h:outputText escape="false" value="Selected Node: #{simpleTreeBean.nodeTitle}" id="selectedNode" />
</h:panelGrid>
</h:form>
</f:view>
</body>
</html>
Important Part of faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
<managed-bean>
<managed-bean-name>simpleTreeBean</managed-bean-name>
<managed-bean-class>
com.realcore.web.beans.SimpleTreeBean
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
<</faces-config>/faces-config>
Additionally there are some Validators and Converters in my faces-config too. But I think this isnt important for this Problem.
And here is the web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>SstSapWEB</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>login.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- Making the RichFaces skin spread to standard HTML controls -->
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<!-- Defining and mapping the RichFaces filter -->
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
This simple Example isnt working too.
I don't know how to fix or workaround this Issue. Any help is greatly appreciated.
Regards,
Daniel
just in fact somebody else has similar Problems: After working on other things in the mean time I now figured out how to solve this Issue.
It was rather easy and all work is done in the JSP:
Use Rich Tree Node inside the Rich Tree Tag
Use the ajaxSubmitSelection and reRender Attributes of the TreeNode
Wrap the Part of the Page, which should be rerendered in a <a4j:outputPanel/> and set its Attribute ajaxRendered to "true"
Ensure that the values of the id-Attribute of the <a4j:outputPanel/> and the reRender-attribute of the TreeNode are the same.
Hope this helps others with similar Problems,
Daniel
I am having an error on loading a theme using JSF 2.2 and Primefaces 5. I have the below bean:
package beans;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
#ManagedBean(name = "themeSwitcher")
#SessionScoped
public class ThemeSwitcher implements Serializable {
private String theme;
public ThemeSwitcher () {
theme = "afterdark";
}
public String getTheme() {
return theme;
}
public void setTheme(String theme) {
this.theme = theme;
}
}
which works perfectly. When I try to change it to #Named in order to be able to inject it to my other beans am getting this error:
FATAL: JSF1073: javax.faces.FacesException caught during processing of RENDER_RESPONSE 6 : UIComponent-ClientId=, Message=Error loading theme, cannot find "theme.css" resource of "primefaces-" library
FATAL: Error loading theme, cannot find "theme.css" resource of "primefaces-" library
javax.faces.FacesException: Error loading theme, cannot find "theme.css" resource of "primefaces-" library
at org.primefaces.renderkit.HeadRenderer.encodeTheme(HeadRenderer.java:117)
at org.primefaces.renderkit.HeadRenderer.encodeBegin(HeadRenderer.java:72)
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:869)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1854)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at filters.AuthenticationFilter.doFilter(AuthenticationFilter.java:136)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:745)
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>#{themeSwitcher.theme}</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/PropertyWS/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
60
</session-timeout>
</session-config>
<security-constraint>
<web-resource-collection>
<web-resource-name>Security</web-resource-name>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<welcome-file-list>
<welcome-file>/public/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
I am using Netbeans 8 and I have added the jars to the Libraries. I also tried to put them in a WEB-INF/lib folder but it did not helped. Any suggestions?
Why not instead inject the bean using the #ManagedProperty annotation? For example, in a secondary class:
#ManagedBean
#ViewScoped
public class Foo extends Bar {
#ManagedProperty(value="#{themeSwitcher}")
private ThemeSwitcher themeSwitcher;