ethan wrote:
>
> Hi,
>
> It will work when I put <%=bean.getName() %>. I am very puzzle why it does
> not work with the getProperty of the bean convention.
>
> Anyone can help to explain?
It's because <jsp:getProperty> (as well as all other actions, both standard
and custom) only have access to objects bound to one of the JSP scopes:
page, request, session and application; an action can not access an object
that is only assigned to a scripting variable (i.e. a Java variable declared
in the page within a JSP scripting element, making it a local variable in
the generated _jspService() method).
In your case you use a <jsp:useBean> action to declare, and create, the
bean in the request scope. The bean you create is empty since you do not
set any properties. Then you use a scriptlet to assign new objects to
the bean. But this code does not update the reference to the original
bean in the request scope.
A better approach would be to use a custom action that loops over all
beans that you have in the "manu" request attribute and make one bean
at the time available in the page scope, where <jsp:getProperty> can
get it. There are plenty of custom actions available that does this
sort of thing. Start looking at the resources found at:
<http://java.sun.com/products/jsp/>
Another alternative is to use scripting code for the whole thing: remove
the <jsp:useBean> action since it doesn't help you here and use
scripting code like:
<%
KeyBean[] beans = (KeyBean[]) request.getAttribute("manu");
if (beans != null) {
for(int i =0;i < beans.length; i++) {
%>
<option>
<%= beans[i].getName() %>
</option>
<%
}
}
%>
Hans
> ----- Original Message -----
> From: "Robert Nicholson" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, October 05, 2000 1:36 PM
> Subject: Re: why my getProperty does not work?
>
> In your code. bean is not a "Bean" that can be used with getProperty. Only
> Beans created via a useBean can be used with getProperty.
>
> What happens when you put
>
> <%= bean.name() %>
>
> there instead?
>
> > -----Original Message-----
> > From: A mailing list about Java Server Pages specification and reference
> > [mailto:[EMAIL PROTECTED]]On Behalf Of ethan
> > Sent: Wednesday, October 04, 2000 7:17 PM
> > To: [EMAIL PROTECTED]
> > Subject: why my getProperty does not work?
> >
> >
> > Hi,
> > Could someone explain why my getProperty does not work? here the code. The
> > select keeps showing null.
> > Thanks for your help!!
> >
> > <%@page import="com.repository.*" errorPage="error.jsp" %>
> > <jsp:useBean id="bean" class="KeyBean" scope="request" />
> >
> > ... html code ...
> > <select size="1" name="manufacturer" tabindex="1"
> > >
> > <option> All </option>
> > <%
> > beans = (KeyBean[]) request.getAttribute("manu");
> > if (beans != null)
> > {
> > for(int i =0;i < beans.length; i++)
> > {
> > bean = beans[i];
> > %>
> > <Option>
> > <jsp:getProperty name="bean" property="name"
> > />
> > </option>
> > <%
> > }
> > }
> > %>
> > </select>
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets