Simon Kitching wrote:
[EMAIL PROTECTED] wrote:
I would like to access the bean instance image in the jsp file
<managed-bean>
<managed-bean-name>image</managed-bean-name>
<managed-bean-class>org.troedel.bean.ImageBean</managed-bean-
class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
The jsp file generates the exception
<%@ page import="org.troedel.bean.ImageBean;" %>
<%
String filename = request.getParameter("filename");
image.setFilename(filename);
image.paintImage();
%>
avax.servlet.ServletException: Unable to compile class for JSP
An error occurred at line: 3 in the jsp file: /imagefile.jsp
Generated servlet error:
image cannot be resolved
An error occurred at line: 3 in the jsp file: /imagefile.jsp
Generated servlet error:
image cannot be resolved
javax.faces.webapp.FacesServlet.service(FacesServlet.java:152)
Yep, this is a common problem.
If the managed bean has been created already (because some JSF component
has evaluated #{image} then your jsp code will then work. However (in
JSF1.1 with JSP) the jsp code won't automatically create the bean if it
doesn't exist, because it doesn't know about the JSF managed-beans file.
The solution is to ensure that some JSF component earlier in the page
references the bean, egsomething like:
<t:outputText style="display:hidden" rendered="#{image}"/>
The rendered attribute will be evaluated when the component is
processed, which has the side-effect of forcing the image object to be
created and placed in the appropriate scope.
umm .. and of course you need to declare your local variable [which
happens to be called "image"] that will hold a reference to the image
object from the managed beans file. This is the "compilation error" you
are getting.
You then need to *retrieve* the image object.
You appear to be expecting JSF managed beans to magically appear as
local variables accessable from your jsp fragments - this does not happen.
Regards,
Simon