struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc BEGUIGNEAU <marc_beguign...@yahoo.fr>
Subject RE: NewBie Q: <logic:iterator></logic:iterator> can't find bean
Date Thu, 12 Jun 2003 14:27:58 GMT
Hi, 

I haved problem with Vector, a better way could be
using ArrayList.

To iterate a list (displaying a search result for
example), I make an ArrayList of bean, that I take in
the request scope. Then in my JSP page, I use the
<logic:iterate... tag for displaying my result.

So let's have a look to a cut of my code:

The bean Film:
<code>
public class Film {

protected int id_film;	
protected String titre;

public String getTitre() {
	return this.titre;
}

public void setTitre(String titre) {
	this.titre = titre;
}

public int getId_film() {
	return this.id_film;
}

public void setId_film(int id_film) {
	this.id_film = id_film;
}
}

</code>
As you see, it's a simple JavaBean wich is an image of
the table in my db.

In my action class:

<code>

ArrayList listfilm = new ArrayList();
Film film = null; 

.... (what you have to do to obtain a ResultSet)

while(searchResult.next()) {
        film = new Film();
	film.setId_film(searchResult.getInt("ID_FILM"));
	film.setTitre(searchResult.getString("TITRE"));
        listfilm.add(film);
}

...

request.setAttribute("listingfilm", listfilm);

</code>

I have cut a part of a code, but what you have seen is
the necessary to have an ArrayList ( of bean in the
request scope.

In my JSP page:

<code>
<table border=0>

<logic:iterate id="film" name="listingfilm"
scope="request">
<tr>
<td align="center">
<bean:write name="film" property="id_film"
filter="true" /> </a>
		
		<td>
			<bean:write name="film" property="titre"
filter="true" />
		</td>
</tr>
</logic:iterate>

</table>

</code>

It's another solotion without Vector, but it's work
fine!

As you want...	

Regards
Marc



 --- Mike Jasnowski <mjasnows@bea.com> a écrit : > Are
you looking in the correct scope with the
> iterate tag?
> 
> -----Original Message-----
> From: TopBid987654321@aol.com
> [mailto:TopBid987654321@aol.com]
> Sent: Thursday, June 12, 2003 9:49 AM
> To: struts-user@jakarta.apache.org
> Subject: NewBie Q: <logic:iterator></logic:iterator>
> can't find bean
> 
> 
> Hi to Everyone,
> 
> I am trying to use the
> <logic:iterator></logic:iterator> tag in my JSP to
> iterate a vector object which is supposed to be
> delivered by a bean, called
> Books, and I do repeatedly get the following
> exception :
> [
> org.apache.jasper.JasperException: Cannot find bean
> Books in any scope
>     at
>
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:2
> 48)
>     at
>
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
>     at
>
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
>     at
>
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>     at
>
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
> FilterChain.java:247)
>     at
>
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
> ain.java:193)
>     at
>
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
> va:260)
>     at
>
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
> eNext(StandardPipeline.java:643)
>     at
>
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
>             ------------
>                 ------------
> 
> root cause
> 
> javax.servlet.ServletException: Cannot find bean
> Books in any scope
>     at
>
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImp
> l.java:530)
>     at
>
org.apache.jsp.tfp_techbooks_jsp._jspService(Books_jsp.java:407)
>     at
>
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
>     at
>
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>     at
>
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:2
> 04)
>     at
>
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
>          -----------
>          -------
> 
> ]
> 
> Here is a snippet from my Action class, BookAction :
>          ----------
> 
>         if (action == null) {
>             return
> (mapping.findForward("techbooks"));
>         }
> 
> 
>         newVector = new
> Vector(newConnClass.getISBN());
>         this.setISBN(newVector);
> 
>         request.setAttribute("Books", newVector);
> 
> 
>         return (mapping.findForward("techbooks"));
>     }
> 
> struts-config.xml:
> 
> ------
> ------
> <action-mappings>
> 
>         <action path="/Books.jsp"
>             type="com.myBook.BookAction"
>             scope="request"
>             input="/Books.jsp">
>             <forward name="techbooks"
> path="/Books.jsp"/>
>         </action>
> 
> 
>     </action-mappings>
> 
> Books.jsp:
> -----
> -----
> <table width="420" border="1" cellpadding="0"
> cellspacing="0" valign="top">
>     <tr><logic:iterate id="myIsbn" name="Books">
>         <td>
>                        <bean:write name="myIsbn"
> property="EnglishISBN" />
>         </td>
>         </logic:iterate>
>     </tr>
> </table>
> -----
> ----
> 
> Where could I be going wrong ?
> 
> Any help/suggestions will be much appreciated.
> 
> Bob
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
>  

___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message