struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xnpeng <xnp...@163.com>
Subject how to update/persist associate entity?
Date Tue, 17 Mar 2009 12:05:15 GMT
class Site{
  String id;
  String name;
  Set<SiteProperty> properties;
  ...setter/getter
}
 
class SiteProperty{
 String typeId;
 String typeName;
 Site site;
 ...
 setter/getter
}
 
SiteController.java
class SiteController extends ActionSupport{
  Site site;
  setter/getter...
  public String update(){
     Session session = SessionFactory.getSession();
     Transaction tx = session.beginTransaction();
     try{
        session.saveOrUpdate(site);
        Set props = site.getProperties();
        Iterator it = props.iterator();
        while(it.hasNext()){
           SiteProperty prop = (SiteProperty)it.next();
           prop.setSite(site);
           session.saveOrUpdate(prop);
        }
        tx.commit();
     }catch(HibernateException e){
        tx.rollback();
     }
     return "index";
  }
}
 
site-edit.jsp:
<s:form action="site/%{site.id}">
  <s:hidden name="_method" value="put"/>
  <s:textvalue name="site.id"/>
  <s:textvalue name="site.name"/>
  <s:iterator value="site.properties">
     <s:textvalue name="propId"/>
     <s:textvalue name="propName"/>
     <s:textvalue name="site.id"/>
  </s:iterator>
  <s:submit/>
</s:form>
 
my question is,i can insert/update Site entity into database, while the properties<SiteProperty>
cannot save to database, even in memory,the properties data refuse to take any change i made
in client.
 
i'm confused by form/action mapping, how does the data transfer to action when client submit
the form? i traced the action's setter/getter method,there is no step into these methods,how
does the request data transfer to action?
 
thank you.


 
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message