Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2007

Tip: Looking for answers? Try searching our database.

Strange problem with Struts - Bean not found in any scope

Thread view: 
Cerveza Mas Fina - 22 Jun 2007 05:53 GMT
Hi Guys,
I have been getting this strange error where I get a bean not found
error when I use <logic:iterate> . The issue
is that if I substitute the <logic:itearate> with a plain <% scriptlet
%> the JSP does not complain i.e It is able
the ArrayList in the session.

Can someone help ??
Here is my code

FacultyAction.java
-----------------------------
...
...
...

                st.setId(rset.getString(1));
                 st.setName(rset.getString(2));
                 st.setSubject(rset.getString(3));
                 st.setQualification(rset.getString(4));
                 al.add(st);

             }
             if( count == 0 )
                 return mapping.findForward("failure");
             HttpSession session = request.getSession(true); //
Create a new session
             session.setAttribute("results", al);

....

struts-config-faculty.xml
------------------------------------------<?xml version="1.0"
encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD
Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/
struts-config_1_1.dtd">

<struts-config>
<form-beans>
   <form-bean name="fbean" type="app.FacultyBean" />
</form-beans>
<global-forwards/>

<action-mappings>
   <action attribute="fbean"name="fbean"path="/faculty"
type="app.FacultyAction" >
     <forward name="success" path="/faculty/faculty.jsp"
contextRelative="true" />
     <forward  name="failure" path="/faculty/failure.jsp"
contextRelative="true" />
</action>
</action-mappings>
</struts-config>

I have tried putting scope = "session" here but I get the same
problem.
---------------------------------------------------------------------------------------------------------------------------------------

faculty.jsp
----------------
......
.........

Search Criteria For Faculty
</div><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:form action = "/faculty">
<table>
<tr>
   <td>Faculty Id</td>
   <td><html:text property="id"/></td>
   <td><html:submit value="Send"/></td>
</tr>
</table>
</html:form>

<table border=1>
<tr>
<td>ID</td>
<td>Name</td>
<td>Subject</td>
<td>Qualification</td>
</tr>

  <logic:iterate id="element" name="results" scope="session"
type="bean.Faculty" >
  <tr>
     <td><bean:write name="element" property="id" /></td>
     <td><bean:write name="element" property="name" /></td>
     <td><bean:write name="element" property="subject" /></td>
     <td><bean:write name="element" property="qualification" /></
td>
  </tr>
  </logic:iterate>
</table>

Instead of the logic block if I put this stuff below , It works just
fine.

<%
 ArrayList al = (ArrayList)session.getAttribute("result");
 if(al != null)
 {
%>

<tr>
<td>ID</td>
<td>Name</td>
<td>Subject</td>
<td>Qualification</td>
</tr>
<%
   for(int i=0; i < al.size(); i++)
   {
     bean.Faculty st = (bean.Faculty)al.get(i);
%>
<tr>
<td><%= st.getId() %></td>
<td><%= st.getName() %></td>
<td><%= st.getSubject() %></td>
<td><%= st.getQualification() %></td>
</tr>
<%
   }
 }
%>

Please help. I have tried everything within my little knowledge.
Thanks
Tim B - 22 Jun 2007 07:30 GMT
> Hi Guys,
> I have been getting this strange error where I get a bean not found
> error when I use <logic:iterate> . The issue
> is that if I substitute the <logic:itearate> with a plain <% scriptlet

you can replace with or substitute for but you cannot substitute with

>    <logic:iterate id="element" name="results" scope="session"
> type="bean.Faculty" >
[quoted text clipped - 6 lines]
>    </tr>
>    </logic:iterate>

This should work, but is a bit of a hack:

<logic:iterate id="element"
collection='<%=request.getSession().getParameter("results")%>'
type="bean.Faculty" >

Alternatively, you could make your list a property of a bean and save the
bean in session, then use something like:

<logic:iterate id="element" name="myBean" property="myList"
type="bean.Faculty">
Lew - 22 Jun 2007 11:59 GMT
"Cerveza Mas Fina" wrote:
>    <logic:iterate id="element" name="results" scope="session"
> type="bean.Faculty" >
...
> <%
>   ArrayList al = (ArrayList)session.getAttribute("result");

You call it "results" in the iterate tag, "result" in the getAttribute() call.

Signature

Lew

Cerveza Mas Fina - 23 Jun 2007 03:59 GMT
Thanks Guys.

> "Cerveza Mas Fina" wrote:
> >    <logic:iterate id="element" name="results" scope="session"
[quoted text clipped - 7 lines]
> --
> Lew
Lew - 23 Jun 2007 13:58 GMT
> Thanks Guys.

Your avoidance of top posting will signify gratitude sufficiently.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.