Announcement Announcement Module
Collapse
No announcement yet.
Form via ActionCommand: no validation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Form via ActionCommand: no validation

    Hi,

    I've created a new Spring RCP project based on the archetype project. I've added a simple form that's controlled by a ActionCommand class. I've added this ActionCommand to the menu and the forms display correctly.

    I've also created a RulesSource implementation for the command object, added some constraints and configured the RulesSource object in the richclient-application-context.xml file.

    However, these constraints don't get applied in the form and I've looked everywhere but can't get the constraints to work. I've based my form on the PetForm in the PetClinic sample.

    This is the command object:

    Code:
    public class ExpenseDTO {
        private BigDecimal amount;
        private String description;
    
        public BigDecimal getAmount() {
            return amount;
        }
    
        public void setAmount(BigDecimal amount) {
            this.amount = amount;
        }
    
        public String getDescription() {
            return description;
        }
    
        public void setDescription(String description) {
            this.description = description;
        }
    }
    This the RulesSource class:

    Code:
    public class ExpenseDTOConstraints extends DefaultRulesSource {
        public ExpenseDTOConstraints() {
            addRules(createExpenseDTORules());
        }
    
        protected Rules createExpenseDTORules() {
            Rules rules = new Rules(ExpenseDTO.class);
            rules.add("amount", all(new Constraint[] { required(), gte(new BigDecimal("0")) }));
            rules.add("description", all(new Constraint[] { required(), maxLength(5) }));
            return rules;
        }
    }
    This is the configuration for the RulesSource class in the richclient-application-context.xml file:

    Code:
    <bean id="rulesSource" class="expenses.gui.constraints.ExpenseDTOConstraints"/>
    This is the Form:

    Code:
    public class NewExpenseForm extends AbstractForm {
        private static final String NEW_EXPENSE_COMMAND = "newExpenseCommand";
    
        public NewExpenseForm(FormModel formModel) {
            super(formModel, NEW_EXPENSE_COMMAND);
        }
    
        protected JComponent createFormControl() {
            TableFormBuilder formBuilder = new TableFormBuilder(getBindingFactory());
            formBuilder.add("amount");
            formBuilder.row();
            formBuilder.addTextArea("description");
            return formBuilder.getForm();
        }
    }
    This is the ActionCommand class:

    Code:
    public class NewExpenseAction extends ActionCommand {
        public NewExpenseAction() {
            super("newExpenseAction");
        }
    
        protected void doExecuteCommand() {
            final NewExpenseForm newExpenseForm = new NewExpenseForm(FormModelHelper.createFormModel(new ExpenseDTO()));
            final FormBackedDialogPage dialogPage = new FormBackedDialogPage(newExpenseForm);
            TitledPageApplicationDialog dialog = new TitledPageApplicationDialog(dialogPage) {
                protected void onAboutToShow() {
                    setEnabled(dialogPage.isPageComplete());
                }
    
                protected boolean onFinish() {
                    newExpenseForm.commit();
                    return true;
                }
            };
            dialog.showDialog();
        }
    }
    This is the configuration that adds the ActionCommand to the menu in commands-context.xml:

    Code:
        <bean id="newMenu"
            class="org.springframework.richclient.command.CommandGroupFactoryBean">
            <property name="members">
                <list>
                    <ref bean="newExpenseCommand"/>
                </list>
            </property>
        </bean>
    
        <bean id="newExpenseCommand"
            class="org.springframework.richclient.command.TargetableActionCommand">
            <property name="commandExecutor">
                <ref bean="newExpenseAction"/>
            </property>
        </bean>
    Again, the menu and the form show correctly and the command object is properly populated. Only, the validation doesn't kick in.

    I'm not sure what I'm doing wrong. Any help is kindly appreciated.

    Thanks

  • #2
    re: Form via ActionCommand

    Hi,
    I'm not sure but try at NewExpenseAction.doExecuteCommand() method after instantiation of NewExpenseForm do setFormObject:

    Code:
    final NewExpenseForm newExpenseForm = new NewExpenseForm(FormModelHelper.createFormModel(new ExpenseDTO()));
    newExpenseForm.setFormObject(new ExpenseDTO());
    This should help.

    --
    Victor

    Comment


    • #3
      What version of SpringRCP you are using?
      And show "applicationServices" bean definition in your application-context.xml file.

      Comment


      • #4
        Originally posted by borism
        What version of SpringRCP you are using?
        And show "applicationServices" bean definition in your application-context.xml file.
        I'm using yesterdays HEAD. I don't have the project handy right now but "applicationServices" is exactly as generated by the archetype project.

        Comment


        • #5
          I generate test project using archetype. And I think the archetype project is not synchronized with with a springrcp-support and a change that intoduce an ServiceLocator and ApplicationServices as it described at http://spring-rich-c.sourceforge.net...upgrading.html. Maybe it is a JIRA issue.

          Just try to add the next bean definitions to your richclient-application-service.xml
          Code:
              <bean id="serviceLocator"  	class="org.springframework.richclient.application.ApplicationServicesLocator">
                  <property name="applicationServices" ref="applicationServices"/>
              </bean>
          
              <bean id="applicationServices"
                  class="org.springframework.richclient.application.support.DefaultApplicationServices">
                  <property name="imageSourceId">
                  	<idref bean="imageSource"/>
                  </property>
                  <property name="rulesSourceId">
                  	<idref bean="rulesSource"/>
                  </property>
                  <property name="binderSelectionStrategyId">
                  	<idref bean="binderSelectionStrategy"/>
                  </property>
                  <property name="formComponentInterceptorFactoryId">
                  	<idref bean="formComponentInterceptorFactory"/>
                  </property>
                  <property name="applicationObjectConfigurerId">
                  	<idref bean="applicationObjectConfigurer" />
                  </property>
              </bean>

          Comment


          • #6
            The archetype is synched with the latest development code. The application services definition generated should look like this:

            Code:
                <bean id="applicationServices" class="org.springframework.richclient.application.support.DefaultApplicationServices">
                    <property name="imageSourceId"><idref bean="imageSource"/></property>
                    <property name="formComponentInterceptorFactoryId"><idref bean="formComponentInterceptorFactory"/></property>
                    <property name="applicationObjectConfigurerId"><idref bean="applicationObjectConfigurer" /></property>
                </bean>

            It does not include a rules source by default (since that is unique to each application). In order to make use of a rules source, just add it to the applicationServices configuration as borism suggests.

            Larry.

            Comment

            Working...
            X