Yes I believe in magic.
You I hope if a bean ist declared in faces-config.xml it is 
magically visible in the jsf file.
Using the useBean statement helps, thank for Your answer.

This imagefile.jsf content works, I have tested it with imagefile.
jsf?filename=C:\temp\chiemgauer.jpg

<jsp:useBean id="image" scope="request" class="org.troedel.bean.
ImageBean" /> 

<%
        String filename = request.getParameter("filename");
        image.setFilename(filename);
        image.paintImage();

%>

But what still does not work is the commandLink call in the jsf 
file. Does this work in JSF?


        <h:form>
                <h:commandLink value="chiemgauer" action="imagefile.jsf?
filename=C:\temp\chiemgauer.jpg"/>
        </h:form>


----Ursprüngliche Nachricht----
Von: [EMAIL PROTECTED]
Datum: 23.01.2007 20:45
An: "MyFaces Discussion"<[email protected]>
Betreff: Re: Access to managed bean in JSP

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



Reply via email to