aspose file tools*
The moose likes Struts and the fly likes Logic:iterate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Logic:iterate" Watch "Logic:iterate" New topic
Author

Logic:iterate

piyush kumar
Greenhorn

Joined: Feb 01, 2007
Posts: 20
Hi all,

I am little bit conffused regarding the usage of logic:iterate tag.
I am getting an error always No collection found and others.
Let me tell the actual scenario:

I have a jsp in which I am using
<logic:iterate id="rsult" name="userForm" property="results">
<bean:write name="rsult" property="fname"/>
<bean:write name="rsult property="lname"/>
</logic:iterate>

Now i am using a Form Bean by the name of "userForm" which contains an attribute "results" of the type ArrayList and its corresponding getters and setters.

now the action class is calling the model class to perform some database transactions and then the result obtained is added one by one to an arraylist and returned to the action class from where it is set to the Form Bean by the setter method. after this the jsp page while displaying the contents throwing the exceptions.

pleae help regarding this?
[ September 17, 2007: Message edited by: Bear Bibeault ]
piyush kumar
Greenhorn

Joined: Feb 01, 2007
Posts: 20
i am getting this excption:


javax.servlet.ServletException: javax.servlet.jsp.JspException: No collection found
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:855)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)
org.apache.jsp.user_jsp._jspService(user_jsp.java:214)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
Tamas Jano
Ranch Hand

Joined: Feb 21, 2007
Posts: 55
Try putting your list onto the request in your action before returning the mappingForward.

Something like:


and


will become
piyush kumar
Greenhorn

Joined: Feb 01, 2007
Posts: 20
hmm i tried these steps but got the following excption:

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean results in any scope
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:855)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:784)
org.apache.jsp.user_jsp._jspService(user_jsp.java:172)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:387)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
Tamas Jano
Ranch Hand

Joined: Feb 21, 2007
Posts: 55
Can you post the code from your action? Only the part that prepares the form and returns the forward?

You could use the session as well for that but I wouldn't recommend.
piyush kumar
Greenhorn

Joined: Feb 01, 2007
Posts: 20
public class UserAction extends DispatchAction
{

//Performs The SearchUser Action When the user submits the form and clicks the SearchUser button
public ActionForward SearchUser(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res) throws Exception
{
UserSearchService service = new UserSearchService();
ArrayList<String> results = null;

UserForm userForm = (UserForm) form;

String name = userForm.getFname();

if(name != null & name.trim().length()>0)
results = service.search(name);
if(results.size()< 1)
{
System.out.println(results.size());
throw new NoResultsFoundException();
}

userForm.setResults(results);

return new ActionForward("/user.jsp");
}

//Performs The ListUser Action When the user clicks the ListUsers link
public ActionForward ListUser(ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res)
{
UserForm userForm = (UserForm) form;
Connection con= null;
Statement stmt = null;
ResultSet rs = null;
ArrayList<String> result = new ArrayList<String>();

try
{
con = ConMgmt.getConnection();
System.out.println("success");
stmt = con.createStatement();
rs = stmt.executeQuery("select * from puser");

while(rs.next())
{
String fname = rs.getString(1);
String lname = rs.getString(2);
result.add(fname);
result.add(lname);
}

userForm.setResults(result);
} catch (SQLException e) {

e.printStackTrace();
}
return new ActionForward("/user.jsp");
}
}
Patricia Samuel
Ranch Hand

Joined: Sep 12, 2007
Posts: 300
Check in struts config...have you done entry for form <form-beans>
piyush kumar
Greenhorn

Joined: Feb 01, 2007
Posts: 20
Yes, My struts-config file is as follows:

<struts-config>

<form-beans>
<form-bean name="userForm" type="we.persistent.UserForm"></form-bean>
</form-beans>

<global-forwards>
<forward
name="user"
path="/user.jsp"/>
</global-forwards>

<action-mappings>
<action
path="/user"
type="we.persistent.UserAction"
parameter="AddUser"
name="userForm"
input="/user.jsp"
scope="session"
validate="true">
</action>
<action
path="/luser"
type="we.persistent.UserAction"
parameter="ListUser"
name="userForm"
scope="session"
validate="false"
input="/user.jsp"/>
<action
path="/suser"
type="we.persistent.UserAction"
parameter="SearchUser"
name="userForm"
scope="session"
validate="true"
input="/user.jsp">
<exception key="error.NoResultsFoundException"
type="we.persistent.NoResultsFoundException"
path="/user.jsp"/>
</action>


</action-mappings>

<message-resources parameter="we.persistent.MessageResources" />

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>

</struts-config>
Tamas Jano
Ranch Hand

Joined: Feb 21, 2007
Posts: 55
Add to both methods (just before the return statement) and do the change in the iterate tag as mentioned in the previous post



You have to specify the bean in the page scope or session scope.

[ September 13, 2007: Message edited by: Tamas Jano ]
[ September 13, 2007: Message edited by: Tamas Jano ]
piyush kumar
Greenhorn

Joined: Feb 01, 2007
Posts: 20
Hi, Tamas

I have done this thing already but I am getting exception thrownthat "No getter method for fname of the bean rsults."
Tamas Jano
Ranch Hand

Joined: Feb 21, 2007
Posts: 55
Now at least the list is seen in the page

The above code translates to:
for (i = 0; i < result.size; i++) {
print(result.get(i).getFname());
print(result.get(i).getLname());
}
It tries to access the list result that contains POJOs and it tries to get the value of fname by calling its getter method as per the bean definition.
To solve this problem add POJOs to the list in you action class, something like this:



where Person is a POJO with attributes fname and lname and the appropiate getters and setters

etc

After all this it should work.
leo oke
Greenhorn

Joined: Jul 09, 2007
Posts: 21
I've got a similiar problem like yours,but you need to read this link
from netbeans.

http://www.netbeans.org/kb/50/tutorial-webapps-struts.html

Let me know how you got on?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Logic:iterate
 
Similar Threads
how to use html:checkbox and requestgetParameterValues() in association
logic:iterate tag displaying same results??
on logic:iterate tag
intresting problem : same page with few modification on some conditions
javax.servlet.ServletException: javax.servlet.jsp.JspException: No getter method for property result