FormBean也不一定所有的属性都要Set吧?你可以在FormBean里包含其它的属性和方法,但JSP页面里不一定要使用的。

解决方案 »

  1.   

    page1页面request得到一个类对象,我想把这个类对象SET至page1对应的FORMBEAN的属性,可以实现吗?
      

  2.   

    oh my god..谁能帮帮我吗??
      

  3.   

    FormBean本身也是一个javaBean,你像一般Bean一样设置就可以了
      

  4.   

    其实String也是一个类啊,其他的类也是可以通过setXXX()和getXXX()方法来实现的
      

  5.   

    去看struts源码。这种东西各个版本都有不同,至少我用的版本仍然用bean:define取得值。比如:
    <bean:define id="countryStateCollectionTO" name="ShipperModeRulesForm" property="countryStateCollectionTO"/>觉得功能不够可以自己extends,不过不要滥用。formbean初衷在于采集用户资料,以及反馈结果,如果要set对象进去,已经有点跑题,考虑考虑自己的设计吧。
      

  6.   

    FormBean应该知识获取页面的表单基本属性
    如果是一个类建议在FormBean多添加几个基本属性描述该类。
    然后在Action里保存.
      

  7.   

    假设你的ActionFormBean有一个Customer类的属性,Customer类有两个成员变量为name和address,则ActionFormBean如下
    package com.ibm.sample.struts;


    import javax.servlet.http.HttpServletRequest;

    import org.apache.struts.action.ActionError;
    import org.apache.struts.action.ActionErrors;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;

    public class SubmitForm extends ActionForm {
    private Customer customer = new Customer();
    private String name = null;
    private String address = null;

    public Customer getCustomer() {
    return customer;
    }
    public void setCustomer(Customer customer) {
    this.customer = customer;
    }
    public String getAddress() {
    return customer.getAddress();
    }
    public String getName() {
    return customer.getName();
    }
    public void setAddress(String address) {
    customer.setAddress(address);
    }
    public void setName(String name) {
    customer.setName(name);
    }
    public void reset(ActionMapping mapping, HttpServletRequest request) {
    this.customer = new Customer();
    name = new String();
    address = new String();
    }
    } 相应的页面对应Customer类的部分如下:
    Name: <html:text property="customer.name"/><br>
    Address: <html:text property="customer.address"/><br>
      

  8.   

    楼上的:既然已经有了setName方法,何必
    <html:text property="customer.name"/>
    呢。
    <html:text property="name"/>
    就可以了。要不然不是白做了两套方法。 :)