public boolean useAjax() {
return "true".equalsIgnoreCase(getPropertyString("useAjax"));
}
public FormRowSet loadAjaxOptions(String[] dependencyValues) {
FormRowSet results = new FormRowSet();
results.setMultiRow(true);
//Using filtered formset to ensure the returned result is clean with no unnecessary nulls
FormRowSet filtered = new FormRowSet();
filtered.setMultiRow(true);
try {
// get form
String formDefId = (String) getProperty("formDefId");
String tableName = getTableName(formDefId);
if (tableName != null) {
String condition = null;
Object[] conditionParams = null;
String extraCondition = (String) getProperty("extraCondition");
if (extraCondition != null && !extraCondition.trim().isEmpty()) {
condition = " WHERE " + extraCondition;
}
if (dependencyValues != null && getProperty("groupingColumn") != null) {
if (extraCondition == null || extraCondition.trim().isEmpty()) {
condition = " WHERE ";
} else {
condition += " AND ";
}
if (dependencyValues.length > 0) {
condition += "e.customProperties." + getProperty("groupingColumn").toString() + " in (";
for (String s : dependencyValues) {
condition += "?,";
}
condition = condition.substring(0, condition.length()-1) + ")";
conditionParams = dependencyValues;
} else {
condition += "e.customProperties." + getProperty("groupingColumn").toString() + " is empty";
}
}
String labelColumn = (String) getProperty("labelColumn");
// get form data
FormDataDao formDataDao = (FormDataDao) AppUtil.getApplicationContext().getBean("formDataDao");
results = formDataDao.find(formDefId, tableName, condition, conditionParams, labelColumn, false, null, null);
if (results != null) {
if ("true".equals(getPropertyString("addEmptyOption"))) {
FormRow emptyRow = new FormRow();
emptyRow.setProperty(FormUtil.PROPERTY_VALUE, "");
emptyRow.setProperty(FormUtil.PROPERTY_LABEL, getPropertyString("emptyLabel"));
filtered.add(emptyRow);
}
//Determine id column. Setting to default if not specified
String idColumn = (String) getProperty("idColumn");
idColumn = (idColumn == null || "".equals(idColumn)) ? FormUtil.PROPERTY_ID : idColumn;
String groupingColumn = (String) getProperty("groupingColumn");
// loop thru results to set value and label
for (FormRow row : results) {
String id = row.getProperty(idColumn);
String label = row.getProperty(labelColumn);
String grouping = "";
if (groupingColumn != null && !groupingColumn.isEmpty() && row.containsKey(groupingColumn)) {
grouping = row.getProperty(groupingColumn);
}
if (id != null && !id.isEmpty() && label != null && !label.isEmpty()) {
row.setProperty(FormUtil.PROPERTY_VALUE, id);
row.setProperty(FormUtil.PROPERTY_LABEL, label);
row.setProperty(FormUtil.PROPERTY_GROUPING, grouping);
filtered.add(row);
}
}
}
}
} catch (Exception e) {