Example usage for javax.servlet.http HttpServletRequest getParameterValues

List of usage examples for javax.servlet.http HttpServletRequest getParameterValues

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getParameterValues.

Prototype

public String[] getParameterValues(String name);

Source Link

Document

Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.

Usage

From source file:com.virtusa.akura.staff.controller.SubjectTeacherAssignController.java

/**
 * Assign a subject teacher object./*  ww w  . j a va  2  s.  co m*/
 * 
 * @param request - an object of HttpServletRequest
 * @param map - a HashMap that contains information of the District
 * @param subTeacher - subject teacher object.
 * @return - name of the view which is redirected to
 * @throws AkuraAppException - The exception details that occurred when add a subject teacher.
 */
@RequestMapping(ADDSUBJECTTEACHER_HTM)
public final String addSubjectTeacher(@ModelAttribute(SUBJECT_TEACHER) SubjectTeacher subTeacher, ModelMap map,
        final HttpServletRequest request) throws AkuraAppException {

    String message;
    String[] classIds = request.getParameterValues(CLASS_ID);
    String selectedGradeSubject = request.getParameter(SELECT_GRADE_SUBJECTS);
    String updateTeacherId = request.getParameter(UPDATE_SELECTED_SUBJECT_TEACHER_ID);
    SubjectTeacher subjectTeacher;

    // int intSubjectTeacherId = subTeacher.getSubjectTeacherId();

    // Validate the user inputs and show an error message if validation fails.
    if (subTeacher.getStaff().getStaffId() == 0 || subTeacher.getGradeId() == 0
            || selectedGradeSubject.equals(ZERO_STRING) || classIds == null
            || subTeacher.getYear().equals(ZERO_STRING)) {
        message = new ErrorMsgLoader().getErrorMessage(REF_UI_MANDATORY_FIELD_REQUIRED);
        map.addAttribute(MESSAGE, message);

        map.addAttribute("subTeacher", subTeacher);

        if (subTeacher.getSubjectTeacherId() != null) {
            subjectTeacher = staffService.findsubjectTeacherById(subTeacher.getSubjectTeacherId());
            map.addAttribute(MODEL_ATT_SELECTED_OBJECT, subjectTeacher);
        }
        // map.addAttribute(MODEL_ATT_SELECTED_OBJECT_ID, intSubjectTeacherId);

        return VIEW_TEACHER_SUBJECT_ALLOCATION;

    } else {
        int subjectId = Integer.parseInt(selectedGradeSubject);
        int gradeSubjectradeId = commonService
                .getGradeSubjectByGradeAndSubject(subTeacher.getGradeId(), subjectId).get(0)
                .getGradeSubjectId();
        int staffId = subTeacher.getStaff().getStaffId();
        String year = subTeacher.getYear();
        GradeSubject gradeSubject = commonService.findGradeSubject(gradeSubjectradeId);
        Staff staff = staffService.findStaff(staffId);
        subTeacher.setStaff(staff);
        subTeacher.setGradeSubject(gradeSubject);
        subTeacher.setYear(year);

        // Get the list of selected classes to an array list.
        List<String> selectedclassList = new ArrayList<String>();
        selectedclassList = Arrays.asList(classIds);

        // Check the action to perform, whether to update or add new record.
        boolean update = updateTeacherId.equals(EMPTY_STRING) ? false : true;

        if (update) {

            // Get the id of the subject teacher to be updated.
            updateTeacherId = (updateTeacherId.equals(EMPTY_STRING) ? ZERO_STRING : updateTeacherId);
            int updateId = Integer.parseInt(updateTeacherId);

            // Get the Subject teacher to be updated.
            SubjectTeacher subjectTeachertobeUpdated = staffService.findsubjectTeacherById(updateId);

            // If the subject teacher to be updated is null then assign it to the subject teacher in the
            // model.
            subjectTeachertobeUpdated = (subjectTeachertobeUpdated == null ? subTeacher
                    : subjectTeachertobeUpdated);

            // If this teacher exist show teacher exist error message.
            if (isExistsSubjectTeacher(staffId, gradeSubjectradeId, year)) {

                if (subjectTeachertobeUpdated.getSubjectTeacherId()
                        .equals(staffService.getSubjectTeacherList(staffId, gradeSubjectradeId, year).get(0)
                                .getSubjectTeacherId())) {
                    staffService.deleteSubjectTeacher(staffId, gradeSubjectradeId, year);
                } else {
                    message = new ErrorMsgLoader().getErrorMessage(REF_UI_SUBJECTTEACHER_ALREADY_EXIST);
                    map.addAttribute(MESSAGE, message);
                    return VIEW_TEACHER_SUBJECT_ALLOCATION;
                }
            }

            // Get the list of Subject teachers with the updating staffId, gradeId, subjectId and year.
            List<SubjectTeacher> subjectTeacherList = staffService.getSubjectTeacherList(
                    subjectTeachertobeUpdated.getStaff().getStaffId(),
                    subjectTeachertobeUpdated.getGradeSubject().getGradeSubjectId(),
                    subjectTeachertobeUpdated.getYear());

            // Delete the list of subject teachers.
            for (SubjectTeacher deleteOrAddTeacher : subjectTeacherList) {
                staffService.deleteSubjectTeacher(deleteOrAddTeacher);
            }

            // Set the Subject teacher Class and add new subject teachers.
            setTeacherSubjects(subTeacher, selectedclassList);

            // Set the subject teacher allocation update successful message.
            message = new ErrorMsgLoader().getErrorMessage(MESSAGE_RECORD_UPDATED);
            map.addAttribute(SUCCESS_MESSAGE, message);
        } else {

            // If this teacher exist show teacher exist error message.
            if (isExistsSubjectTeacher(staffId, gradeSubjectradeId, year)) {
                message = new ErrorMsgLoader().getErrorMessage(REF_UI_SUBJECTTEACHER_ALREADY_EXIST);
                map.addAttribute(MESSAGE, message);
                return VIEW_TEACHER_SUBJECT_ALLOCATION;
            }
            setTeacherSubjects(subTeacher, selectedclassList);

            // Set the new subject teacher allocation successful message.
            message = new ErrorMsgLoader().getErrorMessage(MESSAGE_RECORD_ADDED);
            map.addAttribute(SUCCESS_MESSAGE, message);
        }
    }
    return VIEW_TEACHER_SUBJECT_ALLOCATION;
}

