我的代码:
类别-flow.xml
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<var name="flowScope.categories" class="events.ui.web.adminweb.flow.CategoryFormBackingObject"/>
<view-state id="categoryOverview" model="categories" view="categoryOverview.jsp">
<on-entry>
<evaluate expression="categoryFacade.getCategories()" result="flowScope.categories.categories"/>
</on-entry>
<transition on="new" to="newCategory" />
<transition on="edit" to="editCategory">
<evaluate expression="categoryFacade.getCategoryById(requestParameters.cid)" result="flowScope.categories.editableCategory" />
</transition>
<transition on="delete" to="deleteCategory">
<evaluate expression="categoryFacade.getCategoryById(requestParameters.cid)" result="flowScope.categories.editableCategory" />
</transition>
</view-state>
[...]
DefaultCategoryFacade.java
@Component("categoryFacade")
public class DefaultCategoryFacade implements CategoryFacade {
@Resource
private CategoryService categoryService;
@Resource
private CategoryConverter categoryConverter;
@Override
public Collection<CategoryData> getCategories() {
return categoryConverter.convertAll(categoryService.getCategories());
}
@Override
public CategoryData getCategoryById(int id) {
return categoryConverter.convert(categoryService.getCategoryById(id));
}
}
CategoryFormBackingObject.java
public class CategoryFormBackingObject implements Serializable {
private static final long serialVersionUID = -8237671561218547425L;
private List<CategoryData> categories = new ArrayList<CategoryData>();
private CategoryData editableCategory = new CategoryData();
//With getters and setters
分类数据.java
public class CategoryData implements Serializable {
private static final long serialVersionUID = 2706910537987564159L;
private int id;
private String name;
// With getters and setters
这是我的例外:
Servlet.service() for servlet [adminweb] in context with path [/adminweb] threw exception [Request processing failed; nested exception is org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@37c390b8 targetAction = [EvaluateAction@8523ca2 expression = categoryFacade.getCategories(), resultExpression = flowScope.categories.categories], attributes = map[[empty]]] in state 'categoryOverview' of flow 'categories' -- action execution attributes were 'map[[empty]]'] with root cause
org.springframework.expression.spel.SpelEvaluationException: EL1009E:(pos 21): Field or property 'categories' cannot be set on null
“新”视图状态中的 flowScope.categories.editableCategory 也会发生同样的情况。这里有什么问题,我不知道!