I am learning JSF and was trying to implement a small exercise on EL (with JSF page and JSP2). i found a strange behavior and completely clueless of the reason behind it. Please find my code below and scenario
Backing bean class
package task2;
public class FavortiteColors_1 {
private String firstName = "Tarun";
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
Below is the snapshot of faces config xml which is required for this example Faces config.xml
<managed-bean>
<managed-bean-name>favColors_1</managed-bean-name>
<managed-bean-class>task2.FavortiteColors_1</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
JSP Code
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<f:view>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE>Accessing Bean Properties</TITLE>
<LINK REL="STYLESHEET"
HREF="./css/styles.css"
TYPE="text/css">
</HEAD>
<BODY>
<tr><B>Accessing Bean Properties using JSP 2 EL: version 1<B></tr>
<% System.out.println("Accessing Bean Properties using JSP 2 EL: version 1"); %>
<OL>
<LI>First Name ${favColors.firstName}
</OL>
<BR><BR>
<tr><B>Accessing Bean Properties using JSF 1.1 EL <B></tr>
<% System.out.println("Accessing Bean Properties using JSF 1.1 EL"); %>
<UL>
<LI>First Name = <h:outputText
value="#{favColors.firstName}"/>
</UL>
<BR><BR>
<tr><B>Accessing Bean Properties using JSF 1.1 with JSP2EL: version 2<B></tr>
<% System.out.println("Accessing Bean Properties using JSF 1.1 with JSP2EL: version 2"); %>
<OL>
<LI>First Name ${favColors.firstName}
</OL>
<BR><BR><BR>
<P>
</f:view>
*The output is as below: *
Accessing Bean Properties using JSP 2 EL: version 1
First Name
Accessing Bean Properties using JSF 1.1 EL
First Name = Tarun
Accessing Bean Properties using JSF 1.1 with JSP2EL: version 2
First Name Tarun
With this the background below are my questions
Q1: I am trying to fetch a string from the backing bean using JSF 1 El and JSP 2 EL. I am trying to fetch the name using three expressions. First and 3rd one are JSP2 EL and the funny thing is that the first one is not able to fetch the name where as the third one (with the exactly same syntax is able to fetch the name. Using the SOP, I am getting the that first expression is unable to trigger the backing bean whereas the second and third one are doing it successfully. Why is such a scenario happening? Looking forward for your explanation.
Regards Tarun