?
Solved

Problem in displaying result using <logic:iterate>

Posted on 2005-02-25
7
Medium Priority
?
331 Views
Last Modified: 2010-04-01
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
0
Comment
Question by:sushil_p
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 8

Expert Comment

by:kiranhk
ID: 13404319
>>> 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
 

Author Comment

by:sushil_p
ID: 13440382
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
 
LVL 8

Expert Comment

by:kiranhk
ID: 13440556
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
 

Author Comment

by:sushil_p
ID: 13446777
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
 
LVL 8

Accepted Solution

by:
kiranhk earned 500 total points
ID: 13450672
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question