Strange problem with Struts - Bean not found in any scope

C

Cerveza Mas Fina

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
 
T

Tim B

Cerveza Mas Fina said:
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" >
<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>

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">
 
L

Lew

Cerveza Mas Fina said:
<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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top