Friends iam using Struts1.2 and iam new to this framework. Iam stuck at one place. I have fetched the records from oracle database and set it in the arraylist of type(DTO object) which is defined in bean class. Now iam facing problem in iterating through the arraylist in the jsp page. It seems my jsp page cannot read the bean property set in the logic:iterate, and the logic iterate is getting skipped completely while execution.

Here is the code:

My DAO class for retrieving data and setting it in the DTO type arraylist

public List<CIFCustomerDTO> getCIFData(String custName, int minRow, int maxRow){
        ResultSet rs=null;
        Statement stmt=null;
        Connection con=null;
        String qry="";
        **List<CIFCustomerDTO> cifCustDTOList = new ArrayList<CIFCustomerDTO>();**
        try{

            Class.forName("oracle.jdbc.driver.OracleDriver");
            con = DriverManager.getConnection("jdbc:oracle:thin:@172.16.100.85:1521:xxx","xyz","xyz");
            stmt = con.createStatement();
            qry = "SELECT * FROM (SELECT ROWNUM R, " +
                    "ANCILLARY_FLAG"
                    "ADMN_ADDRESS_1, " +
                    "......"
                    "FROM CIF_CUSTOMER WHERE CUSTOMER_NAME LIKE " + "'%" + custName + "%') WHERE R > "+minRow+" AND R < " + maxRow + "";
            rs = stmt.executeQuery(qry);
            CIFCustomerDTO cifCustDTO=new CIFCustomerDTO();


            while(rs.next()){

           //Setting only a few attributes instead of all

                cifCustDTO.setAcillaryFlag(rs.getString("ANCILLARY_FLAG"));
                cifCustDTO.setAdmnAddress1(rs.getString("ADMN_ADDRESS_1"));
                //Setting some more collumns in the DTO object.

                **cifCustDTOList.add(cifCustDTO);**
            }catch(Exception e){e.print stack trace}
           }

My Bean class where the getter setter of the Arraylist of DTO type is created.

public class InwardBean{
    List<CIFCustomerDTO> resultList = new ArrayList<CIFCustomerDTO>();

    public List<CIFCustomerDTO> getResultList() {
            return resultList;
        }

    public void setResultList(List<CIFCustomerDTO> resultList) {
            this.resultList = resultList;
        }
}

My Action class where iam calling dao function and setting the values in the arraylist object of DTO present in the bean.

public class PagingCIFAction extends Action {

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){

        CIFCustomerDAO cifCustDAO = new CIFCustomerDAO(); 
        List<CIFCustomerDTO> cifCustDTOList = null;
        InwardBean bean = new InwardBean();
        cifCustDTOList=cifCustDAO.getCIFData("JAMMU",0 ,6);
        bean.setResultList(cifCustDTOList);

        return mapping.findForward("success");      
    }
}

My Jsp Page where iam displaying the value of arraylist by iterating using logic:iterate

<table border="1" align="center" class="tbl-vista" bordercolor="#b49984" style="border-collapse:collapse">
        <tr>
        **<logic:iterate id="resultList" name="inwardBean" property="resultList">

                <td>
                    <bean:write name="resultList" property="cifId"/>
                </td>
                <td>
                    <bean:write name="resultList" property="customerName"/>
                </td>

        </logic:iterate>**
        </tr>
    </table>

The logic iterate part is getting skipped completely.

Member Avatar for LastMitch

The logic iterate part is getting skipped completely.

There's nothing wrong here:

<logic:iterate property="resultList" name="inwardBean" id="resultList" >  
<tr>  
<td><bean:write name="resultList" property="cifId" /></td>  
<td><bean:write name="resultList" property="customerName" /></td>   
</tr>  
</logic:iterate>  

Now iam facing problem in iterating through the arraylist in the jsp page. It seems my jsp page cannot read the bean property set in the logic:iterate, and the logic iterate is getting skipped completely while execution.

You need this:

http://javarevisited.blogspot.com/2012/10/jstl-foreach-tag-example-in-jsp-looping.html

hai subratbehera,

i think you need to store inwardBean in any of the scope(like request or session) in PagingCIFAction
before forwarding the request to display the values of it.

so that the values will be available for the page where you want to display

try to place this line at line 10 in PagingCIFAction

request.setAttribute("inwardBean",bean); // like this

check it once and let me know

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.