Working on percentageEditor.

Still having problems with combination of @Max / @Digits /
@Column(length=xxx)
This commit is contained in:
Socrates
2020-06-10 11:22:24 +02:00
parent 224ce9d2a4
commit 905519266b
8 changed files with 74 additions and 7 deletions

View File

@@ -17,7 +17,7 @@ pattern=Muster
brand=Marke
condition=Zustand
size=Gr<EFBFBD><EFBFBD>e
discountedSellPrice=Preis nach Rabatt
discountedSellPrice=Preisvorschlag
articleCount=Anzahl Artikel
originalPriceSum=Summe Originalpreise

View File

@@ -0,0 +1,28 @@
package com.yourcompany.babydatenbank.formatters;
import java.math.*;
import javax.servlet.http.*;
import org.openxava.formatters.*;
import org.openxava.model.meta.*;
import org.openxava.util.*;
/**
* For MONEY and DINERO stereotypes. <p>
*
* @author Javier Paniza
*/
public class PercentageFormatter implements IMetaPropertyFormatter {
public String format(HttpServletRequest request, MetaProperty metaProperty, Object object) throws Exception {
if (object == null) return "";
return object.toString();
}
public Object parse(HttpServletRequest request, MetaProperty metaProperty, String string) throws Exception {
if (Is.emptyString(string)) return null;
return new BigDecimal(string).setScale(0);
}
}

View File

@@ -25,7 +25,7 @@ import javax.validation.constraints.*;
"#buyDate, sellDate];" +
"remarks"
)
@Tab(properties="name, photo, category.description, brand.description, pattern.description, size.description, condition.description, remarks", defaultOrder="${name} asc")
@Tab(properties="name, category.description, brand.description, pattern.description, size.description, condition.description, discountedSellPrice, remarks", defaultOrder="${name} asc")
public class Article {
@Id @Hidden @GeneratedValue(generator="system-uuid2")
@@ -89,8 +89,11 @@ public class Article {
private LocalDate sellDate;
@Digits(integer=3, fraction = 0)
//@Max(value=100)
//@Stereotype("PERCENTAGE")
//@Column(length=11)
private BigDecimal discount;
public String getOid() {
return oid;
}
@@ -211,8 +214,9 @@ public class Article {
this.discount = discount;
}
@Column(length=8)
@Stereotype("MONEY")
@Calculation("(100 - discount) / 100 * originalPrice")
@Column(length=8)
public BigDecimal getDiscountedSellPrice() {
try {
return getOriginalPrice().multiply(BigDecimal.ONE.subtract(getDiscount().divide(new BigDecimal(100), 2, RoundingMode.HALF_EVEN)));
@@ -221,5 +225,5 @@ public class Article {
return BigDecimal.ZERO;
}
}
}
}

View File

@@ -9,6 +9,7 @@ import org.hibernate.annotations.GenericGenerator;
import org.openxava.annotations.*;
@Entity
@Tab(properties="number, description, defaultDiscount")
public class Condition {
@Id
@Hidden
@@ -23,9 +24,10 @@ public class Condition {
@Column(length=32)
private String description;
@Column(length=8)
@Max(value=100)
//@Column(length=8)
//@Max(value=100)
@Digits(integer=3, fraction=0)
@Stereotype("PERCENTAGE")
private BigDecimal defaultDiscount;
public String getOid() {

View File

@@ -1,5 +1,7 @@
package com.yourcompany.babydatenbank.model;
import java.util.*;
import javax.persistence.*;
import org.openxava.annotations.*;
import org.hibernate.annotations.GenericGenerator;
@@ -16,6 +18,10 @@ public class Size {
@Column(length=20, unique=true)
private String description;
@OneToMany(mappedBy="size")
@ListProperties("name, brand.description, category.description, size.description, condition.description")
private Collection<Article> articles;
public String getDescription() {
return description;
@@ -33,5 +39,16 @@ public class Size {
this.oid = oid;
}
public Collection<Article> getArticles() {
return articles;
}
public void setArticles(Collection<Article> articles) {
this.articles = articles;
}
public int getArticleCount() {
return this.articles.size();
}
}

Binary file not shown.

View File

@@ -0,0 +1,6 @@
<jsp:useBean id="style" class="org.openxava.web.style.Style" scope="request"/>
<span class="<%=style.getMoney()%>">
<b>%</b>
<jsp:include page="textEditor.jsp"/>
</span>

10
xava/editors.xml Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE editors SYSTEM "dtds/editors.dtd">
<editors>
<editor name="PercentageTextField" url="percentageEditor.jsp">
<for-stereotype stereotype="PERCENTAGE" />
<formatter class="com.yourcompany.babydatenbank.formatters.PercentageFormatter" />
</editor>
</editors>