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...

Similar Messages

  • Problem in Iterating using logic:iterate tag

    Hi ,
    I am using <logic:iterate> tag to iterate through a list of contents.
    When the List size is 1222, all the Contents in the List are displaying properly.
    When the size execdes 1223, the JSP is not displaying properly.
    I am not getting any exception also.
    I have added try and catch. Still it is not showing any exception.
    When the size is more than 1300, Some contents are not displaying in JSP.
    Can any one provide some inputs, so that I can crack my issue.
    The JSP code :
              <logic:iterate id="someXXXX" property="someXXX" name="someXXX" indexId="count" scope="request">
              <tr>
    <td><html:text name="someXXXX" property="someXXXX"
                             size="50" maxlength="50" onchange="setDirty()" indexed="true"/> </td>               
    <td height="15" align="center"><html:checkbox property="someXXXX" name="someXXXX" indexed="true" onclick="setCheckboxFlag(this)" />               
                   <td width="4"> </td>               
              </tr>
              <html:hidden property="someXXXX" name="someXXXX" indexed="true" />
              </logic:iterate>
    Thanks,
    RamaKrishna

    get the records and store them in a collection. Store the collection in session. take the first 10 records as a subset and pass it to the iterate tag. use the hidden field to keep the last record number in the jsp. So when you first see the jsp the first 10 records will be shown and when user clicks for next records send the hidden field value to the server and take next 10 records as subset and pass it to iterate tag. This is how you can do this. but if you have thousands of records storing them in the session is not recommended. you can pull them directly from the database.

  • 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 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

  • Help with JSP and logic:iterate

    I have some queries hope someone can help me.
    I have a jsp page call request.jsp:
    ====================================
    <%@ page import="java.util.*" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
    <html>
    <body>
       <%@ page import="RequestData" %>
       <jsp:useBean id="RD" class="RequestData" />
       <%Iterator data = (Iterator)request.getAttribute("Data");%>
       <logic:iterate id="element" name="RD" collection="<%=data%>">
          <jsp:getProperty name="RD" property="requestID" />
          <%=element%><br>
       </logic:iterate>
    </body>
    </html>
    And I have the RequestData.java file:
    ======================================
    private int requestID = 1234;
    public int getRequestID() { return requestID; }
    The jsp page display:
    ======================
    0 RequestData@590510
    0 RequestData@5b6d00
    0 RequestData@514f7f
    0 RequestData@3a5a9c
    0 RequestData@12d7ae
    0 RequestData@e1666
    Seems like the requestID is not returned. Does anybody know this?
    I have done the exact one using JSP and servlets, trying to learn using JSP and custom tags. The one with JSP and servlet looks like:
    ============================================
    <%@ page import="RequestData" %>
    <%Iterator data = (Iterator)request.getAttribute("Data");
    while (data.hasNext()) {
       RequestData RD = (RequestData)data.next();
       out.println(RD.getRequestID() );
    }%>

    Oh think I got it...
    but one thing I'm not sure is...
    If I use "<jsp:useBean id="RD" class="RequestData" />", do I still need "<%@ page import="RequestData" %>"?
    I tried without and it gives me error...

  • Pls help me writing logic:iterate tag in jsp page

    Hey guys , I am struck in retriving string p1,p2,p3 in the jsp page
    Pls have a look ata the code
    In DAO class:-
    StdprdDAO.java
    Public arrayList getPFP()
    ArrayList a = new ArrayList();
    While(rs.next())
         columnsVO colVO = new columnsVO;
         colVO.setProduct(rset.getString(1));//will store in String colProduct
         colVO.setFamily(rset.getString(2));//will store in String colFamily
    colVO.setPrice(rset.getString(3));//will store in String colPrice
    a.add(colVO);
    return a;
    In Action Class:-
    ArrayList final = null;
    StdprdDAO DAO = new stdprdDAO();
    final = DAO.getPFP();
    For(int i = 0; final !=null && i<final.size() ; i++)
         columnsVO VO = null;
         VO = (columnsVO)final.get(i);
         String p1 = (String) VO.getProduct();
         String p2 = (String) VO.getFamily();
         String p3 = (String) VO.getPrice();
         Request.setAttribute(“p1”,p1);
         Request.setAttribute(“p2”,p2);
         Request.setAttribute(“p3”,p3);
    In JSP PAGE:-
    id = “columnsVO”>
    <bean:write name = “columnsVO” property=”final” id=”p1”>
    but still I am doubting my above sentences in jsp page ,so pls correct them if possible.
    Instead of l;ogic:iterate can I use directly getattribute(“p1”)? <logic:iterate
    Still I m doubting I can not utilize columnsVO file in logic:iterate, I can utilize only formbean file.
    So pls help me with this.

    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

  • 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);
         }

  • JSP Compile Error when using dynamic ID in logic:iterate and bean:size

    Hello,
    I try to create a dynamic table with logic:iterate and bean:size tag. Dynamic means the attributes are written by scriptlet. Eg.:
    <logic:iterate id="customerBean" name="<%= formName %>"  property="<%= propertyName%>" length="<%= sRowSize%>">When I replace the id Attribute with propertyName I get compile errors, such as
    the compiler doesn't know the value at runtime:
    Unable to compile class for JSP An error occurred at line: 179 in the jsp file: /pages/formContent.jsp Generated servlet error: _newCustomer.java:1046: Missing term. java.lang.Object <%= propertyName %> = null; ^
    Whats wrong ?
    Thanks for your help

    Solution: don't use a runtime expression for the id attribute.
    The id attribute is used to declare
    - an attribute in scope
    - a scriptlet variable on the page
    These are only available for the duration of the <logic:iterate> tag
    The "id" is only used in your programming. You don't need to make it dynamic.

  • Urgent help on logic:iterate

    Dear all,
    I have a problem on logic:iterate and structs. Suppose I have EmployeeListAction to get the employees data as below :-
    employees = EmployeeData.getEmployees(getDataSource(request));
    request.setAttribute("employees", employees);
    In the EmployeeData file, sample codes are as below :-
    Employee employee = null;
    ArrayList employees = new ArrayList();
    employee = new Employee();
    employee.setName(firstname);
    employee.setEmail(Email);
    employee.setTimezone(Time_zone);
    employees.add(employee);
    In JSP, the way to call the employees data in the logic:iterate tag is as below :-
    <logic:iterate id="employee" name="employees" indexId="index" scope="request" property="com.convenxia.EmployeeListAction"
    <bean:message...>
    </logic:iterate>
    But it return errors which is as below :-
    javax.servlet.ServletException: Cannot find bean employees in scope session
    I have tried :-
    <logic:iterate id="employee" name="employees" indexId="index" scope="request"> or
    <logic:iterate id="employee" name="employees" indexId="index" scope="request" type="com.convenxia.Employee">
    But it still return errors which is as below :-
    javax.servlet.ServletException: Cannot find bean employees in scope session
    How to resolve it ?
    Please help me as soon as possible.
    Thank you.
    Cheers,
    yymae

    It look like you did not define or use bean.
    In program you do: request.setAttr || request.getSession().setAttr
    In jsp you then pick it up first:
    <jsp:useBean id="employees" class="...." scope=[request || session] (depends where you put it) />
    or for struts:
    <bean:define id="employees" scope="..[as above] toScope=[where you want to pick it up in iterate]"
    type="..." />
    then you should be able to use it safely in iterate tag.

  • How to use logic:interate tag in this case? thanks a lot.

    a javabean:
    a{
    int a;
    ArrayList bList (to store some strings);
    request.setAttribute("a",a);
    then how can I use <logic:iterate> tag to loop to use <bean:write> tag to write out the strings contained by bList?

    use getparams and get that attribute(arraylist)
    define a bean in jsp with property as this attribute for which u should have a getter method in context
    the following is to iterate through arralist of arraylist
    <logic:iterate id="accList" name="<%=subAppContextName%>" ="accountsHoldedList">
              <tr>
    <logic:iterate id="accList2" name="accList">
    <td> <bean:write name="accList2"/> </td>
    </logic:iterate>
    <td>
    <jfp:link styleClass="appNavNext" warn="false" bundle="<%=bundleName%>" key="GiveNotice" paramId="selectedAccount" paramName="accList2" href="javascript:submitMyForm();"></jfp:link>
    </td>
    </tr>
    </logic:iterate>
    accountsHoldedList is the one which is set in Context and i am iterating to display it.
    bye

  • Struts html:iterate tag

    Hello all,
    Does anyone know if the struts html:iterate tag can be used to iterate through an ArrayList? Can you populate a html:radio tag with such an iterator?
    If anyone has code examples of these, they would be MOST appreciated!
    Thank you!

    I have an ArrayList object that contains a collection of Listing objects.
    The Listing object has two methods getID, getName
    In the ActionForm there is a variable listingData of List type. How can I use the logic:iterate tag to traverse the ArrayList object and display the id and name of the ListingObjects?
    What has to be added in the logic:iterate tag below?
    <table>
    <logic:iterate id="listingForm" name="listingForm" property="listingData">
    <tr>
    <td>
    // Here I want to output the value of ids
    </td>
    <td>
    // Here I want to output the value of names
    </tr>
    </logic:iterate>
    </table>Do I need a nested logic:iterate tag?
    Should the ArrayList be populated with a J2SE class rather than a business object, i.e. the Listing class?

  • How to search and delete repeated elements in a vector

    Hi again,
    In a class of my application, it needs to check in a vector (A), if there are repeated elements, if it founds one, then it is replaced for a *. then the elements different from * are copied into a new vector(Aa). the code is the following:
    //here are defined the components Textfield, etc
    public void Bconj_Action(Object target)
              int idx = 0;
              int tokenCount;
              String var="";
              String var2="";
              String A[] = new String [50];
              String Aa[] = new String [50];
              String message = (TxtA.getText());
              StringTokenizer st = new StringTokenizer(message,",");
              tokenCount = st.countTokens();
              while (st.hasMoreTokens())
                   A[idx] = st.nextToken();
                   idx++;
              //Recorre vector A en busca de repetidos     
              for(int n=0;n<tokenCount-1;n++)
              for(int m=n+1;m<tokenCount;m++)
              if (A[m]==A[n] && A[n]!="*")
                   A[n]="*";
              //Recorre nuevamente el vector A buscando los diferente a * que seran copiados al vector Aa
              int o = 0;
              for (int n=1;n<tokenCount;n++)
              if(A[n]!="*")
              Aa[o]=A[n];
                   o++;
              for (int i=0;i<tokenCount; i++)
                        if (i==0){
                        var=Aa;}
                                  else{
                                  var = var + "," + Aa[i];}
                   TxtA.setText("");
                   TxtU.setText(var);
    when I run it, and I enter to the prog 1, it don't show me nothing, when I enter 1,1 it shows me 1,null and so on.
    do you have any ideas of what is happening.
    Thanks in advance.

    Two things I would point out to you:
    Its possible that the way you are comparing the Strings is causing a problem for you.
    if (A[m]==A[n] && A[n]!="*")
    A[n]="*";
    }A[m] and A[n] are two Strings so you should compare them using
    A[m].equals(A[n]).So the if statement should look like this:
    if (A[m].equals(A[n]) && !A[n].equals("*"))
    A[n]="*";
    }And second:
    When you copy the unique elements over to array Aa you may be copying less that tokenCount elements. You are actually copying o elements.
    The final for loop could be modified like this:
    for (int i=0;i<o; i++)
    if (i==0){
    var=Aa;}
    else{
    var = var + "," + Aa[i];}
    TxtA.setText("");
    TxtU.setText(var);
    } Thus it prints only the unique elements found rather than the whole array which may contain nulls.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Logic regarding EVENTS OnFilter and OnLeadSelect for table ui element

    provide me logic regarding EVENTS OnFilter and OnLeadSelect for table ui element for webdynpro abap application.

    OnLeadSelect - What kind of logic do you want?  There are many different things that you could do inthe OnLeadSelect
    onFilter- Generally you use IF_WD_TABLE_METHOD_HNDL~APPLY_FILTER  to perform the filter operation.
    In the onFilter itself you probably just have one line of code:
    wd_this->table_method_hndl->apply_filter( ).
    In your WDDOMODIFYVIEW you probably have this code to capture the table_method_hndl object:
    if first_time = abap_true.
      * Get reference of the table view element
      l_table ?= view->get_element( 'TABLE' ).
    * Get reference to the Filter & Sorting API
      wd_this->table_method_hndl ?= l_table->_method_handler.
    endif.

  • Help with XMLSEQUENCE and repeating elements

    I need help with the following XML extraction (note this is on Oracle9i). I have the following XML structure. There are multiple <Reading> elements
    <MeterReadings>
    <MeterReading>
    <Meter>
    <id>0004128190</id>
    <idType>METER_X_UNIVERSAL_ID</idType>
    </Meter>
    <Premise>
    <id>PREM4128190</id>
    <idType>X_CLIENT_PRMSE_ID</idType>
    </Premise>
    <Reading>
    <value>11111</value>
    <readingTypeId>CKWH</readingTypeId>
    </Reading>
    <Reading>
    <value>22222</value>
    <readingTypeId>KWHP</readingTypeId>
    </Reading>
    </MeterReading>
    </MeterReadings>
    I want to return one row for each <reading> element, including all its sub-elements - <value> and <readingTypeId>
    So, for the above data set, I would like to get back something like this. The parent elements can be repeated.
    <meter/id>,<Premise/id>,<Reading/value>,<Reading/readingTypeId>
    0004128190,PREM4128190,11111,CKWH
    0004128190,PREM4128190,22222,KWHP
    I have tried to use the XMLSequence function like this:
    select extractvalue(i.xml_message,'MeterReadings/MeterReading/Meter/id'),
    extractvalue(value(p),'value'), extractvalue(value(p),'readingTypeId')
    from myTable i,
    table(XMLSequence(
    extract(i._xml_message, '//Reading/*' ))) p
    But then I get results like this, where each sub-element results in a new row:
    0004128190     11111     null
    0004128190     null     CKWH
    0004128190     22222     null
    0004128190     null     KWHP
    What would be the proper XQuery?
    Thanks!

    This may help:
    http://www.dreamweaverresources.com/tutorials/pagebackgrounds/examplevert.htm
    Nadia
    Adobe® Community Expert : Dreamweaver
    CSS Templates |Tutorials |SEO Articles
    http://www.DreamweaverResources.com
    http://www.csstemplates.com.au
    http://www.perrelink.com.au
    CSS Tutorials for Dreamweaver
    http://www.adobe.com/devnet/dreamweaver/css.html
    "teamkombat" <[email protected]> wrote in
    message
    news:ept196$d1g$[email protected]..
    > Hi I am trying to create a very simple effect where my
    page casts a
    > shadow. If
    > you take a look at
    http://www.timberland.com/home/index.jsp
    the left and
    > right
    > side of the page has a very light shadow. I would like
    to use a similar
    > effect. What I was thinking was to create 2 small .gifs
    with the shadow
    > effect
    > (1 for the left side and 1 for the right side) maybe
    10px long. Then
    > create 1
    > table with 3 columns: The middle collumn will be the
    main column for the
    > content and 2 thin/small columns on the left and right
    to attach the
    > shadow
    > .gifs.
    >
    > I was wondering how do I repeat this shadow .gif image
    for the length of
    > the
    > main column?
    >
    > Also if there is a better solution to the above problem
    please let me
    > know. I
    > have read about faux columns and using CSS for repeating
    images, but don't
    > really grasp the ideas yet. Thanks everyone for their
    time and help.
    >
    >

  • Loop through elements within nested:iterate tag using javascript

    Hello,
    I would like to loop through the adjustedLineItems list and set the checkbox values to true on click of a select all button.
    I am getting the error document.all['adjustedLineItems.selected'] is null or not an object
    however it works if I manually substitute values for i within the function
    document.all['adjustedLineItems[0].selected'].checked=true;
    document.all['adjustedLineItems[1].selected'].checked=true;
    document.all['adjustedLineItems[2].selected'].checked=true;
    Could someone please help me do this via a for loop?
    Thanks
    <nested:iterate name="invoiceForm" property="adjustedLineItems" id="adjli" type="com.bt.lex.common.lineItem.beans.LineItemDetailBean" indexId="idxadjli">
              <tr>
                   <td class="dataLeft"><nested:checkbox property="selected"/></td>
                   <td class="dataLeft"><nested:write property="liNumber"/></td>
              </tr>
    </nested:iterate>
    <script type="text/javascript">
    function onclick_all(ctl) {
         var checkFlag = "false";
         var count = document.all.numOfAdjustedLIs.value;
         var i = 0;
         //alert(count);
         if(ctl.checked)
              if(checkFlag=="false")
                   for (i = 0; i <count; i++)
                        document.all['adjustedLineItems[i].selected'].checked=true;
                   checkFlag = "true";
    </script>

    Its got nothing to do with nested iterate tags :). However,
    document.all['adjustedLineItems.selected'].checked=true;
    The variable 'i' is not getting evaluated as is evident from the error message - document.all['adjustedLineItems.selected'].
    The appearance of 'i' in the error message tells it all, right ? :)
    So
    document.all['adjustedLineItems[' + i + '].selected'].checked=true;should do the trick.
    ram.

Maybe you are looking for