[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.
Regards,
Simon