0

I'm trying to load a page randomly. I have 3 pages 'page1','page2' & 'page3'. When i start the application on the server the index page loads fine. but when i click the "Go to random page button", it gives me the error,

javax.el.PropertyNotFoundException: /index.xhtml @24,60 action="#{navigationBean.choosePage}": Target Unreachable, identifier 'navigationBean' resolved to null

Stack Trace :

javax.faces.el.EvaluationException: javax.el.PropertyNotFoundException: /index.xhtml @24,60 action="#{navigationBean.choosePage}": Target Unreachable, identifier 'navigationBean' resolved to null at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:94) 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:646) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655) at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source) Caused by: javax.el.PropertyNotFoundException: /index.xhtml @24,60 action="#{navigationBean.choosePage}": Target Unreachable, identifier 'navigationBean' resolved to null at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) ... 30 more

And even when i try to access those 3 pages manually ('page1','page2' & 'page3') using the url it gives me this error,

javax/servlet/jsp/jstl/core/Config

Stack Trace :

java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:344) at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:153) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99) 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:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655) at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source)

These are my sources and pages,

@ManagedBean NavigationBean.java

    package proMod;

    import java.util.Random;

    import javax.faces.bean.ManagedBean;

    @ManagedBean
    public class NavigationBean {

        private String[] resultsPage={"page1","page2","page3"};

        public String choosePage() {

            int idx = new Random().nextInt(3);  
            String random = (resultsPage[idx]);
            return random;

        }
    }

index.xhtml

<!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">
<!--  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 Project</title>
<link href="./css/styles.css" 
      rel="stylesheet" type="text/css"/> 
</h:head>
<h:body>
    <h1 class="title">JSF 2.2: Navigation Project</h1>
    <br/>

    <div align="center">
    <fieldset>
    <legend>Random Results Page</legend>
    <h:form>
      Press the button to get a result page.<br/>

      <h:commandButton value="Go to Random Page" 
                       action="#{navigationBean.choosePage}"/>     
    </h:form>
    </fieldset>
    </div>
</h:body>
</html>

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">
  <!-- The bare minimum needed for JSF 2.2 is a servlet 2.5 or later
       declaration (this uses 3.0) and the mapping for the FacesServlet.
       Setting PROJECT_STAGE to Development is highly recommended
       during initial development so that you get more helpful
       error messages. Whether you want server-side state saving
       (default) or client-side is a more complicated question:
       client-side uses more bandwidth but fewer server resources.
       Client-side also helps to avoid the dreaded view expired exceptions.

       From JSF 2 and PrimeFaces tutorial 
       at http://www.coreservlets.com/JSF-Tutorial/jsf2/
  -->
  <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>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
k9yosh
  • 858
  • 1
  • 11
  • 31
  • `choosePage` refers to a property which should have a a getter method `getChoosePage()` and that cannot be found. Change your method name or change your expression to be `choosePage()` to make it a direct method call instead of a property lookup. – M. Deinum Aug 27 '14 at 05:52
  • Next to that you appear to be missing a required dependency (JSTL probably) on your classpath. – M. Deinum Aug 27 '14 at 05:53
  • @M.Deinum I added the JSTL jar to lib folder in WebComponents. It should work right? i'll try changing the method name. – k9yosh Aug 27 '14 at 05:55
  • Not sure where you put it but the fact that it is in your IDe doesn't mean it is on your server, also make sure that you have the correct version for JSF 2. – M. Deinum Aug 27 '14 at 06:03
  • @M.Deinum i did as you said. but now that action value **action="#{navigationBean.choosePage}"** is highlighted in red and i did add the jstl.jar. – k9yosh Aug 27 '14 at 06:41
  • Doh... I didn't notice the action... Try with ()... As I mentioned the fact that you did add it doesn't mean it is there at RUNTIME... RUNTIME != COMPILE time. Also make sure it is the correct version. – M. Deinum Aug 27 '14 at 07:38

0 Answers0