From: Marco Zanon Date: Sun, 11 Mar 2012 14:18:00 +0000 (+0000) Subject: Made MWebDateBox and MWebNumberBox also accept Date and BigDecimal values, respectively. X-Git-Tag: SVN-to-Git~148 X-Git-Url: https://gitweb.marcozanon.com/?a=commitdiff_plain;h=5bb4c5959c1f832c63eea08b166a9565c31daa24;p=Macaco Made MWebDateBox and MWebNumberBox also accept Date and BigDecimal values, respectively. --- diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java index fc89489..b9cfb14 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebDateBox.java @@ -8,6 +8,7 @@ package com.marcozanon.macaco.web.ui; import com.marcozanon.macaco.conversion.MDateConverter; import com.marcozanon.macaco.conversion.MFormatConversionException; +import java.util.Date; public class MWebDateBox extends MWebTextBox { @@ -31,6 +32,12 @@ public class MWebDateBox extends MWebTextBox { this.setText(text); } + public MWebDateBox(MWebApplicationContext applicationContext, MDateConverter dateConverter, Date date) { + this(applicationContext, dateConverter); + // + this.setDate(date); + } + /* Date converter */ protected MDateConverter getDateConverterReference() { @@ -41,6 +48,30 @@ public class MWebDateBox extends MWebTextBox { return this.getDateConverterReference().clone(); } + /* Date conversion */ + + public void setDate(Date date) { + if (null == date) { + this.setText(""); + } + else { + try { + this.setText(this.getDateConverterReference().getStringFromDate(date)); + } + catch (MFormatConversionException exception) { // cannot happen + } + } + } + + public Date getDate() throws MFormatConversionException { + Date date = null; + String text = this.getText(); + if (!"".equals(text)) { + return this.getDateConverterReference().getDateFromString(text); + } + return date; + } + /* Validation */ public void validate() throws MValidationWebException { diff --git a/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java b/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java index f8ccf26..958c6a4 100644 --- a/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java +++ b/src/java/com/marcozanon/macaco/web/ui/MWebNumberBox.java @@ -8,6 +8,7 @@ package com.marcozanon.macaco.web.ui; import com.marcozanon.macaco.conversion.MFormatConversionException; import com.marcozanon.macaco.conversion.MNumberConverter; +import java.math.BigDecimal; public class MWebNumberBox extends MWebTextBox { @@ -31,6 +32,12 @@ public class MWebNumberBox extends MWebTextBox { this.setText(text); } + public MWebNumberBox(MWebApplicationContext applicationContext, MNumberConverter numberConverter, BigDecimal number) { + this(applicationContext, numberConverter); + // + this.setNumber(number); + } + /* Number converter */ protected MNumberConverter getNumberConverterReference() { @@ -41,6 +48,30 @@ public class MWebNumberBox extends MWebTextBox { return this.getNumberConverterReference().clone(); } + /* Number conversion */ + + public void setNumber(BigDecimal number) { + if (null == number) { + this.setText(""); + } + else { + try { + this.setText(this.getNumberConverterReference().getStringFromNumber(number)); + } + catch (MFormatConversionException exception) { // cannot happen + } + } + } + + public BigDecimal getNumber() throws MFormatConversionException { + BigDecimal number = null; + String text = this.getText(); + if (!"".equals(text)) { + return this.getNumberConverterReference().getNumberFromString(text); + } + return number; + } + /* Validation */ public void validate() throws MValidationWebException {