【问题标题】:flowScope variable isn't accessible in jspxflowScope 变量在 jspx 中不可访问
【发布时间】:2014-05-09 08:25:46
【问题描述】:

我有 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} 它让我得到空指针异常。 另外,当我调试时,我看到当我调用 nextCard - 这是 ObjectID1 , 但是当我调用 getQuestion - 这是 ObjectID2。

jspx中如何访问流变量?

【问题讨论】:

    标签: spring spring-webflow jspx


    【解决方案1】:

    我通过改变方法来解决它:

    <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"/>
    

    空指针也面临同样的问题

    【讨论】:

      【解决方案2】:

      您需要使用 flowscope 变量指定模型属性来保存视图的表单字段。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-02-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-15
        相关资源
        最近更新 更多