Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logic:iterate

 
piyush kumar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try putting your list onto the request in your action before returning the mappingForward.

Something like:


and


will become
 
piyush kumar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check in struts config...have you done entry for form <form-beans>
 
piyush kumar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic