PDA

View Full Version : custom simple form controler duplicating command properties


glenmartinthomas
Aug 30th, 2005, 11:24 AM
I'm writing a custom extention of the simple form controller to implement my own xslt processing.

It should be fairly staraight forward.

On Initial display (GET)
1. load command object which is populated from the database.
2. convert to xml and place in model
3. Display

On submit (POST)
1. create blank command
2. populate command from request param's from form.
3. write to DB
4. display next page.

seems quite simpe but for some strange reason the primary key (id)
get's duplicated on the submit.... i.e. record with id 12 results in an id 1212 ......
after a number of tracing, it seems it's caused by a line in the referenceDATA where I add an object ('v_xml') to the model map.....
-- no idea why .... HELP !

here's the code....
public class contentFormCtrl extends SimpleFormController
{
public contentFormCtrl()
{ setSessionForm(false);
setCommandName("command");
setCommandClass(Content.class);
}

protected ModelAndView processFormSubmission(HttpServletRequest request,HttpServletResponse response,Object command, BindException errors) throws Exception
{ System.out.println("processFormSubmission - running! : "+((Content)command).getId());
return super.processFormSubmission(request, response, command, errors);
}

protected void initBinder(HttpServletRequest request,ServletRequestDataBinder binder) throws Exception
{ binder.registerCustomEditor(java.lang.Integer.clas s,new CustomNumberEditor(java.lang.Integer.class,NumberF ormat.getInstance(Locale.ENGLISH), true));
binder.registerCustomEditor(char.class,new charEditor() );
}

public Map referenceData(HttpServletRequest request, Object command, Errors errors)
{
boolean isSubmit = this.isFormSubmission(request);
System.out.println("running Reference data : "+isSubmit+" -- "+errors.getErrorCount()+" -- "+errors.toString());
HashMap hm = new HashMap();
System.out.println("running Reference data 2 : "+((Content)command).getId() );

// !!!!!!!! THIS SEEMS TO BE THE CAUSE OF THE PROBLEM !!!!
if (!isSubmit) hm.put("v_xml","<stuff><content>"+((XMLDomain)command).toXML()+"</content></stuff>" );
return hm;
}

protected Object formBackingObject(HttpServletRequest request) throws ServletException
{ boolean isSubmit = this.isFormSubmission(request);
Content content = getCms2().getContent( RequestUtils.getRequiredIntParameter(request, "id"));
System.out.println("formBackingObject : - :"+isSubmit+" <content>"+content.toXML()+"</content>");
return content;
}

protected ModelAndView onSubmit(Object command) throws ServletException
{
Content content = (Content) command;
System.out.println("running onSubmit : "+content.getId());
return new ModelAndView(getSuccessView() );
}


protected void onBind(HttpServletRequest request,Object command,BindException errors) throws Exception
{ System.out.println("running onBind : "+ ((Content) command).getId());
super.onBind(request, command, errors);
}

}



and the tracing :
5/08/30 16:07:12 formBackingObject : - :true <content><rec><id>12</id><repositoryid>1</repositoryid><parentid>0</parentid><contenttypeid>0</contenttypeid><isbranch></isbranch><creatorid>0</creatorid><publishdate></publishdate><cname>goodmorning</cname></rec></content>

05/08/30 16:07:12 charEditor - setAsText :

05/08/30 16:07:12 running onBind : 1212

05/08/30 16:07:12 processFormSubmission - running! : 1212

05/08/30 16:07:12 running onSubmit : 1212