count = list.size();
}
catch (NoSuchMethodException x)
{
throw new ModelException(x);
}
catch (IllegalAccessException x)
{
throw new ModelException(x);
}
catch (InvocationTargetException x)
{
throw new ModelException(x.getTargetException());
}
}
else if (query.getCountName() != null)
{
count = (int) standardDao.countByNamedQuery(query.getCountName(), queryParams);
}
else if (query.getName() != null)
{
count = (int) standardDao.countByNamedFindQuery(query.getName(), queryParams);
}
else
{
if (query.getCountQuery() != null)
{
count = (int) standardDao.countByQuery(query.getCountQuery(), queryParams);
}
else
{
count = (int) standardDao.countByFindQuery(query.getQuery(), queryParams);
}
}
int page = Math.max(listing.getPage(), 1);
int maxPage = (Math.max(0, count - 1) / context.getResultsPerPage()) + 1;
page = Math.min(page, maxPage);
context.setPage(page);
context.setFirstResult((page - 1) * context.getResultsPerPage());
Output outList = createHeaderElements(request, response, listing, context);
outList.setAttribute("pageCount", new Integer(maxPage));
outList.setAttribute("page", String.valueOf(page));
int firstResult = (page - 1) * context.getResultsPerPage();
int maxResults = context.getResultsPerPage();
java.util.List res = null;
if (query.getDaoName() != null)
{
try
{
res = (java.util.List) MethodUtils.invokeExactMethod(SpringTools.getBean(query.getDaoName()), query
.getDaoMethodName(), queryParams);
}
catch (NoSuchMethodException x)
{
throw new ModelException(x);
}
catch (IllegalAccessException x)
{
throw new ModelException(x);
}
catch (InvocationTargetException x)
{
throw new ModelException(x.getTargetException());
}
}
else if (query.getName() != null)
{
res = standardDao.findByNamedQuery(query.getName(), queryParams, firstResult, maxResults, listing
.getSortColumnName(), listing.getSortOrder());
}
else
{
res = standardDao.findByQuery(query.getQuery(), queryParams, firstResult, maxResults, listing
.getSortColumnName(), listing.getSortOrder());
}
int rowNum = 1;
for (Object row : res)
{
context.setIt(row);
Output outItem = response.createOutput("item");
outList.add(outItem);
String idExpression = listing.getIdColumn();
if (idExpression == null)
{
idExpression = "#{it.id}";
}
String id = ExpressionLanguageContext.evalExpressionLanguageValue(context, request, idExpression)
.toString();
try
{
outItem.setAttribute("id", id);
}
catch (Exception x)
{
throw new ModelException("Unable to retrieve id property in listing '" + listing.getId() + "' ("
+ x.getMessage() + ")");
}
outItem.setAttribute("odd", new Boolean(rowNum % 2 == 1));
outItem.setAttribute("even", new Boolean(rowNum % 2 == 0));