📄 home.java
字号:
package com.ttdev.postage;
import java.util.*;
import org.apache.hivemind.util.*;
import org.apache.tapestry.*;
import org.apache.tapestry.annotations.*;
import org.apache.tapestry.html.*;
import org.apache.tapestry.valid.*;
public abstract class Home extends BasePage {
private KnownPatrons knownPatrons;
@InjectPage("Result")
public abstract IPage getResult();
public abstract double getWeight();
public abstract String getPatronCode();
@Bean
public abstract ValidationDelegate getDelegate();
public Home() {
knownPatrons = new KnownPatrons();
}
public KnownPatrons getKnownPatrons() {
return knownPatrons;
}
public abstract Date getShippingDate();
public abstract String getDesc();
public IPage onSubmit() {
System.out.println(getShippingDate());
System.out.println(getDesc());
ValidationDelegate delegate = getDelegate();
double weight = getWeight();
Integer discount = knownPatrons.getDiscount(getPatronCode());
if (getPatronCode() != null && getPatronCode().equals("p1") && weight > 50) {
delegate.setFormComponent(null);
delegate.record("Can't ship 50kg or more for p1", ValidationConstraint.CONSISTENCY);
}
if (delegate.getHasErrors()) {
return null;
}
int postagePerKg = 10;
int postage = (int) (weight * postagePerKg);
if (discount != null) {
postage = postage * discount.intValue() / 100;
}
IPage resultPage = getResult();
PropertyUtils.write(resultPage, "postage", new Integer(postage));
return resultPage;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -