Here's an example how to solve this problem. I used Karapan Sapi to generate my first
application from reverse engineering my database and it generated all the code and jsp
pages. I found the way that it does this to be unreliable however. But the method
they used to generate a paging list to be effective.
This will display and page through a list of log entries in my database
private ActionForward performList(ActionMapping mapping, ActionForm actionForm,
HttpServletRequest request, HttpServletResponse response) {
try {
DataSource ds = (DataSource)
servlet.getServletContext().getAttribute("DATASOURCE");
LogDAO logDAO = new LogDAO(ds);
List logs = logDAO.list();
int offset;
int length = PAGE_LENGTH; /// how many entries per page?
String pageOffset = request.getParameter("pager.offset"); // we keep track of
which page we're on
if (pageOffset == null || pageOffset.equals("")) {
offset = 0;
} else {
offset = Integer.parseInt(pageOffset);
}
String url = request.getContextPath()+"/do"+mapping.getPath();
String pagerHeader = Pager.generate(offset, logs.size(), length, url);
// setup some request attributes so our jsp page can see them
request.setAttribute("offset", new Integer(offset));
request.setAttribute("pagerHeader", pagerHeader);
request.setAttribute("length", new Integer(length));
request.setAttribute("LOGS", logs);
} catch (Exception e) {
generalError(request, e);
return mapping.findForward("failure");
}
return mapping.findForward("success");
}
now in our jsp page we do this:
We are basically just fetching our list of Log objects from the request. remember
above we called our setAttribute field "LOGS"
Struts uses the offset value to skp to a specific page. See the attached Pager.java
for more information. At the right of our list we display edit, view, delete links to
the item. The links are hyperlinked by the primary key of the log record in the db,
not the index property of the iterate tag. Although you could do that too (i actually
use the second method in my "Show Cart" page to remove/update items in the session
shopping cart rather than a db)
<table class="bodytable" width="100%" cellspacing="1" border="0">
<bean:write name="pagerHeader" scope="request" filter="false"/>
<logic:iterate id="log" offset="offset" length="length" name="LOGS"
type="com.myapp.model.Log">
<tr>
<td align="left" valign="top" width="125" class="tableattributecolor"><span
class="tablecelllabelbold">
<bean:write name="log" property="id" scope="page"/>
</span></td>
<td align="left" valign="top" width="125" class="tableattributecolor"><span
class="tablecelllabelbold">
<bean:write name="log" property="logtext" scope="page"/>
</span></td>
<td align="left" valign="top" width="125" class="tableattributecolor"><span
class="tablecelllabelbold">
<bean:write name="log" property="datestamp" scope="page"/>
</span></td>
<td align="left" valign="top" width="125" class="tableattributecolor"><span
class="tablecelllabelbold">
<html:link href="edit" paramId="id" paramName="log" paramProperty="id"><bean:message
key="label.edit"/></html:link>
<html:link href="view" paramId="id" paramName="log" paramProperty="id"><bean:message
key="label.view"/></html:link>
<html:link href="remove" paramId="id" paramName="log" paramProperty="id"><bean:message
key="label.remove"/></html:link>
</span></td>
</tr>
</logic:iterate>
</table>
Regards,
Mark Williamson
*********** REPLY SEPARATOR ***********
On 03/14/2003 at 4:22 PM Karl wrote:
>I had a look in the archives for the past month but didn't see anything to do
>with this =(
>
>If I use setAttribute, how do I get a handle on it from the jsp page?
>
>I also want the results to be displayed as a paginated list of links, which
>means that the search results page needs an ActionForm of its own. As well,
>the individual links will go to an edit page, which will also need an
>ActionForm of its own. This problem looks like it is going to propagate
>every time I need to use data submitted from one page as a lookup for
>presenting data on another (which also may have an input form present).
>
>The FAQ suggests putting every piece of information I'd ever need into one
>giant form object but this seems like an incredibly naive solution to a
>paradigm issue...
>
>
>2003 3$B7n(B 14 $B6bMKF|(B 12:43$B!"(BMark $B$5$s$O=q$-$^$7$?(B:
>> I believe this question was asked and answered just about a week or two
>> ago....suggest you look in the archives, there are several answers
>>
>> all you really need to do right before your forward is
>>
>> request.setAttribute("searchresults",myCollection);
>>
>> and in your jsp just use iterate tag to walk through the results.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]