5 Replies Latest reply on Dec 22, 2010 4:49 AM by Eswara MoorthyNEC

    Is possible : javascript access c:forEach tag value?

    Eswara MoorthyNEC Newbie



            i have displyed values using c:forEach. (The values got from backing bean).


      Then I want to write javascript for read data from c:forEach values. Is possible?



      <%@page contentType="text/html" pageEncoding="UTF-8"%>
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
      <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
      <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
      <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                  <script type="text/javascript">
                      function getEachValue()
                         //Here i want to write a code for, access the c:forEach tag (displayed) value
                  <h:form id="sampleForm" >                
                      <c:forEach items="${bean.pageHits}" var="pageHit">
                          <c:out value="${pageHit.period} : "/>
                          <c:out value="${pageHit.hits}"/></br>
                      <a4j:commandButton id="getvalue" value="GetValue" oncomplete="getEachVaue()"/>



      If I click GetValue button, then the javascript read all value in c:forEach.





      import java.util.ArrayList;
      import java.util.List;
      public class Bean
         private List<PageHit> pageHits = new ArrayList<PageHit>();
          public Bean()
              pageHits = loadItSomehow();
          public List<PageHit> getPageHits(){
              return pageHits;
          public void setPageHits(List<PageHit> pageHits){
              this.pageHits = pageHits;
          private List<PageHit> loadItSomehow()
              List<PageHit> localpageHits = new ArrayList<PageHit>();
              localpageHits.add(new PageHit("Jan 2010",60));
              localpageHits.add(new PageHit("Feb 2010",30));
              localpageHits.add(new PageHit("Mar 2010",90));
              return localpageHits;





      public class PageHit {
          private String period;
          private Integer hits;
          public PageHit(String period, Integer hits){
              this.period = period;
              this.hits = hits;
          public String getPeriod(){
              return period;
          public void setPeriod(String period){
              this.period = period;
          public Integer getHits(){
              return hits;
          public void setHits(Integer hits){
              this.hits = hits;



      Help me.

      Thanks in advance.