From source file:edu.cornell.mannlib.vedit.controller.BaseEditController.java

protected void populateBeanFromParams(Object bean, HttpServletRequest request) {
    Map params = request.getParameterMap();
    Enumeration paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
        String key = "";
        try {/*from  ww  w  .j  a  v a 2  s. co  m*/
            key = (String) paramNames.nextElement();
        } catch (ClassCastException cce) {
            log.error("populateBeanFromParams() could not cast parameter name to String");
        }
        String value = "";
        if (key.equals(MULTIPLEXED_PARAMETER_NAME)) {
            String multiplexedStr = request.getParameterValues(key)[0];
            Map paramMap = FormUtils.beanParamMapFromString(multiplexedStr);
            Iterator paramIt = paramMap.keySet().iterator();
            while (paramIt.hasNext()) {
                String param = (String) paramIt.next();
                String demultiplexedValue = (String) paramMap.get(param);
                FormUtils.beanSet(bean, param, demultiplexedValue);
            }

        } else {
            try {
                value = (String) request.getParameterValues(key)[0];
            } catch (ClassCastException cce) {
                try {
                    value = ((Integer) params.get(key)).toString();
                } catch (ClassCastException ccf) {
                    log.error("populateBeanFromParams() could not cast parameter name to String");
                }
            }
            FormUtils.beanSet(bean, key, value);
        }
    }
}

From source file:com.adito.security.actions.ShowAvailableAccountsDispatchAction.java

/**
 * @param mapping//from w  w  w  .  j a v a 2 s .co  m
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 * @throws Exception
 */
public ActionForward confirmDisableAccount(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    PolicyUtil.checkPermission(PolicyConstants.ACCOUNTS_AND_GROUPS_RESOURCE_TYPE, PolicyConstants.PERM_DELETE,
            request);
    String[] accounts = request.getParameterValues("username");
    if (accounts == null || accounts.length != 1) {
        ActionMessages mesgs = new ActionMessages();
        mesgs.add(Globals.ERROR_KEY, new ActionMessage("availableAccounts.atLeastOneAccountNotSelected"));
        saveErrors(request, mesgs);
        return list(mapping, form, request, response);
    } else {
        UserDatabase udb = UserDatabaseManager.getInstance()
                .getUserDatabase(getSessionInfo(request).getUser().getRealm());
        for (int i = 0; accounts != null && i < accounts.length; i++) {
            User user = udb.getAccount(accounts[i]);
            if (null != user.getPrincipalName() && user.getPrincipalName()
                    .equals(this.getSessionInfo(request).getUser().getPrincipalName())) {
                ActionMessages mesgs = new ActionMessages();
                mesgs.add(Globals.ERROR_KEY, new ActionMessage("status.sessions.cannotLogoffYourself"));
                saveErrors(request, mesgs);
                return new ActionForward("/confirmDisableAccount.do");
            }
        }
        disable(mapping, form, request, response);
    }
    return list(mapping, form, request, response);
}

