Example usage for javax.servlet RequestDispatcher forward

List of usage examples for javax.servlet RequestDispatcher forward

Introduction

In this page you can find the example usage for javax.servlet RequestDispatcher forward.

Prototype

public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException;

Source Link

Document

Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server.

Usage

From source file:org.apache.wookie.WidgetAdminServlet.java

/**
 * Forward to correct jsp page//from  w  w w . ja  va  2  s.c  o  m
 */
private void doForward(HttpServletRequest request, HttpServletResponse response, String jsp)
        throws ServletException, IOException {
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(jsp);
    dispatcher.forward(request, response);
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.ExternalIdRetryController.java

public void doPost(HttpServletRequest request, HttpServletResponse response) {
    if (!isAuthorizedToDisplayPage(request, response, SimplePermission.DO_BACK_END_EDITING.ACTIONS)) {
        return;//  ww w. ja  v  a  2s.com
    }

    VitroRequest vreq = new VitroRequest(request);

    //create an EditProcessObject for this and put it in the session
    EditProcessObject epo = super.createEpo(request);

    String action = "insert";

    DataPropertyDao dpDao = vreq.getFullWebappDaoFactory().getDataPropertyDao();
    DataPropertyStatementDao edDao = vreq.getFullWebappDaoFactory().getDataPropertyStatementDao();
    epo.setDataAccessObject(edDao);
    epo.setBeanClass(DataPropertyStatement.class);

    IndividualDao eDao = vreq.getFullWebappDaoFactory().getIndividualDao();

    DataPropertyStatement eidForEditing = null;
    if (!epo.getUseRecycledBean()) {
        eidForEditing = new DataPropertyStatementImpl();
        populateBeanFromParams(eidForEditing, vreq);
        if (vreq.getParameter(MULTIPLEXED_PARAMETER_NAME) != null) {
            action = "update";
        }
        epo.setOriginalBean(eidForEditing);
    } else {
        eidForEditing = (DataPropertyStatement) epo.getNewBean();
    }

    //make a simple mask for the class's id
    Object[] simpleMaskPair = new Object[2];
    simpleMaskPair[0] = "Id";
    //simpleMaskPair[1]=Integer.valueOf(eidForEditing.getId());
    epo.getSimpleMask().add(simpleMaskPair);

    //set up any listeners

    FormObject foo = new FormObject();
    HashMap OptionMap = new HashMap();
    List entityList = new LinkedList();
    if (eidForEditing.getIndividualURI() != null) {
        Individual individual = eDao.getIndividualByURI(eidForEditing.getIndividualURI());
        entityList.add(new Option(individual.getURI(), individual.getName(), true));
    } else {
        entityList.add(new Option("-1", "Error: the entity must be specified", true));
    }
    OptionMap.put("IndividualURI", entityList);
    // TOOD change following DAO call to getAllExternalIdDataProperties once implemented
    List allExternalIdDataProperties = dpDao.getAllExternalIdDataProperties();
    Collections.sort(allExternalIdDataProperties);
    OptionMap.put("DatapropURI", FormUtils.makeOptionListFromBeans(allExternalIdDataProperties, "URI",
            "PublicName", eidForEditing.getDatapropURI(), ""));
    foo.setOptionLists(OptionMap);
    foo.setErrorMap(epo.getErrMsgMap());

    epo.setFormObject(foo);

    FormUtils.populateFormFromBean(eidForEditing, action, foo, epo.getBadValueMap());

    RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
    request.setAttribute("bodyJsp", "/templates/edit/formBasic.jsp");
    request.setAttribute("formJsp", "/templates/edit/specific/externalIds_retry.jsp");
    request.setAttribute("scripts", "/templates/edit/formBasic.js");
    request.setAttribute("title", "External Id Editing Form");
    request.setAttribute("_action", action);
    request.setAttribute("unqualifiedClassName", "External Id");
    setRequestAttributes(request, epo);

    try {
        rd.forward(request, response);
    } catch (Exception e) {
        log.error("ExternalIdRetryController could not forward to view.");
        log.error(e.getMessage());
        log.error(e.getStackTrace());
    }

}

From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.IndividualTypeRetryController.java

public void doGet(HttpServletRequest request, HttpServletResponse response) {
    if (!isAuthorizedToDisplayPage(request, response, SimplePermission.DO_BACK_END_EDITING.ACTION)) {
        return;//from   w  w  w . j a  v  a  2s .  c  o m
    }

    //create an EditProcessObject for this and put it in the session
    EditProcessObject epo = super.createEpo(request);

    VitroRequest vreq = new VitroRequest(request);

    WebappDaoFactory wadf = vreq.getUnfilteredAssertionsWebappDaoFactory();
    IndividualDao iDao = wadf.getIndividualDao();
    VClassDao vcDao = wadf.getVClassDao();

    String individualURI = request.getParameter("IndividualURI");

    Individual ind = iDao.getIndividualByURI(individualURI);
    if (ind == null) {
        ind = new IndividualImpl(individualURI);
    }
    request.setAttribute("individual", ind);

    List<VClass> allVClasses = vcDao.getAllVclasses();
    sortForPickList(allVClasses, vreq);

    Set<String> prohibitedURIset = new HashSet<String>();
    for (Iterator<VClass> indClassIt = ind.getVClasses(false).iterator(); indClassIt.hasNext();) {
        VClass vc = indClassIt.next();
        if (vc.isAnonymous()) {
            continue;
        }
        prohibitedURIset.add(vc.getURI());
        for (Iterator<String> djURIIt = vcDao.getDisjointWithClassURIs(vc.getURI()).iterator(); djURIIt
                .hasNext();) {
            String djURI = djURIIt.next();
            prohibitedURIset.add(djURI);
        }
    }

    List<VClass> eligibleVClasses = new ArrayList<VClass>();
    for (VClass vc : allVClasses) {
        if (vc.getURI() != null && !(prohibitedURIset.contains(vc.getURI()))) {
            eligibleVClasses.add(vc);
        }
    }

    FormObject foo = new FormObject();
    epo.setFormObject(foo);
    HashMap optionMap = new HashMap();
    foo.setOptionLists(optionMap);

    List<Option> typeOptionList = new ArrayList<Option>();
    for (VClass vc : eligibleVClasses) {
        Option opt = new Option(vc.getURI(), vc.getPickListName());
        typeOptionList.add(opt);
    }

    optionMap.put("types", typeOptionList);

    RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
    request.setAttribute("editAction", "individualTypeOp");
    request.setAttribute("bodyJsp", "/templates/edit/formBasic.jsp");
    request.setAttribute("scripts", "/templates/edit/formBasic.js");
    request.setAttribute("formJsp", "/templates/edit/specific/individualType_retry.jsp");
    request.setAttribute("title", "Individual Type Editing Form");
    request.setAttribute("_action", "insert");
    setRequestAttributes(request, epo);

    try {
        rd.forward(request, response);
    } catch (Exception e) {
        log.error(this.getClass().getName() + " could not forward to view.");
        log.error(e.getMessage());
        log.error(e.getStackTrace());
    }

}

From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.DatatypeRetryController.java

public void doPost(HttpServletRequest req, HttpServletResponse response) {
    if (!isAuthorizedToDisplayPage(req, response, SimplePermission.EDIT_ONTOLOGY.ACTION)) {
        return;//from  w  ww.j  ava 2  s.  c o  m
    }

    VitroRequest request = new VitroRequest(req);

    //create an EditProcessObject for this and put it in the session
    EditProcessObject epo = super.createEpo(request);

    DatatypeDao dDao = request.getUnfilteredWebappDaoFactory().getDatatypeDao();
    epo.setDataAccessObject(dDao);
    Datatype objectForEditing = null;
    String action = "";

    if (request.getParameter("id") != null) {
        int id = Integer.parseInt(request.getParameter("id"));

        if (id > 0) {
            try {
                log.debug("Trying to retrieve datatype " + id);
                objectForEditing = dDao.getDatatypeById(id);
                action = "update";
            } catch (NullPointerException e) {
                log.error("Need to implement 'record not found' error message.");
            }
        }
    } else {
        action = "insert";
        objectForEditing = new Datatype();
    }

    epo.setOriginalBean(objectForEditing);

    //put this in the parent class?
    //make a simple mask for the class's id
    Object[] simpleMaskPair = new Object[2];
    simpleMaskPair[0] = "Id";
    simpleMaskPair[1] = Integer.valueOf(objectForEditing.getId());
    epo.getSimpleMask().add(simpleMaskPair);

    //set the getMethod so we can retrieve a new bean after we've inserted it
    try {
        Class[] args = new Class[1];
        args[0] = int.class;
        epo.setGetMethod(dDao.getClass().getDeclaredMethod("getDatatypeById", args));
    } catch (NoSuchMethodException e) {
        log.error("EntityRetryController could not find the entityById method in the facade");
    }

    epo.setPostInsertPageForwarder(new DatatypeInsertPageForwarder());
    epo.setPostDeletePageForwarder(new DatatypeDeletePageForwarder());

    FormObject foo = new FormObject();
    epo.setFormObject(foo);
    FormUtils.populateFormFromBean(objectForEditing, action, foo);
    //for now, this is also making the value hash - need to separate this out

    RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
    request.setAttribute("bodyJsp", "/templates/edit/formBasic.jsp");
    request.setAttribute("scripts", "/templates/edit/formBasic.js");
    request.setAttribute("formJsp", "/templates/edit/specific/datatype_retry.jsp");
    request.setAttribute("title", "Datatype Editing Form");
    request.setAttribute("_action", action);
    request.setAttribute("unqualifiedClassName", "Datatype");
    setRequestAttributes(request, epo);

    try {
        rd.forward(request, response);
    } catch (Exception e) {
        log.error("VclassRetryContro" + "ller could not forward to view.");
        log.error(e.getMessage());
        log.error(e.getStackTrace());
    }

}

From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.ApplicationBeanRetryController.java

public void doPost(HttpServletRequest req, HttpServletResponse response) {

    if (!isAuthorizedToDisplayPage(req, response, SimplePermission.EDIT_SITE_INFORMATION.ACTION)) {
        return;// w ww  .  j  a  v  a2  s .c  o m
    }

    VitroRequest request = new VitroRequest(req);

    try {
        super.doGet(request, response);
    } catch (Exception e) {
        log.error(e, e);
    }

    //create an EditProcessObject for this and put it in the session
    EditProcessObject epo = super.createEpo(request);

    epo.setBeanClass(ApplicationBean.class);

    String action = "update";

    ApplicationDao aDao = request.getUnfilteredWebappDaoFactory().getApplicationDao();
    ApplicationBean applicationForEditing = aDao.getApplicationBean();
    epo.setDataAccessObject(aDao);

    if (!epo.getUseRecycledBean()) {
        action = "update";
        epo.setOriginalBean(applicationForEditing);
    } else {
        applicationForEditing = (ApplicationBean) epo.getNewBean();
        action = "update";
        log.debug("using newBean");
    }

    //set the getMethod so we can retrieve a new bean after we've inserted it
    try {
        epo.setGetMethod(aDao.getClass().getDeclaredMethod("getApplicationBean"));
    } catch (NoSuchMethodException e) {
        log.error("could not find the getApplicationBean method in the facade");
    }

    FormObject foo = new FormObject();
    foo.setErrorMap(epo.getErrMsgMap());

    HashMap optionMap = new HashMap();

    List<Option> themeOptions = getThemeOptions(applicationForEditing);
    optionMap.put("ThemeDir", themeOptions);

    foo.setOptionLists(optionMap);

    epo.setFormObject(foo);
    FormUtils.populateFormFromBean(applicationForEditing, epo.getAction(), foo);

    RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
    request.setAttribute("bodyJsp", "/templates/edit/formContact.jsp");
    request.setAttribute("formJsp", "/templates/edit/specific/applicationBean_retry.jsp");
    request.setAttribute("scripts", "/templates/edit/formBasic.js");
    request.setAttribute("title", "Site Information");
    request.setAttribute("_action", action);
    request.setAttribute("unqualifiedClassName", "ApplicationBean");
    setRequestAttributes(request, epo);

    try {
        rd.forward(request, response);
    } catch (Exception e) {
        log.error(e, e);
    }

}

From source file:eu.earthobservatory.org.StrabonEndpoint.BrowseBean.java

/**
 * Processes the request made from the HTML visual interface of Strabon
 * Endpoint./*w  w  w.j a  v a  2  s  .c  o m*/
 * 
 * @param request
 * @param response
 * @throws ServletException
 * @throws IOException
 */
private void processVIEWRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    RequestDispatcher dispatcher;

    String query = URLDecoder.decode(request.getParameter("query"), "UTF-8");
    String format = request.getParameter("format");

    // get stSPARQLQueryResultFormat from given format name
    TupleQueryResultFormat queryResultFormat = stSPARQLQueryResultFormat.valueOf(format);

    if (query == null || format == null || queryResultFormat == null) {
        dispatcher = request.getRequestDispatcher("browse.jsp");
        request.setAttribute(ERROR, PARAM_ERROR);
        dispatcher.forward(request, response);

    } else {
        dispatcher = request.getRequestDispatcher("browse.jsp");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        request.setAttribute("resource", request.getParameter("resource"));

        try {
            strabonWrapper.query(query, format, bos);
            if (format.equals(Common.getHTMLFormat())) {
                request.setAttribute(RESPONSE, bos.toString());
            } else {
                request.setAttribute(RESPONSE, StringEscapeUtils.escapeHtml(bos.toString()));
            }

        } catch (Exception e) {
            logger.error("[StrabonEndpoint.BrowseBean] Error during querying.", e);
            request.setAttribute(ERROR, e.getMessage());

        } finally {
            dispatcher.forward(request, response);
        }
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.jena.RDFUploadController.java

@Override
public void doPost(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException {
    if (!isAuthorizedToDisplayPage(req, response, SimplePermission.USE_ADVANCED_DATA_TOOLS_PAGES.ACTION)) {
        return;//from   w w  w. j a  v a 2  s  .co m
    }

    VitroRequest request = new VitroRequest(req);
    if (request.hasFileSizeException()) {
        forwardToFileUploadError(request.getFileSizeException().getLocalizedMessage(), req, response);
        return;
    }

    Map<String, List<FileItem>> fileStreams = request.getFiles();

    LoginStatusBean loginBean = LoginStatusBean.getBean(request);

    try {
        String modelName = req.getParameter("modelName");
        if (modelName != null) {
            loadRDF(request, response);
            return;
        }
    } catch (Exception e) {
        log.error(e, e);
        throw new RuntimeException(e);
    }

    boolean remove = "remove".equals(request.getParameter("mode"));
    String verb = remove ? "Removed" : "Added";

    String languageStr = request.getParameter("language");

    boolean makeClassgroups = ("true".equals(request.getParameter("makeClassgroups")));

    // add directly to the ABox model without reading first into 
    // a temporary in-memory model
    boolean directRead = ("directAddABox".equals(request.getParameter("mode")));

    String uploadDesc = "";

    OntModel uploadModel = (directRead) ? getABoxModel(getServletContext())
            : ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);

    /* ********************* GET RDF by URL ********************** */
    String RDFUrlStr = request.getParameter("rdfUrl");
    if (RDFUrlStr != null && RDFUrlStr.length() > 0) {
        try {
            uploadModel.enterCriticalSection(Lock.WRITE);
            try {
                uploadModel.read(RDFUrlStr, languageStr);
                // languageStr may be null and default would be RDF/XML
            } finally {
                uploadModel.leaveCriticalSection();
            }
            uploadDesc = verb + " RDF from " + RDFUrlStr;
        } catch (JenaException ex) {
            forwardToFileUploadError("Could not parse file to " + languageStr + ": " + ex.getMessage(), req,
                    response);
            return;
        } catch (Exception e) {
            forwardToFileUploadError("Could not load from URL: " + e.getMessage(), req, response);
            return;
        }
    } else {
        /* **************** upload RDF from POST ********************* */
        if (fileStreams.get("rdfStream") != null && fileStreams.get("rdfStream").size() > 0) {
            FileItem rdfStream = fileStreams.get("rdfStream").get(0);
            try {
                if (directRead) {
                    addUsingRDFService(rdfStream.getInputStream(), languageStr, request.getRDFService());
                } else {
                    uploadModel.enterCriticalSection(Lock.WRITE);
                    try {
                        uploadModel.read(rdfStream.getInputStream(), null, languageStr);
                    } finally {
                        uploadModel.leaveCriticalSection();
                    }
                }
                uploadDesc = verb + " RDF from file " + rdfStream.getName();
            } catch (IOException e) {
                forwardToFileUploadError("Could not read file: " + e.getLocalizedMessage(), req, response);
                return;
            } catch (JenaException ex) {
                forwardToFileUploadError("Could not parse file to " + languageStr + ": " + ex.getMessage(), req,
                        response);
                return;
            } catch (Exception e) {
                forwardToFileUploadError("Could not load from file: " + e.getMessage(), req, response);
                return;
            } finally {
                rdfStream.delete();
            }
        }
    }

    /* ********** Do the model changes *********** */
    if (!directRead && uploadModel != null) {

        uploadModel.loadImports();

        long tboxstmtCount = 0L;
        long aboxstmtCount = 0L;

        JenaModelUtils xutil = new JenaModelUtils();

        OntModel tboxModel = getTBoxModel();
        OntModel aboxModel = getABoxModel(getServletContext());
        OntModel tboxChangeModel = null;
        Model aboxChangeModel = null;
        OntModelSelector ontModelSelector = ModelAccess.on(getServletContext()).getOntModelSelector();

        if (tboxModel != null) {
            boolean AGGRESSIVE = true;
            tboxChangeModel = xutil.extractTBox(uploadModel, AGGRESSIVE);
            // aggressively seek all statements that are part of the TBox  
            tboxstmtCount = operateOnModel(request.getUnfilteredWebappDaoFactory(), tboxModel, tboxChangeModel,
                    ontModelSelector, remove, makeClassgroups, loginBean.getUserURI());
        }
        if (aboxModel != null) {
            aboxChangeModel = uploadModel.remove(tboxChangeModel);
            aboxstmtCount = operateOnModel(request.getUnfilteredWebappDaoFactory(), aboxModel, aboxChangeModel,
                    ontModelSelector, remove, makeClassgroups, loginBean.getUserURI());
        }
        request.setAttribute("uploadDesc",
                uploadDesc + ". " + verb + " " + (tboxstmtCount + aboxstmtCount) + "  statements.");
    } else {
        request.setAttribute("uploadDesc", "RDF upload successful.");
    }

    RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
    request.setAttribute("bodyJsp", "/templates/edit/specific/upload_rdf_result.jsp");
    request.setAttribute("title", "Ingest RDF Data");

    try {
        rd.forward(request, response);
    } catch (Exception e) {
        log.error("Could not forward to view: " + e.getLocalizedMessage());
    }
}

From source file:at.ac.univie.isc.asio.insight.ExplorerPageRedirectFilter.java

@Override
protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain chain) throws ServletException, IOException {
    final String redirect = template.findRedirectTarget(request);
    final String original = request.getRequestURI();

    if (redirect == null) { // skip redirect
        log.debug(Scope.REQUEST.marker(), "not an explorer request ({}) - skip redirecting", original);
        chain.doFilter(request, response);
        return;/*from   w  w w  .  j a  v  a 2s  . c o  m*/
    }

    assert redirect.startsWith("/") : "redirect target is not an absolute path";
    final RequestDispatcher dispatcher = request.getRequestDispatcher(redirect);
    if (dispatcher == null) { // redirect cannot be handled
        final String message = Pretty.format("no handler for request to <%s> (redirected from <%s>) found",
                redirect, original);
        log.debug(Scope.REQUEST.marker(), message);
        if (!response.isCommitted()) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND, message);
        }
        return;
    }

    log.debug(Scope.REQUEST.marker(), "redirect request from {} to {}", original, redirect);
    dispatcher.forward(request, response);
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.ClassgroupRetryController.java

