Search in sources :

Example 1 with JavaClassAccessor

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);
            }
        }
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SelectField(com.manydesigns.elements.fields.SelectField) SelectionProviderReference(com.manydesigns.portofino.resourceactions.m2m.configuration.SelectionProviderReference) JavaClassAccessor(com.manydesigns.elements.reflection.JavaClassAccessor)

Aggregations

SelectField (com.manydesigns.elements.fields.SelectField)1 JavaClassAccessor (com.manydesigns.elements.reflection.JavaClassAccessor)1 SelectionProviderReference (com.manydesigns.portofino.resourceactions.m2m.configuration.SelectionProviderReference)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1