From source file:edu.lafayette.metadb.web.controlledvocab.ShowVocab.java

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*//* w  w  w.j  av  a2  s.c  o  m*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // TODO Auto-generated method stub
    String vocabName = request.getParameter("vocab-name");
    //MetaDbHelper.note("Vocab Name in Servlet: "+vocabName);
    PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF8"), true);
    response.setCharacterEncoding("utf-8");
    request.setCharacterEncoding("utf-8");
    JSONArray vocab = new JSONArray();
    try {
        Set<String> vocabList = ControlledVocabDAO.getControlledVocab(vocabName);
        Iterator<String> itr = vocabList.iterator();
        String[] term = request.getParameterValues("term");

        boolean autocomplete = term != null && !(term[0].equals(""));
        while (itr.hasNext()) {
            String entry = itr.next();
            if (autocomplete) {
                //MetaDbHelper.note("Entry: "+entry+", query: "+term[0]);
                if (entry.toLowerCase().startsWith(term[0].toLowerCase()))
                    vocab.put(entry);
            } else
                vocab.put(entry);
        }
        out.print(vocab);
    } catch (Exception e) {
        MetaDbHelper.logEvent(e);
    }
    out.flush();
}

From source file:com.adito.security.actions.ShowAvailableAccountsDispatchAction.java

/**
 * @param mapping//from www .  java  2s .  c  o  m
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 * @throws Exception
 */
public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    PolicyUtil.checkPermission(PolicyConstants.ACCOUNTS_AND_GROUPS_RESOURCE_TYPE,
            PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, request);
    String[] accounts = request.getParameterValues("username");
    if (accounts == null || accounts.length != 1) {
        ActionMessages mesgs = new ActionMessages();
        mesgs.add(Globals.ERROR_KEY, new ActionMessage("availableAccounts.singleAccountNotSelected"));
        saveErrors(request, mesgs);
        return list(mapping, form, request, response);
    } else {
        return mapping.findForward("edit");
    }
}

From source file:com.globalsight.dispatcher.controller.MTProfilesController.java

private void setExtendInfo(HttpServletRequest p_request, MachineTranslationProfile mtProfile) {
    String[] dirNames = p_request.getParameterValues("dirName");
    if (dirNames == null || dirNames.length == 0)
        return;/*from www . j  ava2s . c  om*/
    Set<MachineTranslationExtentInfo> exInfo = mtProfile.getExInfo();
    if (exInfo == null || exInfo.size() < dirNames.length) {
        exInfo = exInfo == null ? new HashSet<MachineTranslationExtentInfo>() : exInfo;
        for (int i = exInfo.size(); i < dirNames.length; i++) {
            exInfo.add(new MachineTranslationExtentInfo());
        }
        mtProfile.setExInfo(exInfo);
    }

    Iterator<MachineTranslationExtentInfo> it = exInfo.iterator();
    int i = 0;
    while (it.hasNext()) {
        MachineTranslationExtentInfo mtExtentInfo = it.next();
        String[] key = dirNames[i].split("@");
        mtExtentInfo.setSelfInfo(key);
        mtExtentInfo.setMtProfile(mtProfile);
        i++;
    }
}

From source file:fr.paris.lutece.plugins.directory.modules.rest.service.DirectoryRestService.java

/**
 * {@inheritDoc}//from w  w w .  j ava  2  s.c o  m
 */
@Override
public List<Integer> getIdsEntry(int nIdDirectory, HttpServletRequest request) {
    List<Integer> listIdsEntry = new ArrayList<Integer>();
    String[] strIdsEntry = request.getParameterValues(DirectoryRestConstants.PARAMETER_ID_ENTRY_FILTER);

    if (strIdsEntry != null) {
        Plugin pluginDirectory = PluginService.getPlugin(DirectoryPlugin.PLUGIN_NAME);

        for (String strIdEntry : strIdsEntry) {
            if (StringUtils.isNotBlank(strIdEntry) && StringUtils.isNumeric(strIdEntry)) {
                // Check if the entry in the parameter is indeed from the directory
                int nIdEntry = Integer.parseInt(strIdEntry);
                IEntry entry = EntryHome.findByPrimaryKey(nIdEntry, pluginDirectory);

                if ((entry != null) && (entry.getDirectory() != null)
                        && (entry.getDirectory().getIdDirectory() == nIdDirectory)) {
                    listIdsEntry.add(nIdEntry);
                }
            }
        }
    } else {
        listIdsEntry = getIdsEntry(nIdDirectory);
    }

    return listIdsEntry;
}

