Example usage for org.springframework.web.bind ServletRequestUtils getBooleanParameter

List of usage examples for org.springframework.web.bind ServletRequestUtils getBooleanParameter

Introduction

In this page you can find the example usage for org.springframework.web.bind ServletRequestUtils getBooleanParameter.

Prototype

@Nullable
public static Boolean getBooleanParameter(ServletRequest request, String name)
        throws ServletRequestBindingException 

Source Link

Document

Get a Boolean parameter, or null if not present.

Usage

From source file:org.openmrs.module.feedback.web.AddSeverityFormController.java

@Override
protected Map referenceData(HttpServletRequest req) throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    FeedbackService hService = (FeedbackService) Context.getService(FeedbackService.class);

    /* To list all the severites on the add severity page */
    map.put("severities", hService.getSeverities());

    /* TO update the status that the severity has been successfully saved */
    if ((req.getParameter("feedbackPageMessage") != null)
            && ServletRequestUtils.getBooleanParameter(req, "feedbackPageMessage")) {
        map.put("feedbackPageMessage", "feedback.notification.severity.added");
    } else {//from   w  ww  .  jav  a  2 s.c om
        map.put("feedbackPageMessage", "");
    }

    return map;
}

From source file:org.tsm.concharto.web.eventsearch.SearchHelper.java

/**
 * Populate the form with params from the URL query string
 * @param request servlet request/*from  w  w w  .  j  a v  a  2s .c  o m*/
 * @param eventSearchForm the form to populate
 * @throws ServletRequestBindingException e
 * @throws UnsupportedEncodingException 
 */
public void bindGetParameters(HttpServletRequest request, EventSearchForm eventSearchForm)
        throws ServletRequestBindingException {
    eventSearchForm.setWhere(ServletRequestUtils.getStringParameter(request, QUERY_WHERE));
    String whenStr = ServletRequestUtils.getStringParameter(request, QUERY_WHEN);
    try {
        eventSearchForm.setWhen(TimeRangeFormat.parse(whenStr));
    } catch (ParseException e) {
        //no error handling for URL string searches  TODO add error handling
    }
    eventSearchForm.setWhat(ServletRequestUtils.getStringParameter(request, QUERY_WHAT));
    Integer zoom = ServletRequestUtils.getIntParameter(request, QUERY_ZOOM);
    //check for incorrect zoom
    if ((zoom != null) && (zoom > 0) && (zoom < SensibleMapDefaults.NUM_ZOOM_LEVELS)) {
        eventSearchForm.setMapZoom(zoom);
        eventSearchForm.setZoomOverride(true);
    }
    //TSM-257 problem with googlebot.  This is a kludge.  It is difficult to figure out
    //why google isn't following the maptype
    String mapType = request.getParameter(QUERY_MAPTYPE);
    try {
        eventSearchForm.setMapType(new Integer(mapType));
    } catch (NumberFormatException e) {
        eventSearchForm.setMapType(SensibleMapDefaults.DEFAULT_MAP_TYPE);
    }
    eventSearchForm.setUserTag(getUtf8QueryStringParameter(request, QUERY_USERTAG));
    eventSearchForm.setLimitWithinMapBounds(
            (ServletRequestUtils.getBooleanParameter(request, QUERY_WITHIN_MAP_BOUNDS)));
    eventSearchForm.setExcludeTimeRangeOverlaps(
            (ServletRequestUtils.getBooleanParameter(request, QUERY_EXCLUDE_TIMERANGE_OVERLAPS)));
    eventSearchForm.setEmbed((ServletRequestUtils.getBooleanParameter(request, QUERY_EMBED)));
    eventSearchForm.setKml((ServletRequestUtils.getBooleanParameter(request, QUERY_KML)));
    Long eventId = ServletRequestUtils.getLongParameter(request, QUERY_ID);
    if (null != eventId) {
        eventSearchForm.setDisplayEventId(eventId);
    }
    Point ll = getLatLng(request, QUERY_LAT_LNG);
    if (null != ll) {
        eventSearchForm.setMapCenter(ll);
        //tells the javascript client side code not to "fit" the map to the search results
        eventSearchForm.setMapCenterOverride(true);
    }
    eventSearchForm.setBoundingBoxNE(getLatLng(request, QUERY_NE));
    eventSearchForm.setBoundingBoxSW(getLatLng(request, QUERY_SW));

    WebUtils.setSessionAttribute(request, SESSION_DO_SEARCH_ON_SHOW, true);
}

From source file:org.openmrs.module.webservices.rest.web.RestUtil.java

/**
 * Convenience method to get the given param out of the given request as a boolean.
 * //from   w  w w  .java2s .c o m
 * @param request the WebRequest to look in
 * @param param the string name to fetch
 * @return <code>true</code> if the param is equal to 'true', <code>false</code> for any empty
 *         value, null value, or not equal to 'true', or missing param.
 * @should return true only if request param is 'true'
 */
public static Boolean getBooleanParam(HttpServletRequest request, String param) {
    try {
        return ServletRequestUtils.getBooleanParameter(request, param);
    } catch (ServletRequestBindingException e) {
        return false;
    }
}