保持struts-config.xml不变,将动态Form org.apache.struts.action.DynaActionForm转化成ActionForm的例子

很简单,需要注意的是:
在FormBean里  Integer state = new Integer(2);这样初始化和在配置文件中这样初始化:
 <form-property initial="2" name="state" type="java.lang.Integer" />
是不起冲突的,配置文件的优先级更高,实际上这里配不配都是一样的

假设struts-config.xml中本来是这样:
<form-bean name="discussForm" type="org.apache.struts.action.DynaActionForm">
      <form-property initial="2" name="state" type="java.lang.Integer" />
      <form-property name="staffId" type="java.lang.Integer" />
      <form-property name="title" type="java.lang.String" />
      <form-property name="messageContent" type="java.lang.String" />
      <form-property initial="false" name="needReply" type="java.lang.Boolean" />
      <form-property name="messageId" type="java.lang.String" />
      <form-property name="receiverId" type="java.lang.Integer" />
      <form-property name="reply" type="java.lang.Boolean" />
      <form-property name="file1" type="org.apache.struts.upload.FormFile" />
      <form-property name="file2" type="org.apache.struts.upload.FormFile" />
      <form-property name="file3" type="org.apache.struts.upload.FormFile" />    </form-bean>
只改其引用类型:org.apache.struts.action.DynaActionForm,改成com.message.MessageActionForm
则该Form为:
import org.apache.struts.action.ActionForm;
import org.apache.struts.upload.FormFile;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MessageActionForm
    extends ActionForm {
  Integer state = new Integer(2);//这里也可以这么写Integer state;即可
  Integer staffId;
  Integer deptId;
  String title;
  String messageContent;
  Boolean needReply = new Boolean(false);//Boolean needReply;也可以这么写
  String messageId;
  Integer receiverId;
  Boolean reply;
  FormFile file1;
  FormFile file2;
  FormFile file3;
  Log log = LogFactory.getLog(MessageActionForm.class);
  public MessageActionForm() {
  }

  public void reset(ActionMapping mapping, HttpServletRequest request) {
    try {
      request.setCharacterEncoding("GBK");
    }
    catch (UnsupportedEncodingException ex) {
      log.info("encoding error! ", ex);
    }
  }

  public FormFile getFile1() {
    return file1;
  }

  public void setFile1(FormFile file1) {
    this.file1 = file1;
  }

  public FormFile getFile2() {
    return file2;
  }

  public void setFile2(FormFile file2) {
    this.file2 = file2;
  }

  public FormFile getFile3() {
    return file3;
  }

  public void setFile3(FormFile file3) {
    this.file3 = file3;
  }

  public String getMessageContent() {
    return messageContent;
  }

  public void setMessageContent(String messageContent) {
    this.messageContent = messageContent;
  }

  public String getMessageId() {
    return messageId;
  }

  public void setMessageId(String messageId) {
    this.messageId = messageId;
  }

  public Boolean getNeedReply() {
    return needReply;
  }

  public void setNeedReply(Boolean needReply) {
    this.needReply = needReply;
  }

  public Integer getReceiverId() {
    return receiverId;
  }

  public void setReceiverId(Integer receiverId) {
    this.receiverId = receiverId;
  }

  public Boolean getReply() {
    return reply;
  }

  public void setReply(Boolean reply) {
    this.reply = reply;
  }

  public Integer getStaffId() {
    return staffId;
  }

  public void setStaffId(Integer staffId) {
    this.staffId = staffId;
  }

  public Integer getState() {
    return state;
  }

  public void setState(Integer state) {
    this.state = state;
  }

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值