Problem in displaying result using <logic:iterate>

Hi ,
 The problem is with using logic:iterate in jsp page :
  I'm getting all values from database in action class , which i stored
them  in Action Form Bean  but when trying to display the same using logic
iterate it shows nothing, nor even gives any error ....

The size of  arraylist getSrchList() in Action Form Bean gives zero .... i
think that it looses reference to SearchResultValueObject when it comes to
jsp page ... The same SearchResultValueObject  works fine upto Action class
, gives all values but lost in jsp page ....

Below is logic of logic:iterate that i'm using ...... in the jsp file

<logic:present name="SearchReqFormBean" property="srchList">
 <TABLE cellSpacing=0 cellPadding=0 width="640" border="0">
     <TBODY>
      <TR>
        <TD class="tableContents">Request Id</TD> // Display in jsp page.
        <TD class="tableContents">Request Date</TD>
        <TD class="tableContents">Required Date</TD>
        <TD class="tableContents">Requestor SSO</TD>
        <TD class="tableContents">Person Receiving</TD>
      </TR>
<!--the above headers are sen when jsp page is displayed however the results are not seen from logic:iterate-->

      <logic:iterate id="search" name="SearchReqFormBean"
type="StrutsWeb.valueobject.SearchResultValueObject"  property="srchList" >

      <TR>      // shows nothing ..
        <TD class="tableContents"><bean:write name="search"
property="strRequestId" /></TD>
        <TD class="tableContents"></TD>
        <TD class="tableContents"></TD>
        <TD class="tableContents"></TD>
        <TD class="tableContents"></TD>
      </TR>
       </logic:iterate>
    </TBODY>
 </TABLE>
 </logic:present>
 <%
      }
%>

=================================================
Acttaching the Action file...

=================================================
The bean  ...srchFormBean = srchHandler.getSearchReqDetails(srchFormBean).. has values in it we have also checked it by priniting it


public class SearchReqAction extends Action {
      
      public ActionForward execute(ActionMapping mappings ,
                                                 ActionForm form ,
                                                 HttpServletRequest request ,
                                                 HttpServletResponse response) throws IOException , ServletException , RemoteException
      {
            String strFlag = null ;
            
            try
            {
            
                  SearchReqFormBean srchFormBean = (SearchReqFormBean)form;
                  SearchReqHandler srchHandler = new SearchReqHandler();
                  strFlag = request.getParameter("hidFlag");

                  if (strFlag.equals("true")){                  
                        srchFormBean = srchHandler.getSearchReqDetails(srchFormBean);                                          
                        request.setAttribute("Flag",strFlag);
                        return mappings.findForward("success");
                  }else{
                        return mappings.findForward("success");
                  }
                                          
            }
            catch(RemoteException rex)
            {
                  rex.printStackTrace();
                  System.out.println("*========Error in Action Remote====" + rex.getMessage());
                  return (mappings.findForward("failure"));
            }
            catch(Exception ex)
            {
                  ex.printStackTrace();
                  System.out.println("Error encountered = " + ex.getMessage());
                  return (mappings.findForward("failure"));
            }            
      }
}


=================================================
SearchFormBean

=================================================

package StrutsWeb.beans;

import org.apache.struts.action.ActionForm;
import java.io.Serializable;
import java.util.ArrayList;

import  StrutsWeb.valueobject.SearchResultValueObject;

public class SearchReqFormBean extends ActionForm implements Serializable{

      
      private Collection srchList;
      
      public SearchReqFormBean(){
                  super();
                  srchList = new ArrayList();
      }

      public void setSearch(SearchResultValueObject srchResValObj)
      {            
            getSrchList().add(srchResValObj);
      }
      public SearchResultValueObject getSearch(int intIndex)
      {
            return (SearchResultValueObject)getSrchList().get(intIndex);
      }

      public ArrayList getSrchList()
      {            
            return (ArrayList)this.srchList;
      }
      public void setSrchList(Collection srchList)
      {
            this.srchList = srchList;
      }      
}

==================================

SearchResultValueObject

==================================

package StrutsWeb.valueobject;

import org.apache.struts.action.ActionForm;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Collection;

