Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts Select Tag

 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My action class setting an arrayobject in session.
ArrayList products = null;
try{
ProductProcessor pp = new ProductProcessor();
ProductBean pb = pp.getAllProductsByProductGroup();
products = pb.getProductNames();
}catch(PersistenceException pe){
;
}
session.setAttribute("products", products);
I want to populate the list in a dropdown using <html:select> tag.
Any one have simple example?.
When I placed this select tag it forced me to put under form tag then it forced me to specify action. If I specify an action which does not have a formBean then I am getting exception.If I give an action which have dummy formBean associated with it then I am getting exception like getter method not defined for that bean.Why it is expecting a formBean when I am just trying to populate it?.
Apreacite your reply's.
Thanks
 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK.I just did some changes to my code after reading couple of threds. I have created a form bean with getters and setters and commented this line in my code. //session.setAttribute("products", products);
I am still geting No getter method available exception.
//startForm:
public ArrayList getProducts() {
return products;
}
public void setProducts(ArrayList products) {
this.products = products;
}
//StartAction:

HttpSession session = request.getSession();
ProductProcessor pp = new ProductProcessor();
int debugLevel = servlet.getDebug();
ArrayList products = null;
StartForm startForm = (StartForm)form;

try{
ProductBean pb = pp.getAllProductsByProductGroup();
products = pb.getProductNames();
startForm.setProducts(products);
}catch(PersistenceException pe){
;
}
 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//My JSP looks like this.
<html:form action="/LogonSubmit" >
<html:select property="products">
</html:select>
</html:form>
//struts-config.xml
<form-beans>
<form-bean name="startForm" type="app.StartForm"/>
</form-beans>
<action-mappings>

<action path="/Start" type="app.StartAction" name="startForm" scope="session">
<forward name="start" path="/pages/Start.jsp"/>
</action>
</action-mappings>
 
Martin Riedl
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
your JSP calls an Action with the path "/LogonSubmit" - in your config-File your ActionPath says "/Start". I guess these two paths should match together, so try to change your JSP to "/Start" instead of "LogonSubmit".
 
sudhakar Tadepalli
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I resolved this problem.
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic