Html:select inside logic:iterate

hi,
I am having a string type corresponding to the select attribute in my form bean. Since this select tag is inside the logic:iterate all the names of the select boxes are same. i.e myLabel in this context. So, how can i set the value to select box. do i need to change the data type for labelValue in form bean.
my form bean is given below:
here the listTotal is the total of the combo and listValue is the individual combo
     public ArrayList listTotal;
     public Collection getListTotal()
          return (Collection)listTotal;
     public void setListTotal(ArrayList total)
          this.listTotal = total;
     public ArrayList listValues;
     public void setListValues(ArrayList values)
               this.listValues = values;
     public ArrayList getListValues()
          return  listValues;
                     String myLabel;
     public String getMyLabel()
     return myLabel;
     public void setMyLabel(String myLabel)
     this.myLabel = myLabel;
And i m setting the values in the action class
          ArrayList listTotal = new ArrayList(1);
          ArrayList listValues = new ArrayList();
          listValues.add(new LabelValueBean("k1", "Value1"));
          listValues.add(new LabelValueBean("k2", "Value2"));
          listValues.add(new LabelValueBean("k3", "value3"));
          listTotal.add(listValues);
          listValues = new ArrayList();
          listValues.add(new LabelValueBean("l1", "Value4"));
          listValues.add(new LabelValueBean("l2", "Value5"));
          listValues.add(new LabelValueBean("l3", "value6"));
          listTotal.add(listValues);
          listValues = new ArrayList();
          listValues.add(new LabelValueBean("m1", "Value7"));
          listValues.add(new LabelValueBean("m2", "Value8"));
          listValues.add(new LabelValueBean("m3", "value9"));
          listTotal.add(listValues);
          employeeForm.setListTotal(listTotal);
jsp code
<logic:iterate id="listValues" name="EmployeeForm" property="listTotal" indexId="index">
<tr><td>
<html:select property="myLabel" >
<html:options collection="listValues" labelProperty="label" property="value"/>
</html:select>
</logic:iterate>

hi,
instead of having it as a array i thought of going for an array list so that the manipulation would be much easier. ok here is my code.
    //This is the array list for names of the drop downs.
    private ArrayList selectedList;
    public ArrayList getSelectedList()
        return selectedList;
    public void setSelectedList(ArrayList pselectedList)
       this.selectedList = pselectedList;
    public ListValueVO getSelected(int index)
       return (ListValueVO) selectedList.get(index);
    }I have already mentioned in my previous posts that i have 3 lists in my form bean. One list for individual combo box. Another list for total number of combo boxes. The third list for the names of the combo boxes. Pls let me know whether i m going in the correct direction or not.

Similar Messages

  • logic:iterate inside logic:iterate

    How to use <logic:iterate> inside another <logic:iterate>?? pls explain me with example......i found in google that its possible but example was not clear....please help me

    oppsss i throught it the other way around
    are you trying to populate values of a single Combobox ??
    if yes Try with
    <html:select name="detailForm" property="selectedValue" indexed="true" >
        <logic:iterate name="detailForm" property="selectedAction" id="row">
              <html:option value="<%=row%>"><%=row%></html:option>
        </logic>
    </html:select>where you would have properties something like the once below in your Form bean.
    public String getSelectedValue(){
      return selectedValue;
    public void setSelectedValue(String selectedValue){
       this.selectedValue = selectedValue;
    public String[] getSelectedAction(){
    return selectedAction;
    public void setSelectedAction(String [] string) {
    this.selectedAction=selectedAction;
    }Hope this might help :)
    REGARDS,
    RaHuL

  • Ajax input inside logic:iterate

    sorry.. topic sent to the wrong forum inadvertantly..
    Message was edited by:
    nisha20

    Hi Nisha,
    I think I am facing a similar kind of problem like the one you have posted. Can you or anyone else help me out in this?
    Here is my problem ---------------------->>>
    I am having a page with a table whose data I am pre-populating when the page loads. The data is coming from the database based on the name of the user.
    The page gets loaded via a struts action call and the table data are populated using the <logic:iterate> and <bean:write> tags.
    Now, I have a drop down list, which contains the list of all possible users. If I change the user name from this drop-down my table data should change and this should be done without refreshing the page, which means I have to use AJAX.
    SO, my question is, how can I get the changed data placed into the table without having to change the existing codes for <logic:iterate>?
    Can anyone please help me on this?
    Thanks in advance.
    Regards

  • Reg logic:iterate Urgent

    Hi All,
    Having doubt in <logic:iterate>... I am using the following for getting two ArrayList into a JSP using form bean.
    Im having table consisting of 5 column
    element1 element2 element3 element4 element5
    In this element2 is a list which display value in the label and element3 is another list which display the values in combo box.
    I need to know how to iterate two different list in the same row.... using <logic:iterate>...
    Pls Help me..
    Thanks in Advance.. For providing the solution..

    You have two ArrayList to be iterated in the same row but in defferent column.
    <td>
    <logic:iterate id="list1" name="ArraList1">
    <bean:write name="list1" property="propertyname"/>
    </logic:iterate>
    </td>
    <td>
    <html:select property="">
    <logic:iterate id="list2" name="ArraList2">
    <html:option value=""><bean:write name="list2" property="propertyname"/></html:option>
    </logic:iterate>
    </html:select>
    </td>

  • Using properties from a propery file (for i18n support) in a html:select

    <Newbie alert!>
    OK, I' d like to be able to put text strings used by my JSP/Struts pages in a properties file so that we can change them for different languages. So I have a file referenced in struts-config.xml as such:
    <message-resources parameter="com.myproject.resources.ApplicationResources"/>
    This works fine and I can use tags like: <bean:message key="prompt.decision"/> in my JSP files.
    I would like to be able to use strings defined in the property file also for a dropdown list like such:
    <html:select name="displayForm" property="scoreFinalDecision" >
         <html:option value="Approved"><bean:message key="option.approved"/></html:option>
         <html:option value="Denied"><bean:message key="option.denied"/></html:option>
    etc etc
    </html:select>
    This works, but I would like the value (i.e. value="Approved") also to be picked up from the
    property file, not hard-coded like above.
    How can I do that? I know that I could pick up the values from a Collection using html:options,
    but I don't understand how that would help me get the values from the property file?
    </Newbie>
    Many thanks,
    Tattersail (who notices that his forum doesn't undertand international characters: ���)

    Well you could use an <html:optionsCollection tag
    Just fetch the content of your property file in your action and then populate a vector with labelvalubean object (comes with the struts package) org.apache.struts.util.LabelValueBean
    labels = new Vector();
    //loop here
    LabelValueBean label = new LabelValueBean("value","label");
    labels.add(label);
    //end loop
    yourForm.setYourOptionCollection(label);
    The in your form you write something like
    <html:select name="displayForm" property="scoreFinalDecision" >
    <html:optionsCollection property="your property here" />
    </html:select>
    it will iterate through your vector and display the options

  • How to select a drop down option item while using logic:iterate?

    I am using the following peice of code -
    {color:#808080}+String countrySelected = (String)request.getAttribute("country");+
    +....+
    +<logic:iterate id="countryVO" name="countryList" type="com.sa.biz.vo.airport.CountryVO">+
    +<%+
    +if (countrySelected != null){+
    String countrySel = countryVO.getCountryCode().toString();
    String selected = (countrySel.equalsIgnoreCase(countrySelected)) ? " " "Selected" : " ";+
    +%>+
    +<option value="<%=countryVO.getCountryCode()%>*<%=selected%>*"><bean:write property="countryName" name="countryVO"/></option>+
    +<%+
    +}+
    +%>+{color}
    {color:#808080}+</logic:iterate>+
    {color}{color:#000000}The drop down is a list of country names (value - country code, display text - country name) which gets populated from the database. I need to ensure that the countrySelected is the menu item which gets selected in the drop down.
    The expected option item is not rendered as selected when i run this code? Please help!!{color}

    <option value="<%=countryVO.getCountryCode()%>" <%=selected%>>Apply the above change which should help you out on the same. :)
    REGARDS,
    RaHuL

  • html:select Struts tag problems

    hello
    I've a bean "Profile" in my sessionScope under name "myProfile"
    This bean is defined as
    public class Profile implements java.io.Serializable  {
         private User user;
         private List<Groups> groups;
         private List<Function> function;
         private List<Services> services;
         etc. .-.... getter and setter.....
    }the "services list" is full of data
    now in my jsp I want to print all the services in a select box. I'm using struts so I do
    <html:select property="serviceId">
          <html:options collection="${myProfile.services}" property="idSoc" labelProperty="descrizione" />
                        </html:select>it doesn't works..the console says
    Cannot find bean under name [it.object.Services@16b5518, it.object.Services@19fdafc]
    I've read the documentation.. but I don't understand if in the collection attribute I can put only the name of a bean that identify a collection...
    I can't use EL?
    I try do use a bean:define and to put its name in the collection attribute
    <bean:define id="myBean" value="${myProfile.services}"/>
                   <html:select property="societaId" >
                             <html:options collection="myBean" property="idSoc" labelProperty="descrizione" />
                        </html:select>but it still doesn't work.. it says
    Cannot create iterator for [it.object.Services@16b5518, it.object.Services@19fdafc]
    what the way to solve this problem
    thanks
    martina

    <html:select>
    <html:optionsCollection name = "myProfile"
    property = "services" value ="idSoc" label =
    "descrizione"/>
    /html:select>yes evnafets
    you're right
    this code works!
    but there's a problem. To simplify this post I say I've a bean with a Collection inside that I want to iterate.
    In my real application I've a session bean with another bean inside that contains the Collection. I've one more level (3 levels instead 2)
    whit the code you suggest I can't search inside it...
    I mean over myProfile I've onother bean that contains it and it's in the session
    bean1 -> myProfile -> List of Services
    from the session I can take by name only the "bean1"
    do you know what's the solution in this case?
    I've used some code like this
    <bean:define id="myBean" name="bean1" property="profilo"></bean:define>
    <html:select>
            <html:optionsCollection name = "myBean" property = "services" value ="idSoc" label = "descrizione"/>
    </html:select>it works..as you suggest I can specify only attribute names so I think this is the right way... or?!
    thanks a lot for yor help
    martina

  • Preselect an option in html:select

    Hey,
    I am implementing struts in my application. How do i preselect an option in <html:select> tag
    here is what i am doing but the option does not get preselected.. the collection below returns A, B , C etc..
    <html:select property="accountClass" name="criteriaForm" value ="B" styleClass="selectBoxStyle">
    <logic:iterate id="myCollectionElement" collection="<%= Util.getAllClasses() %>">
    <html:option value ="<bean:write name="myCollectionElement" />">
    <bean:write name="myCollectionElement" /></html:option>
    </logic:iterate>     
    </html:select>
    everything seem to work fine except value "B" in the list box is not preselected.. how do i achieve this??
    Thanks
    KM

    Try using the <html:options> tag.
    <html:select property="accountClass" value="B">
        <html:options collection="<%= Util.getAllClasses() %>"
                      property="someValue"
                      labelProperty="someDescription" />
    </html:select>

  • Help with Jsp: logic:iterate  Cannot create iterator for this collection

    Hello,
    I am developing a jsp with struts. This is the snap of the code:
            <logic:iterate id="prod" collection="productList" >
              <tr align="center">
                   <td><html:text property="prodDesc" size="50" indexed="true"/></td>
                   <td>
                        <html:select property="prodUnit" indexed="true">
                             <option selected>-</option>
                            <OPTION VALUE='NMB'>NMB
                             <OPTION VALUE='TEN'>TEN
                             <OPTION VALUE='TPR'>TPR
                             <OPTION VALUE='GWH'>GWH
                        </html:select>
                   </td>
                   <td><html:text property="prodQty" size="20" indexed="true"/></td>
                   <td><html:text property="prodVal" size="20" indexed="true"/></td>               
              </tr>
            </logic:iterate>"productList" is defined as an array of Product[], "prod" is defined as a single Product object in the form. But when i run the page, it gives me this errors:
    "javax.servlet.jsp.JspException: Cannot create iterator for this collection".
    I also tried to make "productList" an ArrayList type, but it game me this same error.
    We are using Websphere 4.0 with Struts 1.1.
    Anyone can help?
    Thanks a lot.
    All the best,
    warren

    Hi , I have similar problem. wonder anyone can help me. I have a datastructure. ArrayList contains list of Hashtable; each Hashtable has two key-value sets ; for each key-value set , value is a ValueObject.
    My jsp works ok. but when I click on the radio butten for one radio group, it sets not only the porperty on that row, but the rows belows ,which suppose to be another radio group , because I am using indexed="true". each row should be a individual group seperated by the name poDisplayVO[i] , as show in the html generated .
    <!-- JSP -->
    <logic:iterate id="poDisplayVO"
    name="testForm"
    property="poDisplayVOList"
    type="java.util.Hashtable">
    <tr>
    <td>
    <bean:write name="poDisplayVO" property="name"/>
    </td>
    <td>          
    <% String val = ((java.util.Hashtable)poDisplayVO).get("subjAreaName").toString();%>
    <html:radio indexed="true" name="poDisplayVO" property="fosVO.select" value="<%=val %>" />
    <bean:write name="poDisplayVO" property="subjAreaName"/>
    </td>
    <td>           
    <html:radio indexed="true" name="poDisplayVO" property="fosVO.select" value="no" /> NO
    </td>
    <td>           
    <html:radio indexed="true" name="poDisplayVO" property="fosVO.select" value="yes" /> YES
    </td>
    </tr>
    </logic:iterate>
    <! ------------------------ html genterated ------------------------------------------------>
    the HTML generated as folllows:
    <tr>
    <td>
              Accounting Studies
    </td>
    <td>          
         <input type="radio" name="poDisplayVO[0].fosVO.select" value="Accounting">
              Accounting
    </td>
    <td>           
         <input type="radio" name="poDisplayVO[0].fosVO.select" value="no"> NO
    </td>
    <td>           
         <input type="radio" name="poDisplayVO[0].fosVO.select" value="yes"> YES
    </td>
    </tr>
    <tr>
    <td>
              Accounting Studies
    </td>
    <td>          
         <input type="radio" name="poDisplayVO[1].fosVO.select" value="Bookkeeping">
              Bookkeeping
    </td>
    <td>           
         <input type="radio" name="poDisplayVO[1].fosVO.select" value="no"> NO
    </td>
    <td>           
         <input type="radio" name="poDisplayVO[1].fosVO.select" value="yes"> YES
    </td>
    </tr>
    <tr>
    <td>
              Accounting Studies
    </td>
    <td>          
         <input type="radio" name="poDisplayVO[2].fosVO.select" value="Computerized Accounting(Duplicate)">
              Computerized Accounting(Duplicate)
    </td>
    <td>           
    <input type="radio" name="poDisplayVO[2].fosVO.select" value="no"> NO
    </td>
    <td>           
    <input type="radio" name="poDisplayVO[2].fosVO.select" value="yes"> YES
    </td>
    </tr>
    <! ------------------------ action form-----------------------------------------------
    public ArrayList getPoDisplayVOList() {
         return poDisplayVOList;
    public void setPoDisplayVOList(ArrayList list) {
         poDisplayVOList = list;
    public Hashtable getPoDisplayVO(int i) {
         Object obj = poDisplayVOList.get(i);
         if (obj == null)
              obj = new Hashtable();
              poDisplayVOList.add(obj);
         return (Hashtable)poDisplayVOList.get(i);
    public void setPoDisplayVO(Hashtable programDisplayVO, int i) {
              poDisplayVOList.add(i, programDisplayVO);
         }

  • Can i write Html code inside JSP method???

    hi i am newbie to jsp and servlets. i am working on a project where i have to use same html code for two conditions in jsp. my question is can i write that html code inside any method in jsp?? and then can i call that method within that if and else scope. can anyone help me with this??

    I don't think that does what you think it does.
    <%!
    void renderStateSelect(String default) { %>Creates a method with that signature and an open brace...
    <select name="state"> puts:
    out.println("<select name=\"state\">");
    into the _jspService method
    <%!
    // logic to loop thru states
    %>Puts the loop logic after the brace opening up the method renderStateSelect
    </select>puts
    out.println("</select>");
    in the _jspService method
    <%!
    %>Closes the renderStateSelect method.
    So if I do this:
    <html>
    <body>
    <%!
    void renderStateSelect(String def) { %>
    <select name="state">
    <%!
    // logic to loop thru states
    %>
    </select>
    <%!
    %>
    Hello<br/>
    <% renderStateSelect("none"); %>
    Everybody
    </body>
    </html>The html output is:
    <html>
    <body>
    <select name="state">
    </select>
    Hello<br/>
    Everybody
    </body>
    </html> The 'renderStateSelect method does not render the state select. The _jspService method does, in place where the HTML is written in the JSP file.  As another look, the translated servlet looks like this:
    package org.apache.jsp;
    public final class IsThisOk_jsp extends org.apache.jasper.runtime.HttpJspBase
        implements org.apache.jasper.runtime.JspSourceDependent {
    void renderStateSelect(String def) {
    // logic to loop thru states
      public void _jspService(HttpServletRequest request, HttpServletResponse response)
            throws java.io.IOException, ServletException {
        try {
          out.write("<html>\r\n<body>\r\n");
          out.write("<select name=\"state\">\r\n");
          out.write("</select>\r\n");
          out.write(" \r\nHello<br/>\r\n");
    renderStateSelect("none");
          out.write("\r\nEverybody\r\n</body>\r\n</html>\r\n ");
    }See. Any plain HTML code you put outside of the <%! %> tags is converted to out.printlns inside the _jspService method (in place where they occured in the JSP, not where the method you want to do the rendering is called...)
    So unless I completely misunderstood your intent here, this apprach does not work.

  • How can I write the analogous code to the logic:iterate tag functionality

    Hai This is Rayalu .And I am very new to the Java World. I have a doubt?.How can I write the analogous code to the<logic:iterate> tag functionality using the JSP Tag Libraries . Pleae Send me some examples .

    Hi,
    SELECT objnr objid aufnr
            from afih
            into table t_afih.
    SELECT objnr
            from JEST
            into table t_JEST
            where stat = 'A0045'
               OR stat = 'A0046'
               AND inact 'X'.
    SELECT objnr
            from COBRB
            into table t_cobrb.
    SELECT arbpl werks objid objty
          from crhd
          INTO table it_crhd
          FOR ALL ENTRIES IN it_afih
          WHERE objty eq 'D'
          AND gewrk = it_afih-objid.
    SELECT aufnr objnr auart txjcd pspel gstrp werks aufnr
            FROM caufv
            INTO table t_caufv
            FOR ALL ENTRIES IN it_afih
            WHERE aufnr = it_afih-aufnr
              And pspel = ' '
              AND txjcd = ' '
             ANd objnr ne it_crhd-objnr
              AND auart in s_wtype
              AND werks in s_plant.
             AND objnr ne it_jest-objnr.
    dont use NE in the select statements, it may effect performance also. Instead use if statements inside
    loops.
    loop at t_caufv.
    read table it_chrd............
      if t_caufv-objnr ne it_chrd-objnr.
      read table it_jest..........
       if   if t_caufv-objnr ne it_jest-objnr.
        (proceed further).
       endif.
      endif.
    endloop.
    hope this helps.
    Reward if useful.
    Regards,
    Anu

  • Using Logic iterate to display a arraylist in STRUts

    I m having a form bean containg a string array......
    <form-bean
    name="myDynaForm"
    type="org.apache.struts.validator.DynaValidatorForm">
    <form-property name="names" type="java.lang.String[]" />
    </form- bean>
    and in my jsp , i m using .......
    <logic:iterate name="myDynaForm" property="names" id="names" >
    <tr>
    <td class="style3" align="left" width="30%" >
    <html:textarea property="names" cols="40" rows="2" size="40" indexed="true" readonly="true" />
    </td>
    </tr>
    Now this code is printing only the first element of String names.
    How can i print all the elemts of answer in my jsp

    How could you do the same thing but using only two cells?
    where the check box returns a specific value in the second.
    in this instance its for a staff registration sheet where a checkbox in (A) would return a set value in (B)
    i know this might sound simple to you guys in the know but i cant figure it out! I have been messing around trying things with the if function but still only shows me the red triangle (syntax error).
    A simple solution would be much appreciated.

  • Html select change to make JSP page forward keeping the exsting field value

    Hello, All,
    I am trying to make the change of a selection box in HTML form to reload the page and populate the second selection box based on the value in the first selection box. The content of the second selection box is from database....
    i used a javascript funtion and called it by the onChange(), the onChange redirect the page to the same page. However all my previous input is lost and the second selection box is not populated based on the first selection box.
    The question is how do I keep the current input and reload the page based on the change of a selection box?
    Please help..
    Thanks..
    Here is the code
    <script language=javascript type="text/javascript">
    function forward(){
    location.href="trdCapDetail.jsp";
    </script>
    <select name=vehicle onChange="forward()">
    <%for(int i = 0; i < Vehicle.getAll().size(); i++){
         Vehicle vehicle = (Vehicle)(Vehicle.getAll().elementAt(i));     
         out.write("<option value=" + vehicle.getKey()+" >" + vehicle.getCode() + "</option>");
    %>

    Ok two things.
    1 - you need to submit the value which was selected.
    2 - you need to repopulate the select box with it.
    1 - you need to submit the value which was selected.
    You do this by either appending the parameter to the url, or calling form.submit().
    <script language=javascript type="text/javascript">
    // either set parameter on url manually
    function forward(control){
    var param = control.value;
    location.href="trdCapDetail.jsp?vehicle=" + param;
    // or submit the form:
    function forward(control){
      control.form.submit();
    <% pageContext.setAttribute("vehicles", Vehicle.getAll() ) ; %>
    <form name="myForm" action="trdCapDetail.jsp"> 
      <select name="vehicle" onchange="forward(this)">
          <c:forEach var="vehicle" items="${vehicles}">
            <option value="<c:out value="${vehicle.key}"/>"> <c:out value="${vehicle.code}"/> </option>
          </c:forEach>
       </select>   
    </form>2: populating the control
    One way is to use javascript again:
    <c:if test="${not empty param.vehicle}">
      <script language="javascript">
        document.myForm.vehicle.value = "<c:out value="${param.vehicle}"/>";
      </script>
      </c:if>
    // or scriptlet code if you must
    <%
    String selectedVehicle = request.getParameter("vehicle");
    if (selectedVehicle != null){  %>
      <script language="javascript">
        document.myForm.vehicle.value = "<%= selectedVehicle%>";
      </script>
    <%
    %>The other way to keep the current input is to generate the string "selected" inside the option tag for the selected item. In your loop, check if the current id equals the submitted id, and print "selected" if it is.
    Hope this helps,
    evnafets

  • Using Strut Logic Iterate tag in JavaScript

    Has anyone tried this or experienced this problem.
    I have JSP pages with JavaScript imbedded. Not my web page but an out of the box portal we bought from a vendor. The JavaScript uses the Logic Iterate Strut tag but gives an error in Nitro:
    "feature is not resolved" on the lines where getLink() and getID() are called. I have put the code in other editors and it does not give me any error. Does any one have a clue to why this error occurs or is this something that NitroX can not handle?
    Thanks,
    Zim 8)
    Some of Code:
    function selectFolder(folderName,doExpandPath)
                        if (typeof(doExpandPath) == 'undefined')
                             doExpandPath = true;
                        var form = document.forms['TreeForm'];
                        // unselect old one
                        var cell = document.getElementById(selectedId);
                        if (null != cell)
                             cell.className = '';
                        // select new one
                        if ('/' == folderName.charAt(folderName.length-1))
                             folderName = folderName.substring(0,folderName.length-1);
                        var targetCellId = 'cellLabel./Documents'+folderName;
                        var isContentFolderBrowser = true;
                        try {
                             var sideBarSelected = top.frames['main'].window.sideBarSelected;
                             isContentFolderBrowser = '/getfolderitems.do' == sideBarSelected;
                             if (!isContentFolderBrowser) {
                             <logic:iterate id="feature" name="userinfobean" property="sideBarFeatures"
                                       type="com.actuate.activeportal.functionality.config.Feature">
                                       if (sideBarSelected == '<%= feature.getLink()%>' )
                                            targetCellId = 'cellLabel./<%= feature.getID()%>';
                                  </logic:iterate>
                        } catch (e) {
                        cell = document.getElementById(targetCellId);

    May I ask why have you done it?
    If it is related to printing of the list then it is of no use.But it IS of use. The objects compEmployees is in scope.
    It has the list we want to print out.
    With logic:iterate:
    <table>
         <tr>
           <th>Number</th>
           <th>Employee</th>
         </tr>
         <logic:iterate name="compEmployees" property="totalEmps" id="emp">
              <tr>
                <td>
                  <bean:write name="emp" property="empNo"/>
                </td>
                <td>
                  <bean:write name="emp" property="empName"/>
                </td>
              </tr>
         </logic:iterate>
    </table>or alternatively with JSTL and c:forEach
    <table>
         <tr>
           <th>Number</th>
           <th>Employee</th>
         </tr>
         <c:forEach items="${compEmployees.totalEmps}" var="emp">
              <tr>
                <td>
                  <c:out value="${emp.empNo}"/>
                </td>
                <td>
                  <c:out value="${emp.empName}"/>
                </td>
              </tr>
         </c:forEach>
    </table>Cheers,
    evnafets

  • C:forEach and logic:iterate tags repeating elements of a collection

    I have an issue that makes absolutely no sense to me. Basically I am using struts, and I am returning a form that contains a List of customers. I am simply trying to iterate that list into a simple table for each customer. The end result will have rows for each table, but I tried to simplify this example.
    The only filter is that I don't want to display customers that don't contain any data that I care to display. In my dataset, there is only one customer that has any data that I care about, and that has been verified in the database and in the backend action feeding the struts page.
    I first attempted this with the c:forEach JSTL tag. What I saw was that the customers were just getting repeated. Instead of showing one table for each customer, it was repeating the tables for each customer equal to the size of the Collection. For example, there were *5* customers in the List, only customer C should have been set into a table, but the table for customer C was being repeated *5* times. I went into the backend code, and made sure the object being sent back to struts contained the correct number of records.
    I then tried the same thing using the logic:iterate Struts EL tag. This did exactly the same thing. Instead of one table for customer C, I had 5 tables, all for customer C.
    Frustrated, I then went back to just writing a basic scriptlet in the JSP, to iterate over the object returned from the struts action. When I did this, everything came back as normal. Only customer C met my conditional statement, and only customer C had a table created in the generated HTML.
    Now I must be missing something with how the JSTL tags are handling the iteration, so I wanted to post the code to see if anyone had any idea what I am doing wrong here.
    The JSP page is found below. As you can see, the first part is done as a scriptlet, and the last part is done with JSTL tags. Unless I am mistaken, the 2 approaches should produce the same result. Please let me know if I am missing something here.
    <%@ include file="/common/customConfig.inc"%>
    <%@ page import="java.util.Iterator,
        com.pw.cemp.webapp.common.forms.CempDocumentsForm,
        com.pw.cemp.webapp.common.views.CustomerView"%>
    Write table with straight scriptlets...
    <br />
    <br />
    <%
        CempDocumentsForm cdForm =
            (CempDocumentsForm) session.getAttribute("cempDocsForm");
        Iterator itCustomers = cdForm.getCustomers().iterator();
        while (itCustomers.hasNext())
            int idx = 0;
            CustomerView customer = (CustomerView) itCustomers.next();
            if (customer.getCemps() != null && !customer.getCemps().isEmpty())
    %>
            <table>
                <% if (idx == 0) { %>
                    <caption>
                        Customer CEMP Listing
                    </caption>               
                <% } %>
                <tbody>
                    <tr>
                        <td class="level1">
                            <%=customer.getName() %> -
                            <%=customer.getSapCustomerId() %>
                        </td>
                    </tr>
                </tbody>
            </table>
    <%      
            idx ++;
    %>
    <br />
    <br />
    Now try using JSTL...
    <br />
    <br />
        <logic:iterate name="cempDocsForm" property="customers" id="customer" indexId="index">
        <!-- <c:forEach items="${cempDocsForm.customers}" var="customer" varStatus="status"> -->
            <c:if test="${not empty customer.cemps}">           
            <table>
                <c:if test="${index == 0}">
                    <caption>
                        Customer CEMP Listing
                    </caption>
                </c:if>
                <tbody>
                    <tr>
                        <td class="level1">
                            <c:out value="${customer.name}" /> -
                            <c:out value="${customer.sapCustomerId}" />
                        </td>
                    </tr>
                </tbody>
            </table>
            </c:if>
        <!-- </c:forEach> -->
        </logic:iterate>
        <br />
        <br />The code above produced the following HTML. As you can see, the scriptlet did exactly what I wanted, it produced 1 table for the only company that met the conditional statement. The JSTL section repeated the table for that one company, equal to the number of items in my List.
    Write table with straight scriptlets...
    <br />
    <br />
            <table>
                    <caption>
                        Customer CEMP Listing
                    </caption>                           
                <tbody>
                    <tr>
                        <td class="level1">
                            FMP Test Company -
                            5
                        </td>
                    </tr>
                </tbody>
            </table>
    <br />
    <br />
    Now try using JSTL...
    <br />
    <br />
            <table>           
                    <caption>
                        Customer CEMP Listing
                    </caption>           
                <tbody>
                    <tr>
                        <td class="level1">
                            FMP Test Company -
                            5
                        </td>
                    </tr>
                </tbody>       
            </table>
            <table>
                <tbody>
                    <tr>
                        <td class="level1">
                            FMP Test Company -
                            5
                        </td>
                    </tr>
                </tbody>
            </table>
            <table>           
                <tbody>
                    <tr>
                        <td class="level1">
                            FMP Test Company -
                            5
                        </td>
                    </tr>
                </tbody>
            </table>
            <table>           
                <tbody>
                    <tr>
                        <td class="level1">
                            FMP Test Company -
                            5
                        </td>
                    </tr>
                </tbody>
            </table>
            <table>       
                <tbody>
                    <tr>
                        <td class="level1">
                            FMP Test Company -
                            5
                        </td>
                    </tr>
                </tbody>
            </table>
        <br />
        <br />Thanks in advance...
    Edited by: cdbyrd on Feb 28, 2008 4:22 PM
    Edited by: cdbyrd on Feb 28, 2008 5:12 PM

    Okay, it looks like I kept moving things around until I stumbled upon something. One thing to note is that I am using Tiles in my struts 1.2.9 application. I don't know if that has anything to do with it, but this is what I found.
    If you notice in my code, with the iteration tags, I had one active and one commented version of the tag. I kept flipping them around, thinking it was some kind of syntax problem or it was specific to either the logic:iterate or c:forEach tag.
    Well, as it turns out, when you comment something the way I did, I think the custom tag processor doesn't ignore the commented sections. I had things commented like the following.
        <logic:iterate name="cempDocsForm" property="customers" id="customer" indexId="index">
        <!-- <c:forEach items="${cempDocsForm.customers}" var="customer" varStatus="status"> -->Now I have done this many times in the past, and I have never noticed any adverse behavior. I guess it was just the correct situation here to make the problem come to the surface. As soon as I removed any comments on the JSP, the page started working as expected. I can't explain why it happens, I just know it happened.
    Does anyone out there have a good explanation for this, so I can put a reason to why I lost so much hair today? Also, does anyone have the proper way to comment out JSTL tags to keep them from being parsed?
    Thanks...

Maybe you are looking for

  • How do I re-install Acrobat X Standard?

    My computer had to be re-installed with Windows. Now I'm in the process of putting all my programs back on. However, when I try to install Adobe Acrobat X Standard, I continually get the following message: "This application cannot be installed on thi

  • Getting Spotlight to Perform Conversions Yosemite

    When I first installed Yosemite I was able to do money and speed conversions with no difficulty at all. Now, even after disabling everything except conversion, it just won't work anymore. Anyone got an idea on this? I haven't been able to find anythi

  • Web Dynpro Problem

    Hi, I am new to the World of Web Dynpro in Java. I have developed a small Web Dynpro Application to access ABAP R/3 Backend. I have to check connection parameters for the used SLD, which are defined in the J2EE Visual Administrator.. Kindly tell me w

  • How to clean-install Mavericks to a fusion drive?

    Because I cannot find a complete answer here or anywhere else, I seek information about reinstalling Mavericks on a 1TB fusion drive on my late 2013 iMac. I see discussions about reinstalling, backing up data, Boot Camp issues, rebuilding a fusion dr

  • Shared content on different devices

    My apple ID is used for my Apple products and I've use it as well for my son's Ipod touch.  When I plug his ipod into our PC at home all my texts are showing up on his ipod.  How do I prohibit all my content from being downloaded onto his ipod?