📄 helloworldhome.java
字号:
package com.ttdev.helloworld;
import java.util.Date;
import java.util.List;
import org.apache.hivemind.util.PropertyUtils;
import org.apache.tapestry.IPage;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.annotations.Bean;
import org.apache.tapestry.annotations.InitialValue;
import org.apache.tapestry.annotations.InjectPage;
import org.apache.tapestry.form.IPropertySelectionModel;
import org.apache.tapestry.form.StringPropertySelectionModel;
import org.apache.tapestry.html.BasePage;
import org.apache.tapestry.valid.ValidationConstraint;
import org.apache.tapestry.valid.ValidationDelegate;
import com.ttdev.eshop.Catalog;
import com.ttdev.eshop.ProductDetails;
public abstract class HelloworldHome extends BasePage {
@Bean
public abstract ValidationDelegate getDelegate();
@InjectPage("Result")
abstract public Result getResultPage();
public String getGreetingSubject() {
return "John";
}
@InitialValue("literal:MSFT")
abstract public String getStockId();
abstract public Date getQuoteDate();
public IPropertySelectionModel getAvailStockIds() {
return new StringPropertySelectionModel(new String[] { "IBM", "MSFT",
"RHAT" });
}
public IPage onOk(IRequestCycle cycle) {
int stockValue = (getStockId() + getQuoteDate().toString()).hashCode() % 100;
Result resultPage = getResultPage();
resultPage.setStockValue(stockValue);
return resultPage;
}
private KnownPatrons knownPatrons;
@InjectPage("Result1")
public abstract IPage getResult1();
public abstract int getWeight();
public abstract String getPatronCode();
public abstract Date getShippingDate();
public abstract String getDesc();
public HelloworldHome() {
knownPatrons = new KnownPatrons();
}
public KnownPatrons getKnownPatrons() {
return knownPatrons;
}
public IPage onSubmit() {
ValidationDelegate delegate = getDelegate();
int 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 = weight * postagePerKg;
if (discount != null) {
postage = postage * discount.intValue() / 100;
}
IPage resultPage = getResult1();
PropertyUtils.write(resultPage, "postage", new Integer(postage));
return resultPage;
}
public List getProducts() {
return Catalog.getGlobalCatalog().getProducts();
}
@InjectPage("ProductDetails")
public abstract ProductDetails getDetailsPage();
public ProductDetails onClickDetailsLink(String productId) {
getDetailsPage().setProductId(productId);
return getDetailsPage();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -