Re: [appengine-java] JDO not saved (commit) when using spring @ModelAttribute

2009-11-16 Thread Rusty Wright
Forgot to add; here's how I used it in my web.xml:



OpenPersistenceManagerInViewFilter




org.springframework.orm.jdo.support.OpenPersistenceManagerInViewFilter





OpenPersistenceManagerInViewFilter


/*


The other thing you could do is use the persistenceManager's detachCopy method 
on anything you're sending out to the web view layer.


Ibrahim Hamza wrote:
> Dear All
> I use JDO  with spring
> and when i add @ModelAttribute("countries")
> All things go fine except the data not saved without any exception
> When query from another datastore
> 
> 
> @Controller
> public class PortController  {
> 
> private static final String FORM_MODEL_KEY = "ports";
> 
> private static final String FORM_UPDATE_KEY = "port/Edit";
> 
> private static final String REDIRECT_LIST_VIEW_KEY = "redirect:/port/
> home.htm" ;
> 
>   @Autowired
>   private PortDAO portDAO;
>   @Autowired
>   private CountryDAO countryDAO;
> 
>   public PortController() {}
> 
> 
> 
>   @InitBinder
>   protected void initBinder(HttpServletRequest request,
> ServletRequestDataBinder binder) throws Exception {
>   binder.registerCustomEditor(String.class, new
> StringTrimmerEditor(false));
>   binder.registerCustomEditor
> (com.xesolution.domain.Country.class, new CountryEditor(countryDAO));
> 
>   }
> 
>   @RequestMapping(value="/port/home.htm")
>   public ModelMap list() {
>   return new ModelMap(FORM_MODEL_KEY,portDAO.readAll());
>   }
>   @RequestMapping(value="/port/new.htm")
>   public ModelAndView create(){
> Port port = new Port();
> return new ModelAndView(FORM_UPDATE_KEY,FORM_MODEL_KEY,port);
> }
>  @RequestMapping(value="/port/update.htm")
>   public ModelAndView update(@RequestParam("id") String id) {
> Port result = portDAO.read(id);
>   return new ModelAndView(FORM_UPDATE_KEY,FORM_MODEL_KEY, result);
>   }
> 
> 
>   @RequestMapping(value="/port/save.htm", method = RequestMethod.POST)
>   public ModelAndView save(@ModelAttribute(FORM_MODEL_KEY) Port port,
> BindingResult result, SessionStatus status) {
> 
>   new PortValidator().validate(port, result);
>   if (result.hasErrors())
>   {
> return new ModelAndView(FORM_UPDATE_KEY, FORM_MODEL_KEY,
> port);
>   }
>   else
>   {
>   portDAO.persist(port);
>   return new ModelAndView(FORM_UPDATE_KEY, FORM_MODEL_KEY, port);
> return new ModelAndView(REDIRECT_LIST_VIEW_KEY, list());
>   }
>   }
> 
>   @ModelAttribute("countries")
>   public List populateCountry() {
>   //this make data not saved
>   return countryDAO.readAll();
>   //But this make the data saved
>   //return portDAO.readAll();
>   }
> 
>   public void setPortDAO(PortDAO portDAO) {
> this.portDAO = portDAO;
>   }
> }
> and this is jsp line which display the form select
>  itemValue="id"/>
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Google App Engine for Java" group.
> To post to this group, send email to google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to 
> google-appengine-java+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/google-appengine-java?hl=.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=.




Re: [appengine-java] JDO not saved (commit) when using spring @ModelAttribute

2009-11-16 Thread Rusty Wright
http://static.springsource.org/spring/docs/3.0.0.RC1/javadoc-api/org/springframework/orm/jdo/support/OpenPersistenceManagerInViewFilter.html

That's the 3.0.0.rc1 version of the docs but it's probably the same for 2.5.6.


Ibrahim Hamza wrote:
> Dear All
> I use JDO  with spring
> and when i add @ModelAttribute("countries")
> All things go fine except the data not saved without any exception
> When query from another datastore
> 
> 
> @Controller
> public class PortController  {
> 
> private static final String FORM_MODEL_KEY = "ports";
> 
> private static final String FORM_UPDATE_KEY = "port/Edit";
> 
> private static final String REDIRECT_LIST_VIEW_KEY = "redirect:/port/
> home.htm" ;
> 
>   @Autowired
>   private PortDAO portDAO;
>   @Autowired
>   private CountryDAO countryDAO;
> 
>   public PortController() {}
> 
> 
> 
>   @InitBinder
>   protected void initBinder(HttpServletRequest request,
> ServletRequestDataBinder binder) throws Exception {
>   binder.registerCustomEditor(String.class, new
> StringTrimmerEditor(false));
>   binder.registerCustomEditor
> (com.xesolution.domain.Country.class, new CountryEditor(countryDAO));
> 
>   }
> 
>   @RequestMapping(value="/port/home.htm")
>   public ModelMap list() {
>   return new ModelMap(FORM_MODEL_KEY,portDAO.readAll());
>   }
>   @RequestMapping(value="/port/new.htm")
>   public ModelAndView create(){
> Port port = new Port();
> return new ModelAndView(FORM_UPDATE_KEY,FORM_MODEL_KEY,port);
> }
>  @RequestMapping(value="/port/update.htm")
>   public ModelAndView update(@RequestParam("id") String id) {
> Port result = portDAO.read(id);
>   return new ModelAndView(FORM_UPDATE_KEY,FORM_MODEL_KEY, result);
>   }
> 
> 
>   @RequestMapping(value="/port/save.htm", method = RequestMethod.POST)
>   public ModelAndView save(@ModelAttribute(FORM_MODEL_KEY) Port port,
> BindingResult result, SessionStatus status) {
> 
>   new PortValidator().validate(port, result);
>   if (result.hasErrors())
>   {
> return new ModelAndView(FORM_UPDATE_KEY, FORM_MODEL_KEY,
> port);
>   }
>   else
>   {
>   portDAO.persist(port);
>   return new ModelAndView(FORM_UPDATE_KEY, FORM_MODEL_KEY, port);
> return new ModelAndView(REDIRECT_LIST_VIEW_KEY, list());
>   }
>   }
> 
>   @ModelAttribute("countries")
>   public List populateCountry() {
>   //this make data not saved
>   return countryDAO.readAll();
>   //But this make the data saved
>   //return portDAO.readAll();
>   }
> 
>   public void setPortDAO(PortDAO portDAO) {
> this.portDAO = portDAO;
>   }
> }
> and this is jsp line which display the form select
>  itemValue="id"/>
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Google App Engine for Java" group.
> To post to this group, send email to google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to 
> google-appengine-java+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/google-appengine-java?hl=.
> 
> 

--

You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=.




[appengine-java] JDO not saved (commit) when using spring @ModelAttribute

2009-11-16 Thread Ibrahim Hamza
Dear All
I use JDO  with spring
and when i add @ModelAttribute("countries")
All things go fine except the data not saved without any exception
When query from another datastore


@Controller
public class PortController  {

private static final String FORM_MODEL_KEY = "ports";

private static final String FORM_UPDATE_KEY = "port/Edit";

private static final String REDIRECT_LIST_VIEW_KEY = "redirect:/port/
home.htm" ;

  @Autowired
  private PortDAO portDAO;
  @Autowired
  private CountryDAO countryDAO;

  public PortController() {}



  @InitBinder
  protected void initBinder(HttpServletRequest request,
  ServletRequestDataBinder binder) throws Exception {
  binder.registerCustomEditor(String.class, new
StringTrimmerEditor(false));
  binder.registerCustomEditor
(com.xesolution.domain.Country.class, new CountryEditor(countryDAO));

  }

  @RequestMapping(value="/port/home.htm")
  public ModelMap list() {
  return new ModelMap(FORM_MODEL_KEY,portDAO.readAll());
  }
  @RequestMapping(value="/port/new.htm")
  public ModelAndView create(){
  Port port = new Port();
  return new ModelAndView(FORM_UPDATE_KEY,FORM_MODEL_KEY,port);
  }
 @RequestMapping(value="/port/update.htm")
  public ModelAndView update(@RequestParam("id") String id) {
  Port result = portDAO.read(id);
  return new ModelAndView(FORM_UPDATE_KEY,FORM_MODEL_KEY, result);
  }


  @RequestMapping(value="/port/save.htm", method = RequestMethod.POST)
  public ModelAndView save(@ModelAttribute(FORM_MODEL_KEY) Port port,
BindingResult result, SessionStatus status) {

  new PortValidator().validate(port, result);
  if (result.hasErrors())
  {
return new ModelAndView(FORM_UPDATE_KEY, FORM_MODEL_KEY,
port);
  }
  else
  {
portDAO.persist(port);
return new ModelAndView(FORM_UPDATE_KEY, FORM_MODEL_KEY, port);
return new ModelAndView(REDIRECT_LIST_VIEW_KEY, list());
  }
  }

@ModelAttribute("countries")
public List populateCountry() {
//this make data not saved
return countryDAO.readAll();
//But this make the data saved
//return portDAO.readAll();
}

  public void setPortDAO(PortDAO portDAO) {
this.portDAO = portDAO;
  }
}
and this is jsp line which display the form select


--

You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=.