This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts Option Collection using MAP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Option Collection using MAP" Watch "Struts Option Collection using MAP" New topic
Author

Struts Option Collection using MAP

Vis Deo
Ranch Hand

Joined: Jul 02, 2004
Posts: 41

I am trying to implement dropdown using MAP data and getting error

Here is the code, Can you please help? is it possible to use value & key?

Part of JSP



<%@ page import="java.util.Collections" %>
<%@ page import="java.util.HashMap" %>

<html:html>

<%
HashMap params = new HashMap();
params.put("param1", "param1Value");
params.put("param2","param2Value");
pageContext.setAttribute("linkParams", params);
%>


<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
<html:form method="get" action="listType" >

<htmlptions collection="linkParams" property="params" value="value" label="key"/> </html:select>

</html:form>
</html:html>
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags.

I am trying to implement dropdown using MAP data and getting error


What's the error?
Vis Deo
Ranch Hand

Joined: Jul 02, 2004
Posts: 41


error is given below.
I want to know syntax to use Map for options collection
if this syntax is correct?
<htmlptions collection="linkParams" property="params" label="value" value="key"/>

As the Map is generalized and will not have any specific getter / setter but through getKey and getValue?
Is using MAp is supported at all?

Map of specific value object that has getter setter may be easy to code bu my situation is addressing it for generalized codes table
that has code and description


ERROR! Failed to process your request.
JSPG0227E: Exception caught while translating /patient_setAneurysmType.jsp: /patient_setAneurysmType.jsp(176,6) --> JSPG0123E: Unable to locate tag attribute info for tag attribute label.


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Did you read the error message?
The server wrote:Unable to locate tag attribute info for tag attribute label.

<html:options> documentation
Vis Deo
Ranch Hand

Joined: Jul 02, 2004
Posts: 41
I found the syntax

<htmlptions collection="MAPTYPES" property="key" labelProperty="value" />

and in Action form set the MAP to session like


session.setAttribute("MAPTYPES",MyDao.getMyTypeMap());

Thanks
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Struts Option Collection using MAP
 
It's not a secret anymore!