public class SearchResultValueObject implements Serializable
{
      String strRequestId ;
      String strReqstDate ;
      String strReqdDate ;      
      String strReqstorSSO ;
      String strPersonRec ;


//Not enterd the full code but added the important method....

public SearchResultValueObject(String strRequestId , String strReqdDate , String strReqstDate , String strReqstorSSO , String strPersonRec ){
            this.strRequestId = strRequestId ;
            this.strReqstDate = strReqstDate ;
            this.strReqdDate = strReqdDate ;      
            this.strReqstorSSO = strReqstorSSO ;
            this.strPersonRec = strPersonRec ;

}


}

your help would be highly appreciated...

thanks in advance
sushil_pAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kiranhkCommented:
>>> I'm getting all values from database in action class , which i stored them  in Action Form Bean
can you post the code where u r doing this...
r u creating the ActionForm and then setting it in either request/session and then forwarding it to your display jsp....
0
sushil_pAuthor Commented:
We are getting the data in the Action class through the action form ..however the same bean gets lost when we display the result in JSP using logic:iterate...

When we set the particular property say for eg.. srchFormBean.getSrchList()); in request and iterate based on the property we get the result

Action Class
==================================
request.setAttribute("srchList",srchFormBean.getSrchList());
return mappings.findForward("success");

logic:iterate code from jsp using request.attribute
=================
<logic:iterate id="search" name="SearchReqFormBean" indexId="ctr" type="StrutsWeb.valueobject.SearchResultValueObject" collection="<%=srchList%>">
      <%System.out.println("ctr=========="+ctr);%>
      <tr <% if((ctr.intValue())%2!=0){%> bgcolor="#000000" <%}%>>
            <TD class="tableContents"><bean:write name="search"  property="requestId" /></TD>
            <TD class="tableContents"><bean:write name="search"  property="strReqstDate" /></TD>
            <TD class="tableContents"><bean:write name="search"  property="strReqdDate" /></TD>
            <TD class="tableContents"><bean:write name="search"  property="strReqstorSSO" /></TD>
            <TD class="tableContents"><bean:write name="search"  property="strPersonRec" /></TD>  
      </TR>
      </logic:iterate>

====================


Can u please tell us why the Actionformbean gets lost when we try to access it in JSP??

thanks in advance
0
kiranhkCommented:
after you set the the list in the property of the form are you setting the form into either request/session scope....
can you post your action class execute method full code...
0
sushil_pAuthor Commented:
public class SearchReqAction extends Action {
      
      public ActionForward execute(      ActionMapping mappings ,
                        ActionForm form ,
                        HttpServletRequest request ,
                        HttpServletResponse response) throws IOException , ServletException , RemoteException
      {
            String strFlag = null ;
            ArrayList arrSearchReq = null;
            int intCount = 0;
      
            try
            {
                  
                  SearchReqFormBean srchFormBean = (SearchReqFormBean)form;
                  SearchReqHandler srchHandler = new SearchReqHandler();
                  strFlag = request.getParameter("hidFlag");
                  if (strFlag.equals("true"))
                  {
                        srchFormBean  = srchHandler.getSearchReqDetails(srchFormBean);                                          
                        request.setAttribute("Flag",strFlag);
                  }                  
                  
                  System.out.println("ACTION====>Result from database" + srchFormBean.getSrchList().size());
                  
            
                  request.setAttribute("srchList",srchFormBean.getSrchList());
                  return mappings.findForward("success");
            }
            catch(RemoteException rex)
            {
                  rex.printStackTrace();
                  return (mappings.findForward("failure"));
            }
            catch(Exception ex)
            {
                  ex.printStackTrace();
                  return (mappings.findForward("failure"));
            }            
      }
}
0
kiranhkCommented:
no.. after u get the data from the DB you need to set your form bean either in request/session scope whichever u would have declared in your struts-config.xml  if you have not given any scope to the form in the action mapping then you can set it in session with the name as you would have given in the form-bean property in struts-config.xml

   System.out.println("ACTION====>Result from database" + srchFormBean.getSrchList().size());
session.setAttribute(your form bean name, srchFormBean);


after this your page will be able to display the data with you having to set the srchList attribute in the request....
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.