use of com.manydesigns.elements.reflection.JavaClassAccessor in project Portofino by ManyDesigns.
the class ManyToManyAction method addSpRefSelectionProvider.
protected void addSpRefSelectionProvider(final List<ModelSelectionProvider> sps, Form form, String fieldName) throws NoSuchFieldException {
SelectionProvider sp = SelectionProviderLogic.createSelectionProvider(fieldName, sps, ModelSelectionProvider.class, null, new String[] { "name" });
JavaClassAccessor acc = JavaClassAccessor.getClassAccessor(ManyToManyConfiguration.class);
form.get(0).add(new SelectField(acc.getProperty(fieldName), sp, Mode.EDIT, "") {
@Override
public void readFromRequest(HttpServletRequest req) {
String stringValue = req.getParameter(inputName);
if (!StringUtils.isEmpty(stringValue)) {
for (ModelSelectionProvider msp : sps) {
if (msp.getName().equals(stringValue)) {
SelectionProviderReference ref = new SelectionProviderReference();
if (msp instanceof ForeignKey) {
ref.setForeignKeyName(msp.getName());
} else {
ref.setSelectionProviderName(msp.getName());
}
selectionModel.setValue(selectionModelIndex, ref);
}
}
} else {
selectionModel.setValue(selectionModelIndex, null);
}
}
});
}
Aggregations