Showing posts with label Struts. Show all posts
Showing posts with label Struts. Show all posts

Sep 11, 2012

Struts2 - Iterating List of Map in struts jsp.

Java Object Declaration

Assume that the declaration was on servlet class that the getListMapmethod can access on your JSP file.
public List<Map<String, String>> getListMap(String pRatingCriteria){

  List<Map<String, String>> myList = new ArrayList<Map<String,String>>();
  Map<String, String> myMap = null;

  myMap = new HashMap<String, String>();
  myMap.put("fname", "Winzter");
  myMap.put("lname", "Corpuz");
  myList.add(myMap);


  myMap = new HashMap<String, String>();
  myMap.put("fname", "Winzter");
  myMap.put("lname", "Corpuz");
  myList.add(myMap);


  myMap = new HashMap<String, String>();
  myMap.put("fname", "Juan");
  myMap.put("lname", "Dela Cruz");
  myList.add(myMap);

  return myList;
}

Here your JSP code to iteration the List Map

<s:iterator var="myMap" value="getListMap()" status="rowStatus">
<tr>
  <td><s:property value="key" /></td>
  <td><s:property value="value" />%</td>
</tr>
</s:iterator>

Sep 4, 2012

Struts - Iteration Map in jsp using Struts

This just one example from.

<logic:iterate id="mapEntry" name="yourHashMap">
  <bean:define id="gift" name="mapEntry" property="value">
  <tr>
    <td><bean:write name="mapEntry" property="key"></td>
    <td><bean:write name="gift" property="productName"></td>
    <td><bean:write name="gift" property="price"></td>
  </tr>
</logic:iterate>
Or maybe like this one.
<s:iterator value="YourListMap" status="stat">
  <tr>
    <th><s:property value="#stat.index"/></th>
    <td><s:property value="key"/></td>
    <td><s:property value="value"/></td>
  </tr>
</s:iterator>
For more example:
  • Aug 14, 2012

    Struts 2 - IF tag

    IF tag with OR

    <s:if test="%{x==1 || z==2}">
       <!--Your data goes here... -->
    </fi>

    Jun 28, 2012

    Struts - How to access Method from your action class to you JSP file.

    From you action class
    public class YourAction extends ActionSupport{ // NOTE to public this data so you can access in JSP public String name="Winzter"; public String getName() { return this.name; } } // class
    From you JSP file.
    <c:out value="${action.getName()}" escapeXml="false"></c:out>
    If the property name was declare public, you can access by this one.
    <c:out value="${name}" escapeXml="false"></c:out>
    NOTE:${action.getName()} in only working on Tomcat7.x.x.

    May 14, 2012

    Struts - Calculating on struts tags

    We need to initilaize variable.
    <s:set var="total" value="%{0.00}"/>
    
    Calculation
    <s:set var="total" value="%{amount + #attr.total}" />
    

    May 9, 2012

    Struts - Formating Text, Date or Number


    Formating Pattern

    format.time = {0,time}
    format.number = {0,number,#0.0##}
    format.percent = {0,number,##0.00'%'}
    format.money = {0,number,\u00A4##0.00}

    Formatting a number

    <s:property value="getText('{0,number,#,##0.00}',{product.price})" />