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
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 issue with PrimeFaces 6.0 push, I have searched all questions here and no answer helped me. I'm building a internal email system and I'm trying to notify user if he has new email inserted in the DB based on back end event (observer pattern), here is my code:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>Test Foo Email system</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>
<!-- primeFaces push declaration -->
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/ *</url-pattern>
</servlet-mapping>
<!-- Ends here-->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/ *</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>
</web-app>
My foo.xhtml page code sample
<script type="text/javascript">
function handleMessage(facesmessage) {
facesmessage.severity = 'info';
PF('growl').show([facesmessage]);
}
</script>
<div class="New_Message_container ">
<!-- primefaces Push component -->
<p:growl widgetVar="growl" showDetail="true" />
<p:socket onMessage="handleMessage" channel="/notify" />
</div>
Controller class:
private final static String CHANNEL = "/notify";
.
.
.
private void notifyView(NewEmailEvent evt) {
String CurrentUser = this.currentUser.getEmailID();
String EventUserId = evt.getUserID();
if (CurrentUser.equalsIgnoreCase(EventUserId)) {
EventBus eventBus = EventBusFactory.getDefault().eventBus();
eventBus.publish(CHANNEL,
new FacesMessage("New Mail", "You have new Mail"));
}
}
NotifyResource class
import javax.faces.application.FacesMessage;
import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.impl.JSONEncoder;
#PushEndpoint("/notify")
public class NotifyResource {
#OnMessage(encoders = {JSONEncoder.class})
public FacesMessage onMessage(FacesMessage message) {
return message;
}
}
Included required libraries which i found was required for this code, I have downloaded these jars from the web which are used in my sample.
atmosphere-annotations-2.4.9.jar
atmosphere-compat-jbossweb-2.0.1.jar
atmosphere-compat-tomcat-2.0.1.jar
atmosphere-compat-tomcat7-2.0.1.jar
atmosphere-runtime-2.4.9.jar
primefaces-6.0.jar
slf4j-api-1.7.22.jar
slf4j-simple-1.7.22.jar
I have tired to debug my code and I noticed that the event bus it NULL when I try to use it (eventBus.publish()) so I got java.lang.NullPointerException.
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/ *</url-pattern>
</servlet-mapping>
There is a space between /primepush/ and *, try removing it.
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 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!
Im getting a ClassCastException if i use Attributes in my Custom Headline Tag. Without Attributes rendering works fine.
Calling <t:headline value="test" /> gives a ClassCastException even before a Method in my HeadlineComponent or HeadlineTag-Class is called. <t:headline /> works fine.
I'm using MyFaces-1.2, on BEA 10.3
default.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%# taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%# taglib prefix="t" uri="http://www.tobi.de/taglibrary" %>
<!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=ISO-8859-1">
<title>Tobi Test</title>
</head>
<body>
<f:view>
<t:headline value="test" />
</f:view>
</body>
</html>
HeadlineComponent.java
package tobi.web.component.headline;
import java.io.IOException;
import javax.el.ValueExpression;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
public class HeadlineComponent extends UIOutput {
private String value;
private Integer size;
#Override
public Object saveState(FacesContext context) {
Object values[] = new Object[3];
values[0] = super.saveState(context);
values[1] = value;
values[2] = size;
return ((Object)(values));
}
#Override
public void restoreState(FacesContext context, Object state) {
Object values[] = (Object[])state;
super.restoreState(context, values[0]);
value = (String)values[1];
size = (Integer)values[2];
}
#Override
public void encodeBegin(FacesContext context) throws IOException {
// Wenn keine Groesse angegeben wurde default 3
String htmlTag = (size == null) ? "h3" : "h"+getSize().toString();
ResponseWriter writer = context.getResponseWriter();
writer.startElement(htmlTag, this);
if(value == null) {
writer.write("");
} else {
writer.write(value);
}
writer.endElement(htmlTag);
writer.flush();
}
public String getValue() {
if(value != null) {
return value;
}
ValueExpression ve = getValueExpression("value");
if(ve != null) {
return (String)ve.getValue(getFacesContext().getELContext());
}
return null;
}
public void setValue(String value) {
this.value = value;
}
public Integer getSize() {
if(size != null) {
return size;
}
ValueExpression ve = getValueExpression("size");
if(ve != null) {
return (Integer)ve.getValue(getFacesContext().getELContext());
}
return null;
}
public void setSize(Integer size) {
if(size>6) size = 6;
if(size<1) size = 1;
this.size = size;
}
}
HeadlineTag.java
package tobi.web.component.headline;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.webapp.UIComponentELTag;
public class HeadlineTag extends UIComponentELTag {
private ValueExpression value;
private ValueExpression size;
#Override
public String getComponentType() {
return "tobi.headline";
}
#Override
public String getRendererType() {
// null, da wir hier keinen eigenen Render benutzen
return null;
}
protected void setProperties(UIComponent component) {
super.setProperties(component);
HeadlineComponent headline = (HeadlineComponent)component;
if(value != null) {
if(value.isLiteralText()) {
headline.getAttributes().put("value", value.getExpressionString());
} else {
headline.setValueExpression("value", value);
}
}
if(size != null) {
if(size.isLiteralText()) {
headline.getAttributes().put("size", size.getExpressionString());
} else {
headline.setValueExpression("size", size);
}
}
}
#Override
public void release() {
super.release();
this.value = null;
this.size = null;
}
public ValueExpression getValue() {
return value;
}
public void setValue(ValueExpression value) {
this.value = value;
}
public ValueExpression getSize() {
return size;
}
public void setSize(ValueExpression size) {
this.size = size;
}
}
taglibrary.tld
<?xml version="1.0" encoding="UTF-8" ?>
<taglib
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-jsptaglibrary_2_1.xsd"
version="2.1">
<description>Tobi Webclient Taglibrary</description>
<tlib-version>1.0</tlib-version>
<short-name>tobi-taglibrary</short-name>
<uri>http://www.tobi.de/taglibrary</uri>
<tag>
<description>Eine Überschrift im HTML-Stil</description>
<name>headline</name>
<tag-class>tobi.web.component.headline.HeadlineTag</tag-class>
<body-content>empty</body-content>
<attribute>
<description>Der Text der Überschrift</description>
<name>value</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>Die Größe der Überschrift nach HTML (h1 - h6)</description>
<name>size</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
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">
<component>
<description>Erzeugt eine Überschrift nach HTML-Stil</description>
<display-name>headline</display-name>
<component-type>tobi.headline</component-type>
<component-class>tobi.web.component.headline.HeadlineComponent</component-class>
<attribute>
<attribute-name>value</attribute-name>
<attribute-class>java.lang.String</attribute-class>
</attribute>
<attribute>
<attribute-name>size</attribute-name>
<attribute-class>java.lang.Integer</attribute-class>
<default-value>3</default-value>
</attribute>
</component>
</faces-config>
exception
Root cause of ServletException.
java.lang.ClassCastException: java.lang.String
at jsp_servlet._jsf.__default._jsp__tag1(__default.java:194)
at jsp_servlet._jsf.__default._jsp__tag0(__default.java:145)
at jsp_servlet._jsf.__default._jspService(__default.java:104)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:408)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:318)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:505)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:251)
at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:341)
at org.apache.myfaces.application.jsp.JspViewHandlerImpl.buildView(JspViewHandlerImpl.java:486)
at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:337)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:140)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:182)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3498)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
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>tobi.web</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>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>faces</servlet-name>
<servlet-class>org.apache.myfaces.webapp.MyFacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
</web-app>
I see, the <rtexprvalue> in taglibrary.tld should be replaced by <deferred-value> for JSF 1.2 on JSP 2.1 when you use UIComponentELTag.
<attribute>
<description>Der Text der Überschrift</description>
<name>value</name>
<required>false</required>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<description>Die Größe der Überschrift nach HTML (h1 - h6)</description>
<name>size</name>
<required>false</required>
<deferred-value>
<type>java.lang.Integer</type>
</deferred-value>
</attribute>
Give it a try. Also see the JSF 1.2 release notes.