* @return
*/
protected Form retrieveDataForm(FormData formData, String primaryKeyValue) {
Form form = null;
ApplicationContext ac = AppUtil.getApplicationContext();
AppService appService = (AppService) ac.getBean("appService");
FormService formService = (FormService) ac.getBean("formService");
AppDefinition appDef = AppUtil.getCurrentAppDefinition();
String formId = getPropertyString("formId");
formData = formService.retrieveFormDataFromRequestMap(formData, getRequestParameters());
//if primary key is null, look up for primary key using userview key
if (primaryKeyValue == null && getPropertyString("keyName") != null && (getPropertyString("loadDataWithKey") != null && "Yes".equalsIgnoreCase(getPropertyString("loadDataWithKey"))) && getPropertyString("keyName").trim().length() > 0 && getKey() != null) {
if (FormUtil.PROPERTY_ID.equals(getPropertyString("keyName"))) {
primaryKeyValue = getKey();
} else {
primaryKeyValue = appService.getPrimaryKeyWithForeignKey(appDef.getId(), appDef.getVersion().toString(), formId, getPropertyString("keyName"), getKey());
}
}
// set primary key
formData.setPrimaryKeyValue(primaryKeyValue);
if (getPropertyString("keyName") != null && getPropertyString("keyName").trim().length() > 0 && getKey() != null) {
formData.addRequestParameterValues(getPropertyString("keyName"), new String[]{getKey()});
}
// retrieve form
String formUrl = getUrl() + "?_action=submit";
if (primaryKeyValue != null) {
try {
formUrl += "&" + FormUtil.PROPERTY_ID + "=" + URLEncoder.encode(primaryKeyValue, "UTF-8");
} catch (UnsupportedEncodingException ex) {
// ignore
}
}
String submitLabel = "Submit";
if (getPropertyString("submitButtonLabel") != null && getPropertyString("submitButtonLabel").trim().length() > 0) {
submitLabel = getPropertyString("submitButtonLabel");
}
String cancelUrl = getPropertyString("redirectUrlOnCancel");
String cancelLabel = null;
if (cancelUrl != null && !cancelUrl.isEmpty()) {
if (getPropertyString("cancelButtonLabel") != null && getPropertyString("cancelButtonLabel").trim().length() > 0) {
cancelLabel = getPropertyString("cancelButtonLabel");
} else {
cancelLabel = "Cancel";
}
}
Boolean readonlyLabel = "true".equalsIgnoreCase(getPropertyString("readonlyLabel"));
form = appService.viewDataForm(appDef.getId(), appDef.getVersion().toString(), formId, null, submitLabel, cancelLabel, getPropertyString("redirectTargetOnCancel"), formData, formUrl, cancelUrl);
if (form != null) {
// make primary key read-only
Element el = FormUtil.findElement(FormUtil.PROPERTY_ID, form, formData);
if (el != null) {