You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by SP...@ixl.com on 2001/01/17 17:17:37 UTC

HASHTABLE - NEED HELP URGENT

Hi,

I am using Struts 0.5.

I have a bean called dispProductsBean which has a hashtable called
"products".

How do I get the contents of the hashtable in my jsp page using enumerate
tag.

Here is my jsp:
<%@ page language="java" %>
<%@ page session="true" import="java.util.*" %>
<%@ taglib uri="/WEB-INF/struts.tld" prefix="struts" %>


<%@page contentType="text/html"%>

<html>
<head><title><struts:message key="product.title"/></title></head>
<body>

<h3><struts:message key="product.pageHeading"/></h3>

<struts:form name="dispProductsBean" type="com.ixl.hmem.dispProductsBean">

	<div align="center">
	<h3><struts:message key="product.listTitle"/></h3>
	</div>
	<struts:property property="size" />
</struts:form>


</body>
</html>
Please help


Sharmila Pandith
Software Engineer
iXL Inc.

phone: 212-500-5180
AIM: spandith
Yahoo: spandith
MSN: spandith

This message is intended only for the use of the Addressee and may contain
information that is PRIVILEGED and CONFIDENTIAL. If you are not the intended
recipient, dissemination of this communication is prohibited. If you have
received this communication in error, please erase all copies of the message
and its attachments and notify us immediately. 



Re: HASHTABLE - NEED HELP URGENT

Posted by Ted Husted <ne...@husted.com>.
Using the 1.0 iterate tag (never used 0.5 or enumerate myself), you
would print the elements of a Hashtable like this:

          <%@ page language="java" %>
          <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
          <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

                <%
                        java.util.Hashtable list = new
java.util.Hashtable();
                list.put("1","First");
                list.put("2","Second");
                list.put("3","Third");
                list.put("4","Fourth");
                list.put("5","Fifth");
                pageContext.setAttribute("list", list,
PageContext.PAGE_SCOPE);
       %>
       <html><body><p>
       <logic:iterate id="myCollectionElement" name="list">
                Element Value: <bean:write name="myCollectionElement"
/><br />
       </logic:iterate>
       </p></body</html>

If you want them on the same line, take out the <br>.

If you wanted to print the values and key seperately, that would be
trickier, since Hashtable does not provide a property method that
exposes just the key. 

In the above example, since an actual property is not specified,
bean:write just calls toString, and prints that.

To get the key or value, you probably need to subclass Hashtable and
provide your own property that did something roughly like 

public object getKey() {
  get(object key);
  return(key);
}

Then you could do something like 

<logic:iterate id="myCollectionElement" name="list">
     Key Value: <bean:write  name="myCollectionElement"
property="key">
</logic:interate>

Of course, to get just the value, there would have to be a property for
that too.

HTH.

-Ted.

*********** REPLY SEPARATOR  ***********

On 1/17/2001 at 11:17 AM SPandith@ixl.com wrote:

Hi,

I am using Struts 0.5.

I have a bean called dispProductsBean which has a hashtable called
"products".

How do I get the contents of the hashtable in my jsp page using
enumerate
tag.

Here is my jsp:
<%@ page language="java" %>
<%@ page session="true" import="java.util.*" %>
<%@ taglib uri="/WEB-INF/struts.tld" prefix="struts" %>


<%@page contentType="text/html"%>

<html>
<head><title><struts:message key="product.title"/></title></head>
<body>

<h3><struts:message key="product.pageHeading"/></h3>

<struts:form name="dispProductsBean"
type="com.ixl.hmem.dispProductsBean">

	<div align="center">
	<h3><struts:message key="product.listTitle"/></h3>
	</div>
	<struts:property property="size" />
</struts:form>


</body>
</html>
Please help


Sharmila Pandith
Software Engineer
iXL Inc.

phone: 212-500-5180
AIM: spandith
Yahoo: spandith
MSN: spandith

This message is intended only for the use of the Addressee and may
contain
information that is PRIVILEGED and CONFIDENTIAL. If you are not the
intended
recipient, dissemination of this communication is prohibited. If you
have
received this communication in error, please erase all copies of the
message
and its attachments and notify us immediately.