code_junkie

Not getting the proper size of an ArrayList in JSP

Nov 12th, 2011
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. <%
  2. ArrayList<Alert> a = AlertGenerator.getAlert();
  3. pageContext.setAttribute("alt", a);
  4. %>
  5. <c:forEach var="alert" items="${alt}" varStatus="status" >
  6. <p>You have <%=alt.size()%> Active Alert(s)</p>
  7. <ul>
  8. <li><a href="#" class="linkthree">${alert.alert1}</a></li>
  9. <li><a href="#" class="linkthree">${alert.alert2}</a></li>
  10. <li><a href="#" class="linkthree">${alert.alert3}</a></li>
  11. </ul>
  12. </c:forEach>
  13.  
  14. package com.cg.mock;
  15.  
  16. import java.util.ArrayList;
  17.  
  18. public class AlertGenerator {
  19.  
  20. public static ArrayList<Alert> getAlert() {
  21.  
  22. ArrayList<Alert> alt = new ArrayList<Alert>();
  23.  
  24. alt.add(new Alert("alert1","alert2","alert3"));
  25.  
  26. return alt;
  27. }
  28.  
  29. }
  30.  
  31. package com.cg.mock;
  32.  
  33. public class Alert {
  34. String alert1;
  35. String alert2;
  36. String alert3;
  37. public Alert(String alert1, String alert2,String alert3) {
  38. super();
  39. this.alert1 = alert1;
  40. this.alert2 = alert2;
  41. this.alert3 = alert3;
  42. }
  43. public String getAlert1() {
  44. return alert1;
  45. }
  46. public void setAlert1(String alert1) {
  47. this.alert1 = alert1;
  48. }
  49. public String getAlert2() {
  50. return alert2;
  51. }
  52. public void setAlert2(String alert2) {
  53. this.alert2 = alert2;
  54. }
  55. public String getAlert3() {
  56. return alert3;
  57. }
  58. public void setAlert3(String alert3) {
  59. this.alert3 = alert3;
  60. }
  61.  
  62. }
  63.  
  64. package com.cg.mock;
  65.  
  66. public class Alert {
  67. String alert1;
  68. public Alert(String alert1) {
  69. super();
  70. this.alert1 = alert1;
  71. }
  72. public String getAlert1() {
  73. return alert1;
  74. }
  75. public void setAlert1(String alert1) {
  76. this.alert1 = alert1;
  77. }
  78. }
  79.  
  80. ArrayList<Alert> alt = new ArrayList<Alert>();
  81.  
  82. alt.add(new Alert("alert1");
  83. alt.add(new Alert("alert2");
  84. alt.add(new Alert("alert3");
  85.  
  86. return alt;
  87.  
  88. <p>You have <%=alt.size()%> Active Alert(s)</p>
  89. <ul>
  90. <c:forEach var="alert" items="${alt}" varStatus="status" >
  91.  
  92. <li><a href="#" class="linkthree">${alert.alert1}</a></li>
  93.  
  94. </c:forEach>
  95. </ul>
  96.  
  97. alt.add(new Alert("alert1","alert2","alert3"));
  98.  
  99. public class Alert {
  100. private String description;
  101. private String status;
  102. private Date raisedOn;
  103. public Alert(String description, String status) {
  104. this.description = description;
  105. this.status = status;
  106. this.raisedOn = new Date();
  107. }
  108. public String getDescription() { return description; }
  109. public String getStatus() { return status; }
  110. public Date getRaisedOn() { return raisedOn; }
  111. }
  112.  
  113.  
  114. ....
  115. alt.add(new Alert("Disk Almost Full", "Warning"));
  116. alt.add(new Alert("Disk Full", "Severe"));
  117. ...
  118.  
  119. ...
  120. <table>
  121. <tr><th>Description</th><th>Status</th><th>Raised</th></td>
  122. <c:forEach var="alert" items="${alt}">
  123. <tr>
  124. <td><c:out value="${alert.description}"/></td>
  125. <td><c:out value="${alert.status}"/></td>
  126. <td><c:out value="${alert.raisedOn}"/></td>
  127. </tr>
  128. </c:forEach>
  129. </table>
  130.  
  131. <%
  132. ArrayList<Alert> a = AlertGenerator.getAlert();
  133. pageContext.setAttribute("alt", a);
  134. %>
  135. <p>You have <%=alt.size()%> Active Alert(s)</p>
  136. <ul>
  137. <c:forEach var="alert" items="${alt}" varStatus="status" >
  138. <li><a href="#" class="linkthree">${alert.alert}</a></li>
  139. </c:forEach>
  140. </ul>
  141.  
  142. package com.cg.mock;
  143.  
  144. import java.util.ArrayList;
  145.  
  146. public class AlertGenerator {
  147.  
  148. public static ArrayList<Alert> getAlert() {
  149.  
  150. ArrayList<Alert> alt = new ArrayList<Alert>();
  151.  
  152. alt.add(new Alert("alert2"));
  153. alt.add(new Alert("alert2"));
  154. alt.add(new Alert("alert3"));
  155.  
  156. return alt;
  157. }
  158. }
  159.  
  160. package com.cg.mock;
  161.  
  162. public class Alert {
  163. String alert;
  164. public Alert(String alert) {
  165. this.alert = alert;
  166. }
  167. public String getAlert() {
  168. return alert;
  169. }
  170. public void setAlert(String alert) {
  171. this.alert = alert;
  172. }
  173. }
Add Comment
Please, Sign In to add comment