2012-05-24 85 views
0

我想顯示一個編輯表單,用戶可以在其中更改其舊數據。 所以我想預先準備從數據庫中拾取的值?如何從數據庫值中預填充struts2中的表格

請告訴我如何在struts2中做到這一點?

+0

嘗試在豆來填充數據,那麼它是通過支桿標籤相應的轉發的jsp訪問。 – AurA

+0

你可以給我示例/鏈接 – JMoh

+0

http://www.tutorialspoint.com/struts_2/struts_database_access.htm – AurA

回答

2

這個攔截器調用prepare()對實現 Preparable的動作。這個攔截器對於在執行實際執行方法 之前需要確保某些邏輯運行的任何情況都非常有用。

PreparableInterceptor

實施例: Struts2 UI Tags similar to pre-population logic.

package com.examples; 
public class RegistrationAction extends ActionSupport implements Preparable { 

    @Override 
    public void prepare() throws Exception { 
     // get the data that you want to pre-populate 
    } 

    public String execute() { 
     // you action logic 
     return SUCCESS; 
    } 

} 



<!-- Calls the params interceptor twice, allowing you to pre-load data for the second time parameters are set --> 
<!-- don't forgot to add prepare interceptor to interceptor stack --> 
<action name="someAction" class="com.examples.RegistrationAction"> 
    <interceptor-ref name="params"/> 
    <interceptor-ref name="prepare"/> 
    <interceptor-ref name="basicStack"/> 
    <result name="success">good_result.ftl</result> 
</action> 
+0

你能給我舉例鏈接/示例代碼? – JMoh

+0

@jmoh更新了我的答案,請檢查。 –

+0

謝謝@Mohana Rao SV – JMoh

相關問題