Working on percentageEditor.
Still having problems with combination of @Max / @Digits / @Column(length=xxx)
This commit is contained in:
@@ -17,7 +17,7 @@ pattern=Muster
|
|||||||
brand=Marke
|
brand=Marke
|
||||||
condition=Zustand
|
condition=Zustand
|
||||||
size=Gr<EFBFBD><EFBFBD>e
|
size=Gr<EFBFBD><EFBFBD>e
|
||||||
discountedSellPrice=Preis nach Rabatt
|
discountedSellPrice=Preisvorschlag
|
||||||
|
|
||||||
articleCount=Anzahl Artikel
|
articleCount=Anzahl Artikel
|
||||||
originalPriceSum=Summe Originalpreise
|
originalPriceSum=Summe Originalpreise
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,7 +25,7 @@ import javax.validation.constraints.*;
|
|||||||
"#buyDate, sellDate];" +
|
"#buyDate, sellDate];" +
|
||||||
"remarks"
|
"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 {
|
public class Article {
|
||||||
|
|
||||||
@Id @Hidden @GeneratedValue(generator="system-uuid2")
|
@Id @Hidden @GeneratedValue(generator="system-uuid2")
|
||||||
@@ -89,6 +89,9 @@ public class Article {
|
|||||||
private LocalDate sellDate;
|
private LocalDate sellDate;
|
||||||
|
|
||||||
@Digits(integer=3, fraction = 0)
|
@Digits(integer=3, fraction = 0)
|
||||||
|
//@Max(value=100)
|
||||||
|
//@Stereotype("PERCENTAGE")
|
||||||
|
//@Column(length=11)
|
||||||
private BigDecimal discount;
|
private BigDecimal discount;
|
||||||
|
|
||||||
public String getOid() {
|
public String getOid() {
|
||||||
@@ -211,8 +214,9 @@ public class Article {
|
|||||||
this.discount = discount;
|
this.discount = discount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Column(length=8)
|
|
||||||
@Stereotype("MONEY")
|
@Stereotype("MONEY")
|
||||||
|
@Calculation("(100 - discount) / 100 * originalPrice")
|
||||||
|
@Column(length=8)
|
||||||
public BigDecimal getDiscountedSellPrice() {
|
public BigDecimal getDiscountedSellPrice() {
|
||||||
try {
|
try {
|
||||||
return getOriginalPrice().multiply(BigDecimal.ONE.subtract(getDiscount().divide(new BigDecimal(100), 2, RoundingMode.HALF_EVEN)));
|
return getOriginalPrice().multiply(BigDecimal.ONE.subtract(getDiscount().divide(new BigDecimal(100), 2, RoundingMode.HALF_EVEN)));
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.hibernate.annotations.GenericGenerator;
|
|||||||
import org.openxava.annotations.*;
|
import org.openxava.annotations.*;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@Tab(properties="number, description, defaultDiscount")
|
||||||
public class Condition {
|
public class Condition {
|
||||||
@Id
|
@Id
|
||||||
@Hidden
|
@Hidden
|
||||||
@@ -23,9 +24,10 @@ public class Condition {
|
|||||||
@Column(length=32)
|
@Column(length=32)
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@Column(length=8)
|
//@Column(length=8)
|
||||||
@Max(value=100)
|
//@Max(value=100)
|
||||||
@Digits(integer=3, fraction=0)
|
@Digits(integer=3, fraction=0)
|
||||||
|
@Stereotype("PERCENTAGE")
|
||||||
private BigDecimal defaultDiscount;
|
private BigDecimal defaultDiscount;
|
||||||
|
|
||||||
public String getOid() {
|
public String getOid() {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.yourcompany.babydatenbank.model;
|
package com.yourcompany.babydatenbank.model;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import org.openxava.annotations.*;
|
import org.openxava.annotations.*;
|
||||||
import org.hibernate.annotations.GenericGenerator;
|
import org.hibernate.annotations.GenericGenerator;
|
||||||
@@ -17,6 +19,10 @@ public class Size {
|
|||||||
@Column(length=20, unique=true)
|
@Column(length=20, unique=true)
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy="size")
|
||||||
|
@ListProperties("name, brand.description, category.description, size.description, condition.description")
|
||||||
|
private Collection<Article> articles;
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
@@ -33,5 +39,16 @@ public class Size {
|
|||||||
this.oid = oid;
|
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.
6
web/xava/editors/percentageEditor.jsp
Normal file
6
web/xava/editors/percentageEditor.jsp
Normal 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
10
xava/editors.xml
Normal 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>
|
||||||
Reference in New Issue
Block a user