title: #{facesContext} EL expression not resolved at runtime
body: <p>I am working on JSF 1.x
  On an example stated in JavaServer Faces in Action.</p>
  
  <p>My EL expression of 'Faces Context' is not executing at run time in command button on retrieving the image.</p>
  
  <p><strong>My Project Structure is as follows:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/Vyox7.jpg" alt="Structure"></p>
  
  <p>I have not used any Java code in this example,
  And it contains only one Login Page.</p>
  
  <p><strong>The login.jsp is as follows:</strong></p>
  
  <pre><code>&lt;%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%&gt;
  &lt;%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%&gt;
  
  
  &lt;f:view&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;link rel="stylesheet" type="text/css" href="stylesheet.css" /&gt;
  
      &lt;script type="text/javascript"&gt;
          function set_image(button, image){
              button.src = img;
          }
      &lt;/script&gt;
  
      &lt;title&gt;&lt;h:outputText value="ProjectTrack" /&gt;&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
      &lt;h:form&gt;
          &lt;h:panelGrid columns="2" border="0" cellpadding="3" cellspacing="3"&gt;
  
              &lt;h:graphicImage url="/images/logo.png"
                      alt="Welcome to ProjectTrack" title="Welcome to ProjectTrack"
                      width="149" height="160" /&gt;
  
  
              &lt;h:panelGrid columns="3" border="0" cellpadding="5" cellspacing="3" headerClass="login-heading"&gt;
  
                  &lt;f:facet name="header"&gt;
                      &lt;h:outputText value="ProjectTrack" /&gt;
                  &lt;/f:facet&gt;
  
                  &lt;h:outputLabel for="userNameInput" &gt;
                      &lt;h:outputText value="Enter your user name: " /&gt;
                  &lt;/h:outputLabel&gt;
  
                  &lt;h:inputText id="userNameInput" size="20" maxlength="30" required="true"&gt;
                      &lt;f:validateLength minimum="5" maximum="30"/&gt;
                  &lt;/h:inputText&gt;
  
                  &lt;h:message for="userNameInput" /&gt;
  
                  &lt;h:outputLabel for="passwordInput"&gt;
                      &lt;h:outputText value="Password"/&gt;
                  &lt;/h:outputLabel&gt;
  
                  &lt;h:inputSecret id="passwordInput" size="20" maxlength="20" required="true"&gt;
                      &lt;f:validateLength minimum="5" maximum="15" /&gt;
                  &lt;/h:inputSecret&gt;
  
                  &lt;h:message for="passwordInput" /&gt;
  
                  &lt;h:panelGroup&gt;
                      &lt;h:commandButton  action="success" 
                                  image="#{facesContext.externalContext.requestContextPath}/images/submit.gif" 
                                  onmouseover="set_image(this, '#{facesContext.externalContext.requestContextPath}/images/submit_over.gif');"
                                  onmouseout="set_image(this, '#{facesContext.externalContext.requestContextPath}/images/submit.gif');" 
                              /&gt;
                  &lt;/h:panelGroup&gt;
  
              &lt;/h:panelGrid&gt;
  
          &lt;/h:panelGrid&gt;
      &lt;/h:form&gt;
  &lt;/body&gt;
  &lt;/f:view&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p><strong>My Deployment Descriptor web.xml is as follows:</strong> </p>
  
  <pre><code>&lt;web-app version="2.5"
        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-app_2_5.xsd"&gt;
  
      &lt;display-name&gt;Project Track&lt;/display-name&gt;
      &lt;description&gt;Sample Project&lt;/description&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;faces/login.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>Faces-config.xml is as follows:</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE faces-config PUBLIC
       "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
       "http://java.sun.com/dtd/web-facesconfig_1_0.dtd"&gt;
  
  &lt;faces-config&gt;
  
      &lt;application&gt;
          &lt;message-bundle&gt;ptrackResources&lt;/message-bundle&gt;
      &lt;/application&gt;
  
      &lt;navigation-rule&gt;
          &lt;from-view-id&gt;/login.jsp&lt;/from-view-id&gt;
          &lt;navigation-case&gt;
              &lt;from-outcome&gt;success&lt;/from-outcome&gt;
              &lt;to-view-id&gt;/inbox.jsp&lt;/to-view-id&gt;
          &lt;/navigation-case&gt;
          &lt;navigation-case&gt;
              &lt;from-outcome&gt;failure&lt;/from-outcome&gt;
              &lt;to-view-id&gt;/login.jsp&lt;/to-view-id&gt;
          &lt;/navigation-case&gt;
      &lt;/navigation-rule&gt;
  
  &lt;/faces-config&gt;
  </code></pre>
  
  <p><strong>My Maven Dependencies are as follows:</strong></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;com.achutha.labs&lt;/groupId&gt;
    &lt;artifactId&gt;03JsfExample&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;
    &lt;name&gt;03JsfExample&lt;/name&gt;
    &lt;description&gt;Project Track&lt;/description&gt;
  
    &lt;dependencies&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.faces&lt;/groupId&gt;
              &lt;artifactId&gt;jsf-api&lt;/artifactId&gt;
              &lt;version&gt;1.2_14&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.faces&lt;/groupId&gt;
              &lt;artifactId&gt;jsf-impl&lt;/artifactId&gt;
              &lt;version&gt;1.2_14&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;jstl&lt;/artifactId&gt;
              &lt;version&gt;1.2&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
              &lt;version&gt;2.5&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
              &lt;artifactId&gt;jsp-api&lt;/artifactId&gt;
              &lt;version&gt;2.1&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!-- EL --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.web&lt;/groupId&gt;
              &lt;artifactId&gt;el-impl&lt;/artifactId&gt;
              &lt;version&gt;2.2&lt;/version&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
  
      &lt;build&gt;
          &lt;finalName&gt;JavaServerFaces&lt;/finalName&gt;
  
          &lt;plugins&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                  &lt;artifactId&gt;tomcat-maven-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;url&gt;http://localhost:8090/manager/text&lt;/url&gt;
                      &lt;server&gt;TomcatServer&lt;/server&gt;
                      &lt;path&gt;/balaji&lt;/path&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.6&lt;/source&gt;
                      &lt;target&gt;1.6&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p>The Application Ran successfully. But the Image for submit button is not displaying which is retrieved through a run time expression. </p>
  
  <p><strong>Browser Display:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/WwpAi.jpg" alt="Browser Display"></p>
  
  <p>I have configured my JBoss tools, from which i can see the preview which evaluates the expression and displays the submit button before deployment:</p>
  
  <p><strong>Eclipse Screen Shot:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/YDeLL.jpg" alt="Eclipse Screen Shots"></p>
  
  <p>The EL expression used in  is not evaluating at runtime.</p>
  
  <pre><code>&lt;h:commandButton  action="success" 
                                  image="#{facesContext.externalContext.requestContextPath}/images/submit.gif" 
                                  onmouseover="set_image(this, '#{facesContext.externalContext.requestContextPath}/images/submit_over.gif');"
                                  onmouseout="set_image(this, '#{facesContext.externalContext.requestContextPath}/images/submit.gif');" 
                              /&gt;
  </code></pre>
  
  <p>I have to use JSF 1.x and cannot upgrade it to JSF 2.
  Please suggest me the solution, and help me know what is going wrong.</p>
  
  <p>My problem is similar to the problem stated here in this link:
  <a href="http://www.java.net/node/703730" rel="nofollow noreferrer">FacesContext not resolved at run-time</a></p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I just added a Debug statement in <code>login.jsp</code> which is as follows:</p>
  
  <pre><code>&lt;h:outputText value=" Debug test for EL exp : #{facesContext.externalContext.requestContextPath}/images/submit.gif" /&gt;
  </code></pre>
  
  <p><strong>Debug Result:</strong></p>
  
  <p><img src="https://i.stack.imgur.com/9csi1.jpg" alt="Debug Result"></p>
  
  <p>The expression is getting evaluated at runtime, 
  But I feel the result must not contain <code>/balaji/images/submit.gif</code>,
  And it should only contain <code>/images/submit.gif</code>.</p>