From source file:com.adito.security.actions.ShowAvailableAccountsDispatchAction.java

/**
 * @param mapping/* w  ww.  j a v a2 s  .c  o m*/
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 * @throws Exception
 */
public ActionForward password(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    PolicyUtil.checkPermission(PolicyConstants.ACCOUNTS_AND_GROUPS_RESOURCE_TYPE,
            PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, request);
    String[] accounts = request.getParameterValues("username");
    if (accounts == null || accounts.length != 1) {
        ActionMessages mesgs = new ActionMessages();
        mesgs.add(Globals.ERROR_KEY, new ActionMessage("availableAccounts.singleAccountNotSelected"));
        saveErrors(request, mesgs);
        return list(mapping, form, request, response);
    } else {
        UserDatabase udb = UserDatabaseManager.getInstance()
                .getUserDatabase(getSessionInfo(request).getUser().getRealm());
        User user = udb.getAccount(accounts[0]);
        request.getSession().setAttribute("setPassword.user", user);
        return mapping.findForward("setPassword");
    }
}

From source file:com.spshop.web.ShoppingController.java

@RequestMapping(value = "/shoppingCart", method = RequestMethod.POST, params = "operation=addItem")
public String shoppingCart2(Model model, HttpServletRequest request, HttpServletResponse response) {
    int qty = retriveQty(request);
    Product product = SCacheFacade.getProduct(retriveProductId(request));

    String[] relatedProducts = request.getParameterValues("relatedProduct");

    List<UserOption> options = retriveUserOptions(request);
    if (null != product) {
        getUserView().getCart().addItem(product, options, qty);

        if (null != relatedProducts) {
            for (String pid : relatedProducts) {
                Product p = SCacheFacade.getProduct(pid);
                if (null != p) {
                    getUserView().getCart().addItem(p, new ArrayList<UserOption>(), 1);
                }//from   w ww  .  j a va2s  . com
            }
        }

        persistantCart();
    }

    return "shoppingCart";
}

From source file:org.openmrs.web.controller.report.CohortReportFormController.java

/**
 * Handles parameters and rows, since Spring isn't good with lists
 * /* w  w w. j a  va 2 s .  c  o m*/
 * @see org.springframework.web.servlet.mvc.BaseCommandController#onBind(javax.servlet.http.HttpServletRequest,
 *      java.lang.Object, org.springframework.validation.BindException)
 */
@Override
protected void onBind(HttpServletRequest request, Object commandObj, BindException errors) throws Exception {
    CommandObject command = (CommandObject) commandObj;

    // parameters
    String[] paramNames = request.getParameterValues("parameterName");
    String[] paramLabels = request.getParameterValues("parameterLabel");
    String[] paramClasses = request.getParameterValues("parameterClass");
    List<Parameter> params = new ArrayList<Parameter>();
    if (paramNames != null) {
        for (int i = 0; i < paramNames.length; ++i) {
            if (StringUtils.hasText(paramNames[i]) || StringUtils.hasText(paramLabels[i])
                    || StringUtils.hasText(paramClasses[i])) {
                try {
                    Class<?> clz = null;
                    if (StringUtils.hasText(paramClasses[i]))
                        clz = Class.forName(paramClasses[i]);
                    Parameter p = new Parameter(paramNames[i], paramLabels[i], clz, null);
                    params.add(p);
                } catch (Exception ex) {
                    errors.rejectValue("parameters", null, "Parameter error: " + ex.toString());
                }
            }
        }
    }
    command.setParameters(params);

    // rows
    String[] rowNames = request.getParameterValues("rowName");
    String[] rowDescriptions = request.getParameterValues("rowDescription");
    String[] rowQueries = request.getParameterValues("rowQuery");
    List<CohortReportRow> rows = new ArrayList<CohortReportRow>();
    if (rowNames != null) {
        for (int i = 0; i < rowNames.length; ++i) {
            try {
                CohortReportRow row = new CohortReportRow();
                row.setName(rowNames[i]);
                row.setDescription(rowDescriptions[i]);
                row.setQuery(rowQueries[i]);
                rows.add(row);
            } catch (Exception ex) {
                errors.rejectValue("rows", null, "Row error: " + ex.toString());
            }
        }
    }
    command.setRows(rows);
}