I’m trying to do something like (in a JSP page, running with JavaServer Faces):
<%
String myTitle = "Cool Action!";
String myAction = "coolAction";
%>
<h:commandLink value="#{myTitle}" action="#{myAction}" />
This isn’t working, because JSF can’t see the JSP variables (at least with this notation?).
Is there a way to access JSP variables from JSF tags (without using a session/page-scoped bean), OR is there a way to define JSF tags like commandLink from inside a <% %> JSP block? Thanks!
You need to put them in at least the request scope. EL resolves among others the attributes of
HttpServletRequest,HttpSessionandServletContext.But this is totally the wrong way of using JSF. To follow the proper MVC design ideology, you should not use old fashioned JSP scriptlets in any way. Even more, JSP’s successor Facelets does not support any form of scriptlets.
Depending on the concrete functional requirement, you could create a backing bean class wherein you specify them as bean properties,
or just “hardcode” it directly in the
<h:commandLink>.or put at least the value in an i18n resource bundle which you load by
<f:loadBundle>or register by<resource-bundle>infaces-config.xml: