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

error using html:options tag

sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
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 ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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 htmlptions 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 htmlptions tag should look like this:


Regarding the difference between htmlptions and htmlptionsCollection, 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 htmlptions 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 htmlptionsCollection. Example:

In the above example, the LabelValueBean has a label and a value property.
[ March 29, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
Thanks Merrill,

now i got the difference between the two.
 
 
subject: error using html:options tag