Two Laptop Bag*
The moose likes Struts and the fly likes My  html:select is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "My  html:select is not working" Watch "My  html:select is not working" New topic
Author

My html:select is not working

surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
I want to use html:select in my application for drop down box. but i get an exception

here is my code:
<html:select property="snvendor" name="batchbillForm">
<html ption value="DTDC Courier"/>
<html ption value="JetAirways"/>
<html ption value="CitiTaxi"/>
</html:select>

My ActionForm

private String snvendor=null;
public void setSnVendor(String snvendor)
{
this.snvendor=snvendor;
}
public String getSnVendor()
{
return snvendor;
}

When i run my application it gives the following exception...
No getter method available for property snvendor for bean under name batchbillForm
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.BatchBill_jsp._jspService(BatchBill_jsp.java:117)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386)
org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:318)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


SCJP 1.4
surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
Also help me how I can achieve this using <logic:iterate> tag without hard coding values for <html ption> tag.

I think i may have to use the bean:write tag.
RoshaniG Gopal
Ranch Hand

Joined: May 15, 2006
Posts: 180
Hi Surendar,
Hi! I dont know why you have not searched the forum for the same. ALready a thread gives the answer to the same.
http://www.coderanch.com/t/54560/Struts/help-please...


Regards,
Roshani


Regards,<br />Roshani
surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
Thanks Roshani,
but again i am getting the exception...

Now my code is this....
<html:select style="WIDTH: 175px" property="snvendor">
<html ptions name="vendor" />
</html:select>

My Actionform now has a collection
private Collection vendor=null;

public void setVendor(Collection vendor)
{
this.vendor=vendor;
}
public Collection getVendor()
{
return vendor;
}

This collection is loaded by an ArrayList in my Action.
My Exception is this.....

javax.servlet.ServletException: No getter method available for property snvendor for bean under name org.apache.struts.taglib.html.BEAN
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.BatchBill_jsp._jspService(BatchBill_jsp.java:117)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386)
org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:318)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Please help me..

Specify the error in my code if there is any....
regards,
surendar
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If the property name in your <html:select> tag is snvendor, the getter method name in your ActionForm must be getSnvendor(), not getSnVendor().


Merrill
Consultant, Sima Solutions
surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
Now I got rid of that exception. But i have some other problem.

<html:select style="WIDTH: 175px" property="snvendor">
<html ptions name="batchbillForm" property="vendor"/>
</html:select>

My code in Action to load the collection

ResultSet rs=dbm.get_ResultSet("bbill");
rs.first();
while(rs.next())
{
vendor.add(new Vendor(rs.getString(1)));
}
rs.close();

bbf.setVendor(vendor);

I have a class Vendor. the code is

public class Vendor {
private String vendor;

/** Creates a new instance of Selections */
public Vendor() {
}
public Vendor(String vendor)
{
this.vendor=vendor;
}
public void setVendor(String vendor)
{
this.vendor=vendor;
}
public String getVendor()
{
return vendor;
}

When i run this application instead of loading the dropdown box with Strings, the <html ptions> tag load my dropdown box with Objects like this btch.Vendor@13497. Which is the best tag to get my Sring values.

For my ordinary text boxes i am using logic:iterate tag and it is working fine.

Please help me.
Some one advised me to use ordinary select tag and between the options tag load the values using bean:write. can i follow that?

regards
Surendar.
surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
Thanks Merill

In a thread regarding this you have given this code..

<html:select property="location" styleClass="textfield"> <html ptions name="locationList" /></html:select>

But that is not working for me. the exception says some thing like

Cannot find bean with name vendor.

So i have tried with the code that is given in my previous post. that displays the JSP page but with the dropdown loaded with objects.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If your collection contains objects rather than Strings, it is generally better to use the <htmlptionsCollection> tag rather than the <htmlptions> tag. Example:

<htmlptionsCollection name="batchbillForm" property="vendor" value="vendor" label="vendor" />

Here is the link to the documentation for this tag.
[ September 06, 2006: Message edited by: Merrill Higginson ]
surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
Thaks Merrill .Thats Great working fine.


regards,
Surendar
 
GeeCON Prague 2014
 
subject: My html:select is not working