K
kbd
Hello:
I can not understand what I have done wrong. I need to test if a
key/value pair exists in a hashmap from within a JSP. I though this
would be simple. Struts is also involved here, but I do not believe
that Struts is causing any problems.
The key/values are placed in the hashmap as follows:
hMap = new HashMap(20);
while ( rs.next() ) {
fRoles = new FormRoles();
fRoles.setFormName(rs.getString("FormName"));
fRoles.setCreate( ( rs.getInt("C")==1)? true:false );
fRoles.setRead( ( rs.getInt("R")==1)? true:false );
fRoles.setUpdate( ( rs.getInt("U")==1)? true:false );
fRoles.setDelete( ( rs.getInt("D")==1)? true:false );
hMap.put(rs.getString("FormName"), fRoles);
} //while
user.setFormRoles( hMap);
In the above code I place the FormRoles objects into the hashmap with
a String as the key. I will be able to retrieve the objects with a
String. Ie. if the form name is "manager", get("manager") will return
the corresponding FormRole object.
Correct??
Here is my JSP:
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="c_rt" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<head>
<title>Welcome World!</title>
<html:base/>
</head>
<body bgcolor="white">
<logicresent scope="session" name="user">
<h3>Welcome <bean:write name="user" property="userId"/>!</h3>
<br>
<bean:write name="user" property="userFName"/>
<bean:write name="user" property="userLName"/>
</logicresent>
<logic:notPresent scope="session" name="user">
<h3>Welcome World!</h3>
</logic:notPresent>
<html:errors/>
<ul>
<li><html:link forward="logon">Sign in</html:link></li>
<logicresent scope="session" name="user">
<li><html:link forward="logoff">Sign out</html:link></li>
<br>
<br>
<bean:define id="fRoles" name="user" property="frmRoles"
type="java.util.HashMap" toScope="page"/>
<logic:iterate id="element" name="fRoles">
Key is <bean:write name="element" property="key"/> <br>
Value is <bean:write name="element" property="value"/> <br>
</logic:iterate>
<c:forEach var="element" items="${fRoles}">
<cut value="Key=${element.key}, Value=${element.value}"/>
<br>
</c:forEach>
fRoles.size() returns <%= fRoles.size() %> <br>
fRoles.keySet() returns <%= fRoles.keySet() %> <br>
fRoles.containsKey("manager") returns <%=
fRoles.containsKey("manager") %>
<br>
<c:forEach items="${fRoles}" var="item">
<c:if test="${item.key == 'manager'}">
Found manager
</c:if>
</c:forEach>
<c:choose>
<c:when test= '<% fRoles.get("manager") != null %> '>
Found formRoles manager
</c:when>
<ctherwise>
NOT Found
</ctherwise>
</c:choose>
</logicresent>
</ul>
<img src='struts-power.gif' alt='Powered by Struts'>
</body>
</html>
Here is the resulting page:
Welcome BC!
B C
* Sign in
* Sign out
Key is country
Value is com.parkerglobal.mgrappBusiness.FormRoles@a2e19e
Key is manager
Value is com.parkerglobal.mgrappBusiness.FormRoles@18a62f6
Key is region
Value is com.parkerglobal.mgrappBusiness.FormRoles@6742d0
Key is currency
Value is com.parkerglobal.mgrappBusiness.FormRoles@1539d49
Key is classificationType
Value is com.parkerglobal.mgrappBusiness.FormRoles@7b5cb8
Key is managerFundClass
Value is com.parkerglobal.mgrappBusiness.FormRoles@1046270
Key is pgsPortfolio
Value is com.parkerglobal.mgrappBusiness.FormRoles@dad4b8
Key is pgsMgrAllocations
Value is com.parkerglobal.mgrappBusiness.FormRoles@c39410
Key is pgsPortfolioShareClass
Value is com.parkerglobal.mgrappBusiness.FormRoles@2db73e
Key is managerFund
Value is com.parkerglobal.mgrappBusiness.FormRoles@1594ba3
Key is classification
Value is com.parkerglobal.mgrappBusiness.FormRoles@174f478
Key=country , Value=com.parkerglobal.mgrappBusiness.FormRoles@a2e19e
Key=manager , Value=com.parkerglobal.mgrappBusiness.FormRoles@18a62f6
Key=region , Value=com.parkerglobal.mgrappBusiness.FormRoles@6742d0
Key=currency ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@1539d49
Key=classificationType ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@7b5cb8
Key=managerFundClass ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@1046270
Key=pgsPortfolio ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@dad4b8
Key=pgsMgrAllocations ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@c39410
Key=pgsPortfolioShareClass ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@2db73e
Key=managerFund ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@1594ba3
Key=classification ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@174f478
fRoles.size() returns 11
fRoles.keySet() returns [country , manager , region , currency ,
classificationType , managerFundClass , pgsPortfolio ,
pgsMgrAllocations , pgsPortfolioShareClass , managerFund ,
classification ]
fRoles.containsKey("manager") returns false
NOT Found
This tells me that I have a valid hashmap object. But why, oh why
does fRoles.containsKey("manager") return false. I am stumped.
Thanks much for looking at this issue.
best regard.
kd
I can not understand what I have done wrong. I need to test if a
key/value pair exists in a hashmap from within a JSP. I though this
would be simple. Struts is also involved here, but I do not believe
that Struts is causing any problems.
The key/values are placed in the hashmap as follows:
hMap = new HashMap(20);
while ( rs.next() ) {
fRoles = new FormRoles();
fRoles.setFormName(rs.getString("FormName"));
fRoles.setCreate( ( rs.getInt("C")==1)? true:false );
fRoles.setRead( ( rs.getInt("R")==1)? true:false );
fRoles.setUpdate( ( rs.getInt("U")==1)? true:false );
fRoles.setDelete( ( rs.getInt("D")==1)? true:false );
hMap.put(rs.getString("FormName"), fRoles);
} //while
user.setFormRoles( hMap);
In the above code I place the FormRoles objects into the hashmap with
a String as the key. I will be able to retrieve the objects with a
String. Ie. if the form name is "manager", get("manager") will return
the corresponding FormRole object.
Correct??
Here is my JSP:
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="c_rt" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<head>
<title>Welcome World!</title>
<html:base/>
</head>
<body bgcolor="white">
<logicresent scope="session" name="user">
<h3>Welcome <bean:write name="user" property="userId"/>!</h3>
<br>
<bean:write name="user" property="userFName"/>
<bean:write name="user" property="userLName"/>
</logicresent>
<logic:notPresent scope="session" name="user">
<h3>Welcome World!</h3>
</logic:notPresent>
<html:errors/>
<ul>
<li><html:link forward="logon">Sign in</html:link></li>
<logicresent scope="session" name="user">
<li><html:link forward="logoff">Sign out</html:link></li>
<br>
<br>
<bean:define id="fRoles" name="user" property="frmRoles"
type="java.util.HashMap" toScope="page"/>
<logic:iterate id="element" name="fRoles">
Key is <bean:write name="element" property="key"/> <br>
Value is <bean:write name="element" property="value"/> <br>
</logic:iterate>
<c:forEach var="element" items="${fRoles}">
<cut value="Key=${element.key}, Value=${element.value}"/>
<br>
</c:forEach>
fRoles.size() returns <%= fRoles.size() %> <br>
fRoles.keySet() returns <%= fRoles.keySet() %> <br>
fRoles.containsKey("manager") returns <%=
fRoles.containsKey("manager") %>
<br>
<c:forEach items="${fRoles}" var="item">
<c:if test="${item.key == 'manager'}">
Found manager
</c:if>
</c:forEach>
<c:choose>
<c:when test= '<% fRoles.get("manager") != null %> '>
Found formRoles manager
</c:when>
<ctherwise>
NOT Found
</ctherwise>
</c:choose>
</logicresent>
</ul>
<img src='struts-power.gif' alt='Powered by Struts'>
</body>
</html>
Here is the resulting page:
Welcome BC!
B C
* Sign in
* Sign out
Key is country
Value is com.parkerglobal.mgrappBusiness.FormRoles@a2e19e
Key is manager
Value is com.parkerglobal.mgrappBusiness.FormRoles@18a62f6
Key is region
Value is com.parkerglobal.mgrappBusiness.FormRoles@6742d0
Key is currency
Value is com.parkerglobal.mgrappBusiness.FormRoles@1539d49
Key is classificationType
Value is com.parkerglobal.mgrappBusiness.FormRoles@7b5cb8
Key is managerFundClass
Value is com.parkerglobal.mgrappBusiness.FormRoles@1046270
Key is pgsPortfolio
Value is com.parkerglobal.mgrappBusiness.FormRoles@dad4b8
Key is pgsMgrAllocations
Value is com.parkerglobal.mgrappBusiness.FormRoles@c39410
Key is pgsPortfolioShareClass
Value is com.parkerglobal.mgrappBusiness.FormRoles@2db73e
Key is managerFund
Value is com.parkerglobal.mgrappBusiness.FormRoles@1594ba3
Key is classification
Value is com.parkerglobal.mgrappBusiness.FormRoles@174f478
Key=country , Value=com.parkerglobal.mgrappBusiness.FormRoles@a2e19e
Key=manager , Value=com.parkerglobal.mgrappBusiness.FormRoles@18a62f6
Key=region , Value=com.parkerglobal.mgrappBusiness.FormRoles@6742d0
Key=currency ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@1539d49
Key=classificationType ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@7b5cb8
Key=managerFundClass ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@1046270
Key=pgsPortfolio ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@dad4b8
Key=pgsMgrAllocations ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@c39410
Key=pgsPortfolioShareClass ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@2db73e
Key=managerFund ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@1594ba3
Key=classification ,
Value=com.parkerglobal.mgrappBusiness.FormRoles@174f478
fRoles.size() returns 11
fRoles.keySet() returns [country , manager , region , currency ,
classificationType , managerFundClass , pgsPortfolio ,
pgsMgrAllocations , pgsPortfolioShareClass , managerFund ,
classification ]
fRoles.containsKey("manager") returns false
NOT Found
This tells me that I have a valid hashmap object. But why, oh why
does fRoles.containsKey("manager") return false. I am stumped.
Thanks much for looking at this issue.
best regard.
kd