2013-10-23 57 views
0

我已經用於當一個提交按鈕的應用程序以下流被點擊在模型添加時如何查看在jsp的數據:使用彈簧MVC

1)viewActivity方法是從ActivityController.java

稱爲
ActivityController.java 
@ActionMapping(params = "ActivityController=showActivity") 
public void viewActivity(@RequestParam Integer index, ActionResponse response, Model model, @ModelAttribute Header header, 
.... 
    model.addAttribute("recoveryForm", new RecoveryForm(detailsResult.getDetails())); 
    response.setRenderParameter("ServiceController", "showService"); 
} 

2)然後showRecovery方法被稱爲從serviceConroller如下顯示:

ServiceController.JAVA 
    @RenderMapping(params = "ServiceController=showService") 
    public String showRecovery(@ModelAttribute recoveryForm form, @ModelAttribute header header) { 
    ..... 
      return service; 
    } 

然後我service.jsp顯示

基本上我必須顯示在DetailsResult.getDetails()對象中找到的detailName的變量的值,我已將它添加到我的模型中作爲 ,它可以在ActivityController.java中找到的viewActivity方法中顯示,顯示爲ealier。

我知道當我們添加model.addAttribute它應該能夠在這個將要顯示在JSP中使用以下標籤:

<form:input path="..." />

但在這種情況下,它被添加到作爲如下圖所示構造函數的參數:

model.addAttribute("recoveryForm", new RecoveryForm(detailsResult.getDetails())); 

我有我的RecoveryForm以下變量:

public class RecoveryForm implements Serializable { 


    private CDetails Cdlaim; 
    private Action addAction; 
    private String addRemark; 
    private String remarks; 

public RecoveryForm(CDetails Cdlaim) { 
    ... 
    } 
    ... 
} 

但是我沒有在我的RecoveryForm中的detailsResult。

任何想法如何我可以得到在我的service.jsp DetailsResult.getDetails()中的值?

+0

向我們展示您在'RecoveryForm'中保留'Details'的屬性? –

回答

0

我相信你看着這個錯誤的方式。作爲屬性,DetailsResult.getDetails()的值顯然存儲在RecoveryForm中。所以,我要假設你RecoveryForm看起來像:

public class RecoveryForm { 
    private String details; 
    public RecoveryForm(String details) { 
     this.details = details; 
    } 
    public String getDetails() { 
     return details; 
    } 
} 

當您綁定到你的JSP形式,你需要窩在一個<form:form ...>標籤您<form:input ...>標籤:

<form:form commandName="recoveryForm" ...> 
    <form:input path="details" ... /> 
</form:form> 

commandName是告訴表單模型對象的關鍵,您將從中抽取表單值。在這種情況下,您將從名爲recoveryFormRecoveryForm實例獲取details屬性。合理?

+0

嗨,我已經使用RecoveryForm.java更新了代碼。好,所以你的意思是數據應該可以通過使用recoveryForm ..在我的jsp中 – user1999453

+0

正確。您的RecoveryForm是由「recoveryForm」鍵引用的對象。因此,如果您想從該實例獲取屬性,則只需使用點符號引用它們即可。例如,如果您的CDetails對象具有名爲「name」的其他子屬性,則可以使用「details.name」作爲輸入路徑來引用它。 – MattSenter