I know the ugly way
a>0 ? a : -a
but this is very annoyng when a is a relatively long expression.
OBJ1["x"]-someVar>0 ? OBJ1["x"]-someVar : -(OBJ1["x"]-someVar)
Is there any nicer way of doing it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For plain jsp, you can create a custom EL function which delegates to
Math#abs(int).If you first just create a
/WEB-INF/functions.tldfile which look like follows:Then you’ll be able to use it as follows:
This solution also works for JSF, but if you are using JSF, OmniFaces has simplified this for you by providing its importFunctions (if not already using OmniFaces with JSF, you should start using it)
See also: