package eg.web.action.jdbc; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import org.hdpagination.core.QueryCallback; import org.hdpagination.dataaccess.jdbc.AbstractJdbcQueryCallback; import org.hdpagination.web.action.AbstractCommandPaginationAction; import eg.vo.ProductVO; import eg.web.action.SearchCriteria; public class SearchProductAction extends AbstractCommandPaginationAction { public SearchProductAction() { super(SearchCriteria.class); } //convert String type to Integer type private Integer convertStr2Int(String str) { if (str == null || str.trim().equals("")) { return null; } else { return new Integer(str); } } //The following sample method is for searching based on JDBC SQL query public QueryCallback getQueryCallback(HttpServletRequest request, Object command) { SearchCriteria crit = (SearchCriteria)command; Integer priceFrom = convertStr2Int(crit.getPriceFrom()); Integer priceTo = convertStr2Int(crit.getPriceTo()); JdbcQueryCallbackWrapper callback = JdbcQueryCallbackWrapper .newInstance("select productId,prodNo,price,madeIn,description from product p", ProductVO.class) .addRestriction( Restrictions.eq("prodNo", crit.getProdNo()) ) .addRestriction( Restrictions.in("madeIn", crit.getMadeIn()) ) .addRestriction( Restrictions.contains("description", crit.getDescription()) ) .addRestriction( Restrictions.range("price", priceFrom, priceTo)) .setOrderBy("p.madeIn"); return callback; } }