我有cardQuestion.jspx
<html xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:form="http://www.springframework.org/tags/form" contenteditable="inherit">
<jsp:output omit-xml-declaration="yes" />
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<head>
<title>SS</title>
</head>
<body>
<label>${wordingPractice.question}</label>
</body>
</html>
我有流声明wording-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="wordingPractice" class="Practice.WordingPractice"/>
<view-state id="wording">
<transition on="next" to="setTranslationDirection"/>
<transition on="cancel" to="endState"/>
</view-state>
<action-state id="setTranslationDirection">
<evaluate expression="wordingPractice.translationDirection = requestParameters.translationDirection"/>
<transition to="setSaver"/>
</action-state>
<action-state id="setSaver">
<evaluate expression="wordingPractice.saver = saverExtension"/>
<transition to="nextCard"/>
</action-state>
<action-state id="nextCard">
<evaluate expression="wordingPractice.nextCard()"/>
<transition to="cardQuestion"/>
</action-state>
<view-state id="cardQuestion">
<transition on="cancel" to="endState"/>
</view-state>
<end-state id="endState" />
</flow>
在方法nextCard中 - 我初始化问题变量。 但是当我在jspx中调用它时:$ {wordingPractice.question} 它让我得到Null指针异常。 另外,当我调试时,我看到当我调用nextCard时 - 这是ObjectID1, 但是当我调用getQuestion时 - 这是ObjectID2。
如何在jspx中访问流变量?
答案 0 :(得分:0)
我通过改变方法来解决它:
<view-state id="cardQuestion">
<on-entry>
<evaluate result="viewScope.questionValue" expression="wordingPractice.question"/>
</on-entry>
<transition on="cancel" to="endState"/>
</view-state>
和jspx
<label>${questionValue}</label>
但如果有人知道如何在viewScope中使用对象 - 欢迎回答!
当我尝试做同样的事情时:
<evaluate result="viewScope.wordingPractice" expression="wordingPractice"/>
我遇到与空指针相同的问题
答案 1 :(得分:0)
您需要使用包含视图表单字段的流动变量变量指定模型属性。
<view-state id="wording" model="wordingPractice">
<transition on="next" to="setTranslationDirection"/>
<transition on="cancel" to="endState"/>
</view-state>
<view-state id="cardQuestion" model="wordingPractice">
<transition on="cancel" to="endState"/>
</view-state>