Created
May 11, 2009 18:15
-
-
Save akahn786/110081 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* Excerpted from "Stripes: and Java Web Development is Fun Again", | |
* published by The Pragmatic Bookshelf. | |
* Copyrights apply to this code. It may not be used to create training material, | |
* courses, books, articles, and the like. Contact us if you are in doubt. | |
* We make no guarantees that this code is fit for any purpose. | |
* Visit http://www.pragmaticprogrammer.com/titles/fdstr for more book information. | |
***/ | |
/* item_list.js */ | |
function filterItems(field, url) { | |
// from aporter: | |
//$('$item_table').load(url, { 'filter': $(field).val(), '_eventName': 'findByName' }); | |
$.get(url, | |
{ 'filter': $(field).val(), | |
'_eventName': 'findByName' | |
}, | |
function(data) { | |
$('#item_table').html(data); | |
} | |
); | |
} | |
function ajaxLink(link, update) { | |
$.get(link, function(data) { | |
$(update).html(data); | |
$(update).show(); | |
}); | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%-- Trying to do what Matt Raible does in his example here: http://raibledesigns.com/rd/entry/the_future_of_the_displaytag --%> | |
<%@ include file="/WEB-INF/jsp/common/taglibs.jsp" %> | |
<s:layout-render name="/WEB-INF/jsp/common/layout.jsp" title="Found Items"> | |
<s:layout-component name="head"> | |
<script type="text/javascript" src="${contextPath}/script/jquery-1.3.2.min.js"></script> | |
<script type="text/javascript" src="${contextPath}/script/item_list.js"></script> | |
<script type="text/javascript" src="${contextPath}/script/aa.js"></script> | |
<script type="text/javascript"> | |
ajaxAnywhere.getZonesToReaload = function() { return "itemList" } | |
ajaxAnywhere.onAfterResponseProcessing = function() { replaceLinks() } | |
function replaceLinks() { | |
// replace all the links in <thead> with onclick's that call AjaxAnywhere | |
var sortLinks = $('userList').getElementsByTagName('thead')[0] | |
.getElementsByTagName('a'); | |
ajaxifyLinks(sortLinks); | |
if (document.getElementsByClassName('pagelinks').length > 0) { | |
var pagelinks = document.getElementsByClassName('pagelinks')[0] | |
.getElementsByTagName('a'); | |
ajaxifyLinks(pagelinks); | |
} | |
} | |
function ajaxifyLinks(links) { | |
for (i=0; i < links.length; i++) { | |
links[i].onclick = function() { | |
ajaxAnywhere.getAJAX(this.href); | |
return false; | |
} | |
} | |
} | |
replaceLinks(); | |
</script> | |
</s:layout-component> | |
<s:layout-component name="body"> | |
<div>Found Items</div> | |
<%-- The filter field --%> | |
<s:url var="url" beanclass="org.stripesbook.quickstart.action.ItemListActionBean"/> | |
Item Filter: <input type="text" onkeyup="filterItems(this, '${url}');"/><br/> | |
<%-- This tag is the one called by the JS filter to redraw the table --%> | |
<div id="item_table"> | |
<aa:zone name="itemList"> | |
<%-- I generally include the table below in the include, but commented out and pasted below for now --%> | |
<%--@include file="/WEB-INF/jsp/parts/item_table.jsp" --%> | |
<d:table name="${actionBean.items}" id="item" requestURI="" defaultsort="1" | |
pagesize="30" sort="list" defaultorder="descending"> | |
<d:column title="Date Found" sortProperty="dateFound" sortable="true" > | |
<fmt:formatDate type="date" dateStyle="full" value="${item.dateFound}" /> | |
</d:column> | |
<d:column title="Name" sortable="true"> | |
<s:link beanclass="org.stripesbook.quickstart.action.ItemDetailActionBean"> | |
<s:param name="item" value="${item.id}"/> | |
${item.name} | |
</s:link> | |
</d:column> | |
<d:column title="City" property="cityId" sortable="true" /> | |
<d:column title="State" property="stateId" sortable="true" /> | |
<d:column title="Picture" sortable="true"> | |
<c:if test="${item.imageExists}"> | |
x | |
</c:if> | |
</d:column> | |
</d:table> | |
</div> | |
</aa:zone> | |
</s:layout-component> | |
</s:layout-render> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.stripesbook.quickstart.action; | |
// my imports | |
// java imports | |
import java.util.List; | |
// 3rd party imports | |
import net.sourceforge.stripes.action.DefaultHandler; | |
import net.sourceforge.stripes.action.ForwardResolution; | |
import net.sourceforge.stripes.action.Resolution; | |
import org.apache.log4j.Logger; | |
import org.hibernate.criterion.Restrictions; | |
import org.hibernate.Session; | |
import org.stripesbook.quickstart.model.Item; | |
import org.stripesstuff.stripersist.Stripersist; | |
public class ItemListActionBean extends ItemBaseActionBean { | |
private final static String LIST = "/WEB-INF/jsp/item_list.jsp"; | |
private final static String ITEM_LIST = "/WEB-INF/jsp/parts/item_table.jsp"; | |
private static Logger logger = Logger.getLogger(ItemListActionBean.class); | |
private List<Item> items; | |
public String filter; | |
@DefaultHandler | |
public Resolution list() { | |
logger.debug("*** in list()"); | |
Session sess = org.stripesbook.quickstart.util.DAO.getSession(); | |
items = sess.createCriteria(Item.class).list(); | |
logger.debug("*** items.size: " + items.size()); | |
return new ForwardResolution(LIST); | |
} | |
public Resolution findByName() { | |
logger.debug("*** in findByName()"); | |
Session sess = org.stripesbook.quickstart.util.DAO.getSession(); | |
if (filter != null && filter.length() > 0) { | |
items = sess.createCriteria(Item.class) | |
.add(Restrictions.ilike("name", filter+"%")) | |
.list(); | |
} else { | |
this.list(); | |
} | |
logger.debug("*** after filter"); | |
return new ForwardResolution(ITEM_LIST); | |
} | |
public List<Item> getItems() { | |
return items; | |
} | |
public void setItems(List<Item> items) { | |
this.items = items; | |
} | |
public String getFilter() { | |
return filter; | |
} | |
public void setFilter(String filter) { | |
this.filter = filter; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%-- Stripes TLD --%> | |
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %> | |
<%@ taglib prefix="sdyn" uri="http://stripes.sourceforge.net/stripes-dynattr.tld" %> | |
<%-- JSTL TLDs --%> | |
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> | |
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> | |
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> | |
<%-- Display Tag - displaytag.sourceforge.net --%> | |
<%@ taglib prefix="d" uri="http://displaytag.sf.net" %> | |
<%-- AjaxAnywhere - ajaxanywhere.sourceforge.net --%> | |
<%@ taglib prefix="aa" uri="http://ajaxanywhere.sourceforge.net/" %> | |
<%-- This is so that you can conveniently refer to the context path with ${contextPath} --%> | |
<c:set var="contextPath" value="${pageContext.request.contextPath}"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment