Example usage for org.apache.commons.lang BooleanUtils toInteger

List of usage examples for org.apache.commons.lang BooleanUtils toInteger

Introduction

In this page you can find the example usage for org.apache.commons.lang BooleanUtils toInteger.

Prototype

public static int toInteger(Boolean bool, int trueValue, int falseValue, int nullValue) 

Source Link

Document

Converts a Boolean to an int specifying the conversion values.

 BooleanUtils.toInteger(Boolean.TRUE, 1, 0, 2)  = 1 BooleanUtils.toInteger(Boolean.FALSE, 1, 0, 2) = 0 BooleanUtils.toInteger(null, 1, 0, 2)          = 2 

Usage

From source file:com.redhat.rhn.frontend.action.user.UserPrefAction.java

/** {@inheritDoc} */
public ActionForward execute(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
        HttpServletResponse response) {/*from   ww  w.j  a va2 s .  com*/

    DynaActionForm form = (DynaActionForm) formIn;
    RequestContext requestContext = new RequestContext(request);
    StrutsDelegate strutsDelegate = getStrutsDelegate();

    User user = UserManager.lookupUser(requestContext.getCurrentUser(), requestContext.getParamAsLong("uid"));
    request.setAttribute(RhnHelper.TARGET_USER, user);
    if (user == null) {
        user = requestContext.getCurrentUser();
    }

    user.setEmailNotify(BooleanUtils.toInteger((Boolean) form.get("emailNotif"), 1, 0, 0));
    user.setPageSize(getAsInt(form, "pagesize", 5));
    user.setCsvSeparator((Character) form.get("csvSeparator"));

    handlePanes(form, user);

    UserManager.storeUser(user);

    ActionMessages msgs = new ActionMessages();
    msgs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message.preferencesModified"));
    strutsDelegate.saveMessages(request, msgs);

    return strutsDelegate.forwardParam(mapping.findForward("success"), "uid", String.valueOf(user.getId()));
}