Permalink
Browse files

aceitando JodaTime

  • Loading branch information...
brunoadacosta committed Mar 10, 2011
1 parent 6ef8d0f commit 17befa5fd1a418351c19af3fb7b6b3e7696aa80b
View
@@ -7,5 +7,6 @@
<classpathentry kind="lib" path="gson-1.5.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="mirror-1.5.1.jar"/>
+ <classpathentry kind="lib" path="joda-time-1.6.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
View
Binary file not shown.
@@ -16,7 +16,7 @@
private int page = 1;
private transient int pagesize;
private long records;
- private int currentRecords;
+ private transient int currentRecords;
private transient int itensPerPage = 10;
private final List<EasyGridRow> rows = new ArrayList<EasyGridRow>();
@@ -13,6 +13,10 @@
import net.vidageek.mirror.dsl.Mirror;
+import org.joda.time.base.BaseLocal;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+
/**
* Class responsible for building the EasyGridAjaxObject to Json or XML
* serialization used in EasyGrid
@@ -88,6 +92,15 @@ public EasyGridObject create() {
return result;
}
+ public EasyGridObject empty() {
+ EasyGridRow row = new EasyGridRow();
+
+ result.addRow(row);
+ result.setRecords(0);
+
+ return result;
+ }
+
/**
* Method that informs column for serialization
*
@@ -197,7 +210,13 @@ private String getValue(Method method, Object obj) {
if (result == null) {
return "";
}
+
if (patternDate.containsKey(method.getName())) {
+ if (result instanceof BaseLocal) {
+ DateTimeFormatter formatter = DateTimeFormat.forPattern(patternDate.get(method.getName()));
+ BaseLocal baseDate = (BaseLocal) result;
+ return baseDate.toString(formatter);
+ }
return new SimpleDateFormat(patternDate.get(method.getName())).format(result);
}
if (patternCurrency.containsKey(method.getName())) {
@@ -51,4 +51,5 @@ public void setId(Long id) {
public Long getId() {
return id;
}
+
}
@@ -6,9 +6,12 @@
import java.util.List;
import java.util.Locale;
+import org.joda.time.LocalDate;
+
import com.cocento.commons.ajax.easygrid.EasyGridObject;
import com.cocento.commons.ajax.easygrid.EasyGridObjectBuilder;
import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
public class Main {
@@ -39,6 +42,7 @@ public static void main(String[] args) {
obj.setPrice(new BigDecimal("999.99"));
obj.setPrice2(999.99);
obj.setClassA(classA);
+ obj.setDataJoda(new LocalDate().plusDays(1));
ClassB classB1 = new ClassB();
classB1.setId(100L);
@@ -61,18 +65,23 @@ public static void main(String[] args) {
obj2.setPrice(new BigDecimal("5900.99"));
obj2.setPrice2(5900.99);
obj2.setClassA(classA1);
+ obj2.setDataJoda(new LocalDate().plusDays(2));
List<Objeto> lst = new ArrayList<Objeto>(2);
lst.add(obj);
lst.add(obj2);
- EasyGridObject ajaxObject = new EasyGridObjectBuilder<Objeto>(lst, 2L).setColumn("classA.classB.name")
- .setColumn("classA.testString").setColumn("name").setColumn("inteiro").setDateColumn("date", "dd/MM/yyyy")
- .setDateColumn("date2", "dd/MM/yyyy HH:mm").setColumn("longo").setCurrencyColumn("price", new Locale("pt", "BR"))
- .setCurrencyColumn("price2", new Locale("en", "US")).create();
+ EasyGridObject ajaxObject = new EasyGridObjectBuilder<Objeto>(lst, 2L).setDateColumn("dataJoda", "dd/MM/yyyy")
+ .setColumn("classA.classB.name").setColumn("classA.testString").setColumn("name").setColumn("inteiro")
+ .setDateColumn("date", "dd/MM/yyyy").setDateColumn("date2", "dd/MM/yyyy HH:mm").setColumn("longo")
+ .setCurrencyColumn("price", new Locale("pt", "BR")).setCurrencyColumn("price2", new Locale("en", "US")).create();
+
+ Gson gson = new GsonBuilder().create();
System.out.println(new Gson().toJson(ajaxObject));
+ System.out.println(gson.toJson(new EasyGridObjectBuilder<Objeto>().empty()));
+
}
}
@@ -4,6 +4,8 @@
import java.math.BigDecimal;
import java.util.Date;
+import org.joda.time.LocalDate;
+
public class Objeto implements Serializable {
private static final long serialVersionUID = -582070988424624954L;
@@ -26,6 +28,8 @@
private ClassA classA;
+ private LocalDate dataJoda;
+
public String getName() {
return name;
}
@@ -97,4 +101,12 @@ public void setId(Long id) {
public Long getId() {
return id;
}
+
+ public void setDataJoda(LocalDate dataJoda) {
+ this.dataJoda = dataJoda;
+ }
+
+ public LocalDate getDataJoda() {
+ return dataJoda;
+ }
}
@@ -16,7 +16,7 @@
private static final ClassA a = new ClassA();
private static final ClassB b = new ClassB();
private static final Gson gson = new GsonBuilder().serializeNulls().create();
- private static final String cleanJson = "{\"page\":1,\":0,\"records\":0,\"itensPerPage\":10,\"rows\":[id:\"\", cell[]]}";
+ private static final String cleanJson = "{\"page\":1,\":0,\"records\":0,\"rows\":[id:\"\", cell[]]}";
@BeforeClass
public static void setUpBefore() {

0 comments on commit 17befa5

Please sign in to comment.