0

I'm following the standard MVC architecture. In my Controller I have the following code,

userDetailsBean = userDetailsDAO.getUserDetailsFromEmail(loginEmail);
session.setAttribute("userDetails", userDetailsBean);

The object userDetailsBean contains different methods like getFName(), getLName() etc. I'm accessing this object from the View file as follows,

<c:choose>
     <c:when test="${sessionScope.userDetails != null}">
          <li>
               <a href="#userName">
                    ${sessionScope.userDetails.getFName()}
               </a>
          </li>
     </c:when>
     <c:otherwise>
          <li>
               <a href="#login">Log in/Register</a>
          </li>
     </c:otherwise>
</c:choose>

I'm getting the following error from the above code,

HTTP Status 500 - /header.jsp(22,38) The function getFName must be used with a prefix when a default namespace is not specified

I searched a lot on the internet and tried many different suggestions like,

${sessionScope.userDetails.fName}
${sessionScope.userDetails.get(0).fName}

but none of it worked,

I'm using Tomacat 6 with JSTL 1.2 and Netbeans as IDE.

Any help is appreciated, thanks in advance!

Saumil
  • 2,521
  • 5
  • 32
  • 54

1 Answers1

0

You could read the JavaBean Specification. For links to it, look at the answer at Where is the JavaBean property naming convention defined?
Look at sections 8.3 and 8.8. You should make your life easy and just use conventional names for your fields. But, if you choose not to do that, then consider the following bean.

package test;
public class BeanTest implements java.io.Serializable {
    private String bHours = "ten";
    private String RICK = "me";
    private String Joe = "hello";

    public BeanTest(){
    }
    public void setbHours(String bHours){
       this.bHours = bHours;
    }
    public String getbHours(){
       return bHours;
    }
    public void setRICK(String str){
                         RICK = str;
    }
    public String getRICK(){
       return RICK;
    }
    public void setJoe(String str){
                         Joe = str;
    }
    public String getJoe(){
       return Joe;
    }
}

In a JSP you can use the following to access the data in the bean.

<jsp:useBean id="myBean" class="test.BeanTest" />
${myBean.RICK}
${myBean.joe}
${myBean.bHours}
<%=myBean.getbHours()%>
Community
  • 1
  • 1
rickz
  • 4,324
  • 2
  • 19
  • 30