public void doPost(HttpServletRequest req, HttpServletResponse response) {
    if (!isAuthorizedToDisplayPage(req, response, SimplePermission.USE_MISCELLANEOUS_ADMIN_PAGES.ACTION)) {
        return;//from  www.j av  a  2s.co  m
    }

    VitroRequest request = new VitroRequest(req);

    //create an EditProcessObject for this and put it in the session
    EditProcessObject epo = super.createEpo(request);

    String action = null;
    if (epo.getAction() == null) {
        action = "insert";
        epo.setAction("insert");
    } else {
        action = epo.getAction();
    }

    VClassGroupDao cgDao = ModelAccess.on(getServletContext()).getWebappDaoFactory().getVClassGroupDao();

    epo.setDataAccessObject(cgDao);

    VClassGroup vclassGroupForEditing = null;
    if (!epo.getUseRecycledBean()) {
        if (request.getParameter("uri") != null) {
            try {
                vclassGroupForEditing = (VClassGroup) cgDao.getGroupByURI(request.getParameter("uri"));
                action = "update";
                epo.setAction("update");
            } catch (NullPointerException e) {
                log.error("Need to implement 'record not found' error message.");
            }
            if (vclassGroupForEditing == null) {
                //UTF-8 expected due to URIEncoding on Connector in server.xml
                String uriToFind = new String(request.getParameter("uri"));
                vclassGroupForEditing = (VClassGroup) cgDao.getGroupByURI(uriToFind);
            }
        } else {
            vclassGroupForEditing = new VClassGroup();
        }
        epo.setOriginalBean(vclassGroupForEditing);
    } else {
        vclassGroupForEditing = (VClassGroup) epo.getNewBean();
    }

    //validators
    List<Validator> validatorList = new ArrayList<Validator>();
    validatorList.add(new RequiredFieldValidator());
    epo.getValidatorMap().put("PublicName", validatorList);

    //make a postinsert pageforwarder that will send us to a new class's fetch screen
    epo.setPostInsertPageForwarder(new VclassGroupInsertPageForwarder());
    //make a postdelete pageforwarder that will send us to the list of classes
    epo.setPostDeletePageForwarder(new UrlForwarder("listGroups"));

    //set the getMethod so we can retrieve a new bean after we've inserted it
    try {
        Class[] args = new Class[1];
        args[0] = String.class;
        epo.setGetMethod(cgDao.getClass().getDeclaredMethod("getGroupByURI", args));
    } catch (NoSuchMethodException e) {
        log.error(this.getClass().getName() + " could not find the getGroupByURI method");
    }

    FormObject foo = new FormObject();
    foo.setErrorMap(epo.getErrMsgMap());
    epo.setFormObject(foo);

    FormUtils.populateFormFromBean(vclassGroupForEditing, action, foo, epo.getBadValueMap());

    RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
    request.setAttribute("bodyJsp", "/templates/edit/formBasic.jsp");
    request.setAttribute("formJsp", "/templates/edit/specific/classgroup_retry.jsp");
    request.setAttribute("scripts", "/templates/edit/formBasic.js");
    request.setAttribute("title", "Classgroup Editing Form");
    request.setAttribute("_action", action);
    request.setAttribute("unqualifiedClassName", "VClassGroup");
    setRequestAttributes(request, epo);

    try {
        rd.forward(request, response);
    } catch (Exception e) {
        log.error("VclassGroupRetryController could not forward to view.");
        log.error(e.getMessage());
        log.error(e.getStackTrace());
    }

}

