我的代码:

Categories-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


CategoryData.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也会发生同样的情况。这里怎么了,我不知道!

最佳答案

您必须在Bean名称前加上字符@

<evaluate expression="@categoryFacade.getCategories()"


这样就可以了。

关于java - Spring Webflow org.springframework.expression.spel.SpelEvaluationException:EL1009E-不能设置为null,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16296081/

10-09 03:26