// get service and DAO objects
ApplicationContext ac = AppUtil.getApplicationContext();
AppService appService = (AppService)ac.getBean("appService");
final FormService formService = (FormService)ac.getBean("formService");
final FormDefinitionDao formDefinitionDao = (FormDefinitionDao)ac.getBean("formDefinitionDao");
final AppDefinition appDef = appService.getAppDefinition(appId, appVersion);
if (appDef != null && formDefId != null && !formDefId.isEmpty() && primaryKeyValue != null) {
formDefinitionDao.getHibernateTemplate().execute(new HibernateCallback() {
@SuppressWarnings("unchecked")
public Object doInHibernate(Session s) throws HibernateException, SQLException {
// get root form
Form form = null;
FormData formData = new FormData();
formData.setPrimaryKeyValue(primaryKeyValue);
FormDefinition formDef = formDefinitionDao.loadById(formDefId, appDef);
if (formDef != null) {
String formJson = formDef.getJson();
if (formJson != null) {
formJson = AppUtil.processHashVariable(formJson, assignment, StringUtil.TYPE_JSON, null);
form = (Form) formService.loadFormFromJson(formJson, formData);