Forgot to add; here's how I used it in my web.xml:
<filter>
<filter-name>
OpenPersistenceManagerInViewFilter
</filter-name>
<filter-class>
org.springframework.orm.jdo.support.OpenPersistenceManagerInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>
OpenPersistenceManagerInViewFilter
</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
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
> <form:select path="country" items="${countries}" itemLabel="name"
> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=.