From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.PropertyGroupRetryController.java

public void doPost(HttpServletRequest req, HttpServletResponse response) {
    if (!isAuthorizedToDisplayPage(req, response, SimplePermission.USE_MISCELLANEOUS_ADMIN_PAGES.ACTION)) {
        return;//from   ww  w  .  java  2s . c  o m
    }

    VitroRequest request = new VitroRequest(req);

    //create an EditProcessObject for this and put it in the session
    EditProcessObject epo = super.createEpo(request);

    String action = null;
    if (epo.getAction() == null) {
        action = "insert";
        epo.setAction("insert");
    } else {
        action = epo.getAction();
    }

    PropertyGroupDao pgDao = ModelAccess.on(getServletContext()).getWebappDaoFactory().getPropertyGroupDao();

    epo.setDataAccessObject(pgDao);

    PropertyGroup propertyGroupForEditing = null;
    if (!epo.getUseRecycledBean()) {
        if (request.getParameter("uri") != null) {
            try {
                propertyGroupForEditing = (PropertyGroup) pgDao.getGroupByURI(request.getParameter("uri"));
                action = "update";
                epo.setAction("update");
            } catch (NullPointerException e) {
                log.error("Need to implement 'record not found' error message.");
            }
            if (propertyGroupForEditing == null) {
                // UTF-8 expected due to URIEncoding on Connector element in server.xml
                String uriToFind = new String(request.getParameter("uri"));
                propertyGroupForEditing = (PropertyGroup) pgDao.getGroupByURI(uriToFind);
            }
        } else {
            propertyGroupForEditing = new PropertyGroup();
        }
        epo.setOriginalBean(propertyGroupForEditing);
    } else {
        propertyGroupForEditing = (PropertyGroup) epo.getNewBean();
    }

    //validators
    List<Validator> validatorList = new ArrayList<Validator>();
    validatorList.add(new RequiredFieldValidator());
    epo.getValidatorMap().put("Name", validatorList);

    //make a postinsert pageforwarder that will send us to a new class's fetch screen
    epo.setPostInsertPageForwarder(new PropertyGroupInsertPageForwarder());
    //make a postdelete pageforwarder that will send us to the list of classes
    epo.setPostDeletePageForwarder(new UrlForwarder("listPropertyGroups"));

    //set the getMethod so we can retrieve a new bean after we've inserted it
    try {
        Class[] args = new Class[1];
        args[0] = String.class;
        epo.setGetMethod(pgDao.getClass().getDeclaredMethod("getGroupByURI", args));
    } catch (NoSuchMethodException e) {
        log.error(this.getClass().getName() + " could not find the getGroupByURI method");
    }

    FormObject foo = new FormObject();
    foo.setErrorMap(epo.getErrMsgMap());
    epo.setFormObject(foo);

    FormUtils.populateFormFromBean(propertyGroupForEditing, action, foo, epo.getBadValueMap());

    RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP);
    request.setAttribute("bodyJsp", "/templates/edit/formBasic.jsp");
    request.setAttribute("formJsp", "/templates/edit/specific/propertyGroup_retry.jsp");
    request.setAttribute("scripts", "/templates/edit/formBasic.js");
    request.setAttribute("title", "Property Group Editing Form");
    request.setAttribute("_action", action);
    request.setAttribute("unqualifiedClassName", "PropertyGroup");
    setRequestAttributes(request, epo);

    try {
        rd.forward(request, response);
    } catch (Exception e) {
        log.error("PropertyGroupRetryController could not forward to view.");
        log.error(e.getMessage());
        log.error(e.getStackTrace());
    }

}