/** * @author Added By Subhash Chandrashaker.V * @purpose Overridden For Retriving Search Query After MODIFY OR CANCEL the record * @param request * @param response * @return ModelAndView */ public ModelAndView onSubmit( HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { String action = (String) request.getAttribute(Constants.REQUEST_FORM_ACTION_FIELD); request.removeAttribute("successmessage"); DefaultListFormBackingObject backingObject = (DefaultListFormBackingObject) command; // For Reseting The Page Number to 1 for every search (SUBHASH CHANDRASHAKER.V) START if (Constants.ACTION_SEARCH.equals(action) && backingObject.getPageOperation() == null) { backingObject.setPageNumber(null); backingObject.setTotalPages(null); } // For Reseting The Page Number to 1 for every search (SUBHASH CHANDRASHAKER.V) END if (Constants.ACTION_SEARCH.equals(action)) { if (request.getSession().getAttribute("searchCriteriaObject") != null) { request.getSession().removeAttribute("searchCriteriaObject"); request.getSession().removeAttribute("searchCriteriaFunctionCode"); } } else { SearchFormCriteria criteria = (SearchFormCriteria) backingObject.getDataObject(); request.getSession().setAttribute("searchCriteriaObject", criteria); request.getSession().setAttribute("searchCriteriaFunctionCode", getFunctionCode()); } ModelAndView ret = null; if (action != null) { if (Constants.ACTION_REDIRECT.equals(action) || Constants.ACTION_SAVEREDIRECT.equals(action)) { ret = listRedirect(request, response, command, errors); } else if (Constants.ACTION_NEW.equals(action)) { ret = listNew(request, response, command, errors); } else if (Constants.ACTION_COPY.equals(action)) { ret = listCopy(request, response, command, errors); } else if (Constants.ACTION_VIEW.equals(action)) { ret = listView(request, response, command, errors); } else if (Constants.ACTION_DELETE.equals(action)) { ret = listDelete(request, response, command, errors); } else if (Constants.ACTION_EDIT.equals(action)) { ret = listEdit(request, response, command, errors); } else if (Constants.ACTION_SEARCH.equals(action)) { ret = listSearch(request, response, command, errors); } else if (Constants.ACTION_TABCHANGE.equals(action)) { ret = listTabChange(request, response, command, errors); } } if (ret == null) { /* * Now just redisplay the same form. */ return showForm(request, response, errors); } else { return ret; } }
/** * Actually runs the query and puts the returned table model on the request as attribute * 'tableModel'. * * @param request * @param criteria * @throws ServletException */ protected void runQuery(HttpServletRequest request, DefaultListFormBackingObject backingObject) throws ServletException { IdTableModel tm = null; ObjectQueryCommand command = createQueryCommand(request, backingObject); SearchFormCriteria criteria = (SearchFormCriteria) backingObject.getDataObject(); // FOR RETERIVING SEARCH CRITERIA WRITTEN BY SUBHASH CHANDRASHAKER.V START String searchCriteriaFunctionCode = (String) request.getSession().getAttribute("searchCriteriaFunctionCode"); if (request.getSession().getAttribute("searchCriteriaObject") != null && searchCriteriaFunctionCode != null && searchCriteriaFunctionCode.equals(getFunctionCode())) { criteria = (SearchFormCriteria) request.getSession().getAttribute("searchCriteriaObject"); backingObject.setDataObject(criteria); request.getSession().removeAttribute("searchCriteriaObject"); request.getSession().removeAttribute("searchCriteriaFunctionCode"); } else if (searchCriteriaFunctionCode != null && !searchCriteriaFunctionCode.equals(getFunctionCode())) { request.getSession().removeAttribute("searchCriteriaObject"); request.getSession().removeAttribute("searchCriteriaFunctionCode"); } // FOR RETERIVING SEARCH CRITERIA WRITTEN BY SUBHASH CHANDRASHAKER.V END if (criteria.getParentInfo() != null) { command.setParentInfo(criteria.getParentInfo()); } /* * If we have criteria, then add them to the command. */ if (criteria.getCriteria() != null && criteria.getCriteria().size() > 0) { Iterator i = criteria.getCriteria().values().iterator(); while (i.hasNext()) { ObjectQueryCommandFilterCriterion crit = (ObjectQueryCommandFilterCriterion) i.next(); if (crit.getValue() != null) { // the validator resets all empty strings to null, so we don't have to check // here // Modified by SIVAPRASAD for single quotes handling if (crit.getAttributeName() != null && crit.getAttributeName().equals("code")) { command.addFilterCriterion( crit.getAttributeName(), crit.getOperator(), StringUtility.escapeCharsSQLQuery(((String) crit.getValue()).toUpperCase())); } else { command.addFilterCriterion( crit.getAttributeName(), crit.getOperator(), StringUtility.escapeCharsSQLQuery((String) crit.getValue())); } } } } /*PAGINATION RELATED CODE STARTS*/ String currentPageNumber = backingObject.getPageNumber(); if (currentPageNumber != null && !"".equals(currentPageNumber) && backingObject.getTotalPages() != null && !"".equals(backingObject.getTotalPages())) { int oldTotal = Integer.parseInt(backingObject.getTotalPages()); int selectedPage = Integer.parseInt(currentPageNumber); if (selectedPage > oldTotal) currentPageNumber = backingObject.getTotalPages(); } String pageOperation = backingObject.getPageOperation(); if ((currentPageNumber == null) || ("").equals(currentPageNumber) || (Integer.parseInt(currentPageNumber) <= 0) && (pageOperation == null || ("").equals(pageOperation))) { currentPageNumber = "1"; } else { // check the Operation requested if (Constants.PAGE_FIRST.equals(pageOperation)) { currentPageNumber = "1"; backingObject.setPageOffset(null); } else if (Constants.PAGE_PREVIOUS.equals(pageOperation)) { int tempCount = (Integer.parseInt(currentPageNumber)); if (tempCount >= 1) { currentPageNumber = Integer.toString(tempCount - 1); if (tempCount == 2 && backingObject.getPageOffset() != null && Integer.parseInt(backingObject.getPageOffset()) > 0) { backingObject.setPageOffset(null); } } } else if (Constants.PAGE_NEXT.equals(pageOperation)) { currentPageNumber = Integer.toString((Integer.parseInt(currentPageNumber)) + 1); } else if (Constants.PAGE_LAST.equals(pageOperation)) { currentPageNumber = Integer.toString(Integer.parseInt(backingObject.getTotalPages())); } else if (Constants.PAGE_CLICK_ENTER.equals(pageOperation)) { // Modified by SIVAPRASAD to display the first page when 0 is entered in the page number if (currentPageNumber.equals("0")) currentPageNumber = "1"; else currentPageNumber = currentPageNumber; } // added above condition for pagenation for WPBN Issue 67620 } setPositionToValues(request, backingObject, command); // enable pagination command.setPaginationEnabled(backingObject.isPaginationEnabled()); command.setCurrentPageNum(Integer.parseInt(currentPageNumber)); // if (backingObject.getSelectedEntityId() != null) { // command.setPositionToEntity(backingObject.getSelectedEntityId()); // } String defaultFetchSize = backingObject.getPageSize(); // set the Fetch Size try { // Modified by Yogesh for Auto Grid Functionality // Modified by Kiran sajja for WPBN ISSUE ID 98681 if (defaultFetchSize != null && !("").equals(defaultFetchSize)) { int defaultFetchSizeInt = Integer.parseInt(defaultFetchSize); command.setPageSize(defaultFetchSizeInt); } else { command.setPageSize(getDefaultAutoSize()); // set the default fetch size to 10 backingObject.setPageNumber("" + getDefaultAutoSize()); } } catch (NumberFormatException ex) { command.setPageSize(getDefaultAutoSize()); // set the default fetch size to 10 backingObject.setPageSize("" + getDefaultAutoSize()); } // modified by lokesh for issue 159432 request.setAttribute("defaultAutoSize", getDefaultAutoSize() + ""); // setup page offset (if required) if (backingObject.getPageOffset() != null) { if (backingObject.getPageSize().equals(backingObject.getPageOffsetForPageSize())) { command.setPageOffset(Integer.parseInt(backingObject.getPageOffset())); } else { // page size has changed, recalc the offset and page int rowPosition = 0; int pageOffset = Integer.parseInt(backingObject.getPageOffset()); if (pageOffset != 0) { rowPosition = pageOffset + ((Integer.parseInt(backingObject.getPageNumber()) - 2) * Integer.parseInt(backingObject.getPageOffsetForPageSize())); pageOffset = rowPosition % command.getPageSize(); command.setPageOffset(pageOffset); command.setCurrentPageNum(((rowPosition - pageOffset) / command.getPageSize()) + 2); } } } // work out if we have a pagination-related change boolean paginationChange = false; // page changed if (backingObject.getPageNumber() != null && backingObject.getTableModel() != null) { int requestedPageNumber = Integer.parseInt(backingObject.getPageNumber()); if (requestedPageNumber != backingObject.getTableModel().getPageNumber()) { paginationChange = true; } } if (backingObject.getPageSize() != null && backingObject.getPageOffsetForPageSize() != null) { if (!backingObject.getPageSize().equals(backingObject.getPageOffsetForPageSize())) { paginationChange = true; } } if (backingObject.getPageOperation() != null && !"".equals(backingObject.getPageOperation())) { paginationChange = true; } // if the pagination has not changed, reset to the first page because we're doing a search if (!paginationChange) { command.setCurrentPageNum(1); backingObject.setPageNumber("1"); command.setPageOffset(0); backingObject.setPageOffset("0"); } try { command.setCurrentPageNum(Integer.parseInt(currentPageNumber)); } catch (NumberFormatException e) { command.setCurrentPageNum(1); } /* PAGINATION RELATED CODE CONTINUES */ tm = retrieveQueryResults(command); /* PAGINATION RELATED CODE CONTINUED */ // CALCULATE THE TOTAL PAGE COUNT Object[][] data = tm.getData(); if (data.length > 0) { int totalPages = 1; if ((tm.getTotalRowCount() > command.getPageSize()) || tm.getPageOffset() != 0) { int totalRows = tm.getTotalRowCount(); int offset = tm.getPageOffset(); int overhang = (totalRows - offset) % command.getPageSize(); // normal pages in the set totalPages = 0; // if we overhang, e.g. 15 rows on page size 10, then add extra page if (offset > 0) totalPages += 1; if (overhang > 0) totalPages += 1; totalPages += (totalRows - (offset + overhang)) / command.getPageSize(); } command.setTotalPageCount(totalPages); // commented for pagenation for WPBN Issue 67620 // currentPageNumber = Integer.toString(tm.getPageNumber()); } else { request.setAttribute( "successmessage", ResourceUtils.getLiteral("norecordsfound", getUserLocale(request))); command.setTotalPageCount(1); currentPageNumber = "1"; } // set the new Total Page Count backingObject.setTotalPages(Integer.toString(command.getTotalPageCount())); // set the new Page Number backingObject.setPageNumber(currentPageNumber); // set the defaultFetchSize backingObject.setPageSize(Integer.toString(command.getPageSize())); // set the page offset (for position to) backingObject.setPageOffset(Integer.toString(tm.getPageOffset())); backingObject.setPageOffsetForPageSize(backingObject.getPageSize()); // reset for the next query backingObject.setPageOperation(null); /*PAGINATION RELATED CODE ENDS*/ request.setAttribute("tableModel", tm); backingObject.setTableModel(tm); TableLayoutDescriptor layoutDescriptor = new TableLayoutDescriptor(tm); setTableLayout(layoutDescriptor, tm, backingObject, request); ((DefaultListFormBackingObject) backingObject).setTableLayout(layoutDescriptor); request.setAttribute("tableColumnHeadings", getColumnHeadings(getUserLocale(request))); // Added By vara for Issue Id: 88316 to retain the customized grid column width String tableColumnString = request.getParameter("tableColumnSize"); String tableColumnSize[] = setColumnSize(); if (tableColumnString != null && tableColumnString != "" && !tableColumnString.equals("")) { tableColumnSize = tableColumnString.split(","); } request.setAttribute("tableColumnSize", tableColumnSize); // End backingObject.setDisplayTab(Constants.ACTION_LIST); request.setAttribute(Constants.REQUEST_FORM_ACTION_FIELD, Constants.ACTION_LIST); // make sure the view knows what URL to access to maintain an instance request.setAttribute(Constants.REQUEST_MAINTAINER_URL, getMaintainerUrl()); }