2013-10-29 100 views
2

我試圖做到這一點對我流的一個:Spring Webflow:如何將bean從控制器傳遞到流? (使用輸入映射)

<!-- Initial inputs --> 
<input name="profileId" required="true" type="long" /> 
<input name="profile" required="true" type="com.myapp.model.Profile" /> 

冗餘的,我知道。這只是爲了調試目的

這裏的問題是配置文件爲空(com.myapp.model.Profile),由於所需的屬性錯誤引發異常到我的流程處理程序。 但是,profileId(長)不爲空,並且正常工作。

我的問題:

有沒有一種可能性,即類型不能是僅僅只有一個長型? (Here是另一個相關主題)

這裏是我的控制器:

@RequestMapping(value = "/mappingUrl", method = {RequestMethod.POST}) 
public String go2Flow(.... some parameters ..., 
@ModelAttribute("profile") Profile profile, 
ModelMap model) { 

model.put("profile", profile); 
model.put("profileId", profile.getId()); 

return "redirect:/app/myFlow"; 
} 

編輯:

我解決它。由於我在我的Spring MVC控制器上使用@SessionAttributes作爲對象配置文件(名爲'profile'),所以在我的流程中,我只使用ExternalContext API檢索該對象。

因此,控制器保持相同的代碼,但我流的ExternalContext API可用於這樣的:

<on-start> 
    <evaluate expression="someService.serviceMethod(externalContext)" result="flowScope.outputVariable" /> 
</on-start> 

,然後在服務方法:

@Override 
public SomeObject serviceMethod(ExternalContext externalContext) { 

    Profile profile = (Profile) externalContext.getSessionMap().get("profile"); 

     ..... 
    (method logic) 
     ..... 
} 
+0

它的怪異,你包的名字中有一個大寫字母 –

+0

對此深感抱歉。這不是真正的包名。這只是一個例子(一個糟糕的例子,也許是XD)。 – solaris98

+1

修復了軟件包名稱。一個問題中不必要的奇怪東西往往會分散人們的注意力。 –

回答

0

這裏是什麼你可以這樣做:

只保留profileId並且不要求

然後開始你

<decision-state id="isProfileIdSet"> 
    <if test="profileId != null" then="setProfile" else="errorState" /> 
</decision-state> 

<action-state id="setProfile">/*get Profile with id and store it in flowScope */</action-state> 

<end-state id="errorState"></end-state> 

流並添加<on-start>狀態或<on-entry>你的第一個國家內部

+0

謝謝你的回答。我已經將profileId設置爲以前版本代碼的flowScope。然而,這裏的主要問題是我想將整個對象從控制器傳遞到流程,而沒有任何NullPointerException。我正在嘗試像「currentEvent.attributes.profile」,但也沒有工作。 – solaris98

+0

你爲什麼想這樣做?爲什麼你不能保存它並從流程中檢索它? – rptmat57

+0

因爲這是整個需求的一小部分。下一步是向控制器的流發送一個HashMap。這就是爲什麼我正在尋找一個關於如何用對象來做的參考,而不是用一個Long類型來做。 – solaris98

相關問題