HttpServletRequest request,
HttpServletResponse response)
throws Throwable {
EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
TaxListingActionForm form = (TaxListingActionForm) actionForm;
AdminBean adminBean = getAdminBean(request);
Site site = adminBean.getSite();
initSiteProfiles(form, site);
if (form.getSrTaxCode() == null) {
return start(actionMapping, actionForm, request, response);
}
Query query = null;
String sql = "select tax " +
"from Tax tax " +
"where siteId = :siteId ";
if (form.getSrTaxCode().length() > 0) {
sql += "and tax.taxLanguage.taxCode like :taxCode ";
}
if (!form.getSrPublished().equals("*")) {
sql += "and published = :published ";
}
sql += "order by taxId";
query = em.createQuery(sql);
query.setParameter("siteId", site.getSiteId());
if (form.getSrTaxCode().length() > 0) {
query.setParameter("taxCode", "%" + form.getSrTaxCode() + "%");
}
if (!form.getSrPublished().equals("*")) {
query.setParameter("published", form.getSrPublished());
}
Iterator<?> iterator = query.getResultList().iterator();
Vector<TaxDisplayForm> vector = new Vector<TaxDisplayForm>();
while (iterator.hasNext()) {
Tax tax = (Tax) iterator.next();
TaxLanguage taxLanguage = null;
for (TaxLanguage language : tax.getTaxLanguages()) {
if (language.getSiteProfileClass().getSiteProfileClassId().equals(form.getSiteProfileClassDefaultId())) {
taxLanguage = language;
}
}
TaxDisplayForm taxDisplay = new TaxDisplayForm();
taxDisplay.setTaxId(Format.getLong(tax.getTaxId()));
taxDisplay.setTaxCode(taxLanguage.getTaxCode());
taxDisplay.setTaxName(taxLanguage.getTaxName());
taxDisplay.setTaxRate(Format.getFloatObj4(tax.getTaxRate()));
taxDisplay.setPublished(String.valueOf(tax.getPublished()));
vector.add(taxDisplay);
}
form.setTaxes(vector);
ActionForward actionForward = actionMapping.findForward("success");
return actionForward;
}