📄 productcategorybaseaction.java
字号:
package com.bluesky.elecall.web.struts.action;
import java.util.ArrayList;
import java.util.List;
import com.bluesky.elecall.domain.CategoryItem;
import com.bluesky.elecall.web.Link;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.interceptor.PreResultListener;
public class ProductCategoryBaseAction extends BaseAction implements Preparable,PreResultListener{
/*
* if in search mode, keywords is not empty
*/
protected String keywords;
/*
* current selected category item id, input via GET URL
*/
protected long categoryItemId;
/*
* for menu data
*/
protected CategoryItem rootCategoryItem;
/*
* current selected category item
*/
protected CategoryItem categoryItem;
/*
* selected leve1 1 item.
*/
protected CategoryItem selectedBookItem;
/*
* sometimes, selectedCategoryItem != currentCategoryItem, when the level3
* item is selected, its parent item is the 'currentCategoryItem'
*/
protected CategoryItem currentCategoryItem;
/*
* category path, from root -> ..., -> current selected category item
*/
protected List<Link> categoryPath = new ArrayList();
public void prepare() throws Exception {
// load menu data
rootCategoryItem = productCategory.getRootCategoryItem(2);
}
public void beforeResult(ActionInvocation arg0, String arg1) {
if(categoryItem==null)
categoryItem = productCategory.getCategoryItem(categoryItemId);
if (currentCategoryItem == null)
currentCategoryItem = categoryItem;//by default
// load the category path
if (currentCategoryItem != null) {
CategoryItem item = currentCategoryItem;
while(item.getLevel() > 1){
CategoryItem parentItem = productCategory.getParentCategoryItem(item);
String url;
String name;
if (item.getLevel() == 3)
{
url = String.format("categoryItemId=%d#%s", parentItem.getId(),item.getName());
name = item.getName();
}
else
{
url = String.format("categoryItemId=%d", item.getId());
name = item.getName();
}
Link link = new Link(url,name);
categoryPath.add(0, link);
item = parentItem;
}
selectedBookItem = item;
}
}
public String getKeywords() {
return keywords;
}
public void setKeywords(String keywords) {
this.keywords = keywords;
}
public CategoryItem getRootCategoryItem() {
return rootCategoryItem;
}
public void setRootCategoryItem(CategoryItem rootCategoryItem) {
this.rootCategoryItem = rootCategoryItem;
}
public CategoryItem getCategoryItem() {
return categoryItem;
}
public void setCategoryItem(CategoryItem categoryItem) {
this.categoryItem = categoryItem;
}
public CategoryItem getSelectedBookItem() {
return selectedBookItem;
}
public void setSelectedBookItem(CategoryItem selectedBookItem) {
this.selectedBookItem = selectedBookItem;
}
public CategoryItem getCurrentCategoryItem() {
return currentCategoryItem;
}
public void setCurrentCategoryItem(CategoryItem currentCategoryItem) {
this.currentCategoryItem = currentCategoryItem;
}
public List getCategoryPath() {
return categoryPath;
}
public void setCategoryPath(List categoryPath) {
this.categoryPath = categoryPath;
}
public long getCategoryItemId() {
return categoryItemId;
}
public void setCategoryItemId(long categoryItemId) {
this.categoryItemId = categoryItemId;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -