0

我想显示一个编辑表单,用户可以在其中更改其旧数据。所以我想用从数据库中提取的值预先填充表单?

请告诉我如何在struts2中做到这一点?

4

1 回答 1

2

此拦截器在实现 Preparable 的操作上调用 prepare()。对于需要确保某些逻辑在实际执行方法运行之前运行的任何情况,此拦截器都非常有用。

可准备拦截器

示例: 类似于预填充逻辑的 Struts2 UI 标签。

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>
于 2012-05-24T16:51:48.127 回答