|
|
Let's say I'm populating my form via a given GET request parameter (Constants.BIBLE_ID_REQUEST_PARAM) in the formBackingObject method. The implementation bellow works. But am I doing it right?
I don't think I am doing it right, only because there are methods in my BiblePropertyEditor such as getAsText() which seem as though they should do the bulk of that work for me, but never get called.Code:
/*** Implementation of lt;stronggt;SimpleFormControllerlt;/stronggt; that interacts with* the {@link OSBManager} to retrieve/persist values to the database.*/
public class BibleFormController extends BaseFormController {
private OsbBaseObjectManager osbBaseObjectMgr;
public void setOsbBaseObjectManager(OsbBaseObjectManager osbBaseObjectMgr)
{
this.osbBaseObjectMgr = osbBaseObjectMgr;
}
/*** Step 1: In a GET* Step 1: In a POST** In a GET:* This should return a formbacking object* for populating the display on the front end.*/
protected Object formBackingObject(fromServletRequest request)
throws Exception
{
log.info(quot;Begin: formBackingObjectquot;);
String bibleId = null;
BibleForm form = new BibleForm(); // Create the form object
Bible bible = null;
// If the user has clicked a link
// requesting to edit an existing Bible...
//
// ...place that Bible's properties
// in the form/command object.
bibleId = (String) request.getParameter(Constants.BIBLE_ID_REQUEST_PARAM);
log.debug(quot;Request Parameter: quot; + bibleId);
if(bibleId != null)
{bible = osbBaseObjectMgr.getBible(bibleId);
form.setId(quot;quot; + bible.getId());
form.setLocale(bible.getLocale());
form.setVersion(bible.getVersion());
}
log.info(quot;Exit: formBackingObjectquot;);
return form;
}
/*** Step 2: In a GET* Step 2: In a POST** In a GET:* This method binds the object to the form using* PropertyEditorSupports to associate an* entire object with a primitive value stored in* the form. (PropertyEditorSupports are seprate* implementation classes)** When we say bind we mean...what the property editor does,* associates an entire object with the values being populated* in the form.**/
protected void initBinder(fromServletRequest request, ServletRequestDataBinder binder)
{
log.info(quot;Begin: initBinderquot;);
BiblePropertyEditor propertyEditor = new BiblePropertyEditor();
propertyEditor.setOsbBaseObjectManger(osbBaseObjectMgr);
binder.registerCustomEditor(Bible.class, quot;biblequot;, propertyEditor);
super.initBinder(request, binder);
log.info(quot;Exit: initBinderquot;);
}
/*** Step 3: In a GET* This is the place to provide any thing that is* likely to populate othe elements in the view* for instance Lists for dropdowns and tables.**/
protected Map referenceData(fromServletRequest request,
Object command,
Errors errors)
throws Exception
{
log.info(quot;Begin: referenceDataquot;);
Map model = new HashMap();
// Nothing at the moment...
log.info(quot;Exit: referenceDataquot;);
return model;
}
}
Thank you, Andrew J. Leer |
|