java - Accessing a managed bean from a JSP tag file -
i have following minimal test case:
not_working.jsp:
<%@page contenttype="text/html" pageencoding="utf-8"%> <%@taglib prefix="t" tagdir="/web-inf/tags" %> <t:not_working_tag> hello </t:not_working_tag>
web-inf/tags/not_working_tag.tag
<%@tag description="main page template" pageencoding="utf-8"%> <%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <html> <head></head> <f:view> <h:outputtext value="#{userbean.test}"/> <jsp:dobody/> </f:view> </html>
src/java/userbean.java
@managedbean(name="userbean") @sessionscoped public class userbean { public string gettest() { return "hello!"; } }
now i'd expect when access not_working.jsp through browser, i'd see "hello!". except see "#{userbean.test}". say, literal el expression put in value attribute. now, when put "${userbean.test}" directly above , 1 works - shows "hello!". simple test case, enough, of course want use values bean in more complex situations (e.g. in f:selectitems).
what i'm making out of of el deferred expressions isn't being evaluated reason. doing wrong? how use deferred expressions, required in value attributes of jsf tags, tag files?
i'm using jsf 2.2 (mojarra 2.2.0) , tomcat, if makes difference.
to display method value need specify parenthesis @ end of method name. use <h:outputtext value="#{userbean.test()}"/>.
jsp recognize method , display value
Comments
Post a Comment