• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

error using html:options tag

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,

i am using following code in my jsp page
-----------------------

<html:select styleClass="formtext-1" property="painScale">
<% String totalPainScale []={"-1","1","2","3","4","5","6","7","8","9","10"}; %>
<html ptions collection="<%=totalPainScale%>"/>
</html:select>
------------------
i am getting error

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 276 in the jsp file: /pd/PatientComplaint.jsp
Generated servlet error:
The method setCollection(String) in the type OptionsTag is not applicable for the arguments (String[])
--------------------------

even i want the difference between html ption tag and html ptionsCollection tag

I have checked the difference in the followingdocs link.

I am cleared with html ptions tag but I not clear with html ptionsCollection tag.

clear my doubt with an example.

Thanks
[ March 28, 2007: Message edited by: sreenivas jeenor ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a few problems with your code.

First is the fact that any object used in a struts tag must be in some scope (either page, request, session, or application). It's not enough just to declare a scriptlet variable. So, your scriptlet should look like this:

This code puts the array in page scope, so now it's available to a Struts tag.

The second problem is that you're using the wrong attribute of the html:options tag. If you've got a collection of Strings and you want each String to be both the label and the value of the option, you simply specify the name of the collection or array as the name attribute. So, your html:options tag should look like this:


Regarding the difference between html:options and html:optionsCollection, here is the rule I generally use:

If you've got an array or collection of strings that represent both the label and the value of the option, use html:options just like I showed you in the example above.

If you've got a collection of JavaBeans for which one bean property represents the label and another represents the value, use html:optionsCollection. Example:

In the above example, the LabelValueBean has a label and a value property.
[ March 29, 2007: Message edited by: Merrill Higginson ]
 
sreenivas jeenor
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Merrill,

now i got the difference between the two.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic