on 2009 Jan 23 3:42 PM
Hi
z Java class is setting request.attribute for a hashmap(Key, value) type.
I need to display the values of hashmap on the JSP.
Please help!
Thanks
ET
int alPriceSize = alPriceCondPanel.size();
String salesItemProductId = item_ID.getProductId().toString();
String itemIpcCondition = null;
HashMap z_itemprz = new HashMap();
for (int i = 0; i < ipcPricingCond.length; i++) {
IPCPricingCondition ipcCondition = ipcPricingCond<i>;
if (ipcCondition.getConditionTypeName().equalsIgnoreCase("ZCM1"))
{
String condDiscountValue = ipcCondition.getConditionValue();
String condDiscountTypeName = ipcCondition.getConditionTypeName();
String ipcCondDiscountRate = ipcCondition.getConditionRate();
String ipcCondDiscountDesc = ipcCondition.getDescription();
String condDiscountCurr = ipcCondition.getConditionCurrency();
String condDiscountCounter = ipcCondition.getCounter();
log.error("IPC Discount Counter: "+condDiscountCounter);
log.error("Discount value: "+condDiscountValue);
log.error("Discount Description: "+ipcCondDiscountDesc);
String chDot = ".";
int indxDot = condDiscountValue.indexOf(chDot, 3);
String condFinalDiscountVal = condDiscountValue.substring(0, indxDot);
String space = " ";
condDiscountCurr = condDiscountCurr.concat(space);
String ipcPhsDiscount = condFinalDiscountVal.concat(condDiscountCurr);
log.error("PHS Dicount Value: "+ipcPhsDiscount);
request.setAttribute("ipcPhsDiscount", ipcPhsDiscount);
z_itemprz.put( item_ID.getProductId().toString(),ipcPhsDiscount);
}
if (ipcCondition.getConditionTypeName().equalsIgnoreCase("ZA01"))
{
String condListValue = ipcCondition.getConditionValue();
String condListTypeName = ipcCondition.getConditionTypeName();
String condListRate = ipcCondition.getConditionRate();
String condListDesc = ipcCondition.getDescription();
String condListCurr = ipcCondition.getConditionCurrency();
String condListCounter = ipcCondition.getCounter();
log.error("IPC List Counter: "+condListCounter);
log.error("List Price value: "+condListValue);
log.error("List Price Description: "+condListDesc);
String chDot = ".";
int indxDot = condListRate.indexOf(chDot, 0) + 3;
String condFinalListPrice = condListRate.substring(0, indxDot);
String space = " ";
condListCurr = condListCurr.concat(space);
String ipcPhsListPrice = condFinalListPrice.concat(condListCurr);
// String ipcPhsListPrice = itemProdId.concat(ipcPhsListPrice1);
log.error("PHS List Value : "+ipcPhsListPrice);
request.setAttribute("ipcPhsListPrice", ipcPhsListPrice);
}
}
request.setAttribute("z_itemprz", z_itemprz);
ET,
You can do just the way you would do it in a Java class. In JSP, just use the <% java scrriptlets instead.
1. Define the HashMap package in the JSP page includes
2. In the scriptlet, get the z_itemprz from the request context - request.geAttribute(z_itemprz);
3. Remember to cast this to (HashMap)
4. Now that you have the HashMap, you can iterate or loop over and read the contents in the HashMap.
5. Assign the contents to local Java variables
6. Use the variables in <%= expressions to print it in the page.
More important - [see this link|http://www.sun.com/training/certification/java/index.xml]. )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ram
Please find the code developed below, it gave me an error of incompatible types found : java.lang.Object required: java.lang.String ipcPhsHashListPrice = z_itemListPrz.get(itemKey); ^ 1 error ].
Kindly help!
Thanks
<td class="price">
<% if (item.isPriceRelevant()) {
if (!ui.isZeroProductId() && ui.isElementVisible("order.item.grossValue", itemKey)) { %>
<%-- String ipcPhsListPrice = "";
if (request.getAttribute("ipcPhsListPrice") != null){
ipcPhsListPrice = (String)request.getAttribute("ipcPhsListPrice");
} %>
<%= ipcPhsListPrice + " " + JspUtil.encodeHtml(item.getCurrency()) --%>
<% String ipcPhsHashListPrice = "";
HashMap z_itemListPrz = new HashMap();
if (request.getAttribute("ipcPhsListPrice") != null)
{
z_itemListPrz = (HashMap) z_AccGroup.getAttribute("z_itemListPrz");
ipcPhsHashListPrice = z_itemListPrz.get(itemKey);
}
%>
<%= ipcPhsHashListPrice + " " + JspUtil.encodeHtml(item.getCurrency()) %>
<% }
}
// out.println("list prize:"+z_itemListPrz.get(itemKey));
%>
</td>
Hi Ram,
Thanks!
I am using session instead of Request parameter in the Action class now. I have three Hashmaps to be passed.
Action class session request:
session.setAttribute("z_itemprz", z_itemprz);
session.setAttribute("z_itemListPrz", z_itemListPrz);
session.setAttribute("z_itemYourPrz",z_itemYourPrz);
In the JSP I am declaring one session object at the start and i am defining the three Hashmaps also as given below:
HttpSession z_ListPriceSession = request.getSession();
HashMap z_itemListPrz = new HashMap(); //Hashmap List Price
HashMap z_itemYourPrz = new HashMap(); //Hashmap Your Price
HashMap z_itemprz = new HashMap(); //Hashmap Discount
For displaying the values i am doing as given below for each hashmap. Get the value for the key i.e. itemKey = item.getTechKey().getIdAsString(); as for the hashmap is mapped for the item_id as key and pricing cndtion value as Value.
<td class="price">
<% if (item.isPriceRelevant()) {
if (!ui.isZeroProductId() && ui.isElementVisible("order.item.grossValue", itemKey)) { %>
<% if (z_ListPriceSession.getAttribute("z_itemListPrz") != null)
{
z_itemListPrz = (HashMap) z_ListPriceSession.getAttribute("z_itemListPrz");
out.println(" "+z_itemListPrz.get(itemKey));
}
else
{
out.println("no values");
}
%>
<%= " "+ JspUtil.encodeHtml(item.getCurrency()) %>
<% }
}
%>
</td>
The doubt what i have is can one session object return the values of all the hashmap on JSP.
Please share me the matter if you have about session data.
Thanks
Ekta
Thanks a lot Ram!
able to view the pricing condtions through session variables.
Got all the pricing conditions on the JSP. Object is completed. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
23 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.