From 99bb6714373a4b6f877a53dec1f52b1ac26b75b9 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Mon, 28 Nov 2016 17:03:48 +0100 Subject: [PATCH] WW-4721 Enables rounding mode --- .../org/apache/struts2/components/Number.java | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/components/Number.java b/core/src/main/java/org/apache/struts2/components/Number.java index a52bff228..7ca45b14c 100644 --- a/core/src/main/java/org/apache/struts2/components/Number.java +++ b/core/src/main/java/org/apache/struts2/components/Number.java @@ -1,11 +1,4 @@ -/** - * - */ -package org.apache.struts2.components; - /* - * $Id$ - * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information @@ -23,6 +16,7 @@ package org.apache.struts2.components; * specific language governing permissions and limitations * under the License. */ +package org.apache.struts2.components; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.util.ValueStack; @@ -33,6 +27,7 @@ import org.apache.struts2.views.annotations.StrutsTagAttribute; import java.io.IOException; import java.io.Writer; +import java.math.RoundingMode; import java.text.NumberFormat; import java.util.Currency; @@ -154,16 +149,14 @@ public class Number extends ContextBean { setRoundingMode(format); String msg = format.format(number); - if (msg != null) { - try { - if (getVar() == null) { - writer.write(msg); - } else { - putInContext(msg); - } - } catch (IOException e) { - LOG.error("Could not write out Number tag", e); + try { + if (getVar() == null) { + writer.write(msg); + } else { + putInContext(msg); } + } catch (IOException e) { + LOG.error("Could not write out Number tag", e); } } return super.end(writer, ""); @@ -221,8 +214,6 @@ public class Number extends ContextBean { } private void setRoundingMode(NumberFormat format) { - /* - TODO lukaszlenart: enable when switched to Java 1.6 if (roundingMode != null) { roundingMode = findString(roundingMode); if ("ceiling".equals(roundingMode)) { @@ -245,7 +236,6 @@ public class Number extends ContextBean { LOG.error("Could not recognise a roundingMode of [" + roundingMode + "]"); } } - */ } private NumberFormat getNumberFormat() { @@ -275,12 +265,12 @@ public class Number extends ContextBean { return format; } - @StrutsTagAttribute(description = "Type of number formatter (currency, integer, number or percent, default is number)", rtexprvalue = false) + @StrutsTagAttribute(description = "Type of number formatter (currency, integer, number or percent, default is number)") public void setType(String type) { this.type = type; } - @StrutsTagAttribute(description = "The currency to use for a currency format", type = "String", defaultValue = "") + @StrutsTagAttribute(description = "The currency to use for a currency format") public void setCurrency(String currency) { this.currency = currency; } @@ -408,7 +398,7 @@ public class Number extends ContextBean { /** * @param roundingMode the roundingMode to set */ - @StrutsTagAttribute(description = "The rounding mode to use - not implemented yet as this required Java 1.6", type = "String") + @StrutsTagAttribute(description = "The rounding mode to use, possible values: ceiling, down, floor, half-down, half-even, half-up, unnecessary, up") public void setRoundingMode(String roundingMode) { this.roundingMode = roundingMode; }