Announcement Announcement Module
No announcement yet.
bindAndValidate does not work within Subflows?? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • bindAndValidate does not work within Subflows??


    I have a form that is displayed in my parent flow, however I do some validation within a subflow,. among other things. It seems that validation fails within the subflow, but passes in my parent flow. In other words, I tested the same validation in both flows and it passes in the parent but fails in the subflow.

    Is there something I must pass to my subflow to get validation to work? I am passing the form to my subflow and have done some manipulations, so that is not it. I don't know what I'm missing. Perhaps I should override bindAndValidate so it can find my form?


  • #2
    I have exactly the same situation and validation works perfectly for me

    Paste your relevant flows, context and jsp fragments.


    • #3

      Here are the relevant fragments:

      Parent Flow:
      addActionState (ACTION_SELECT_CATEGORY_ID, method ("getSubcategories", actionRef (CatalogAction.class)), 
      				new Transition[] { on ("showOnlyCategories", VIEW_ONLY_CATEGORIES_ID),
      									on ("showCategoriesAndProducts", VIEW_CATEGORIES_AND_PRODUCTS_ID)});
      				new Transition[] {on("showCategory", ACTION_SELECT_CATEGORY_ID), 
      									on ("addCategory",SUB_FLOW_ADD_CATEGORY),
      									on ("duplicateCategory", SUB_FLOW_DUPLICATE_CATEGORY),
      									on ("updateCategory",SUB_FLOW_UPDATE_CATEGORY),
      									on ("removeCategory",SUB_FLOW_REMOVE_CATEGORY),
      									on ("deleteCategory",SUB_FLOW_DELETE_CATEGORY),
      									on (submit(), SUB_FLOW_SUBMIT_CATEGORY)});
      addSubFlowState(SUB_FLOW_SUBMIT_CATEGORY, flow(SUB_FLOW_SUBMIT_CATEGORY), new BrowseCatalogFlowAttributeMapper(),
      				new Transition[] { on(finish(), END_IN_REDIRECT), on(error(),  ACTION_SELECT_CATEGORY_ID) });

      Child Flow:

      I realized that SWF "[Bind] the parameters of the last event in given request context to the given form object using given data binder." So, I commented (removed) the first state. However, that only partially fix my problem; validation works but I am unable to see my validation errors besides my form. I believe the problem lies in the fact that my subflow is not exposing the validation errors to the parent flow, where it is displayed. How do I map back the validation errors to the parent flow? Perhaps, flowScope.errors or something?

      public void buildStates() throws FlowBuilderException {
      		//determine whether or not category should be created inline or via template
      		addActionState (METHOD, method(METHOD, actionRef(CategoryFormAction.class)),
      				new Transition[] {on (TEMPLATE,  BIND_N_VALIDATE), on (INLINE,  BIND_N_VALIDATE_INLINE)});
      		addActionState (BIND_N_VALIDATE_INLINE, method (BIND_N_VALIDATE, actionRef (CategoryFormAction.class)), 
      				new Transition[] {on (success(),  SUBMIT_CATEGORY_INLINE), on (error(), ERROR) });
      		//creates the category inline
      		addActionState (SUBMIT_CATEGORY_INLINE, method ( SUBMIT_CATEGORY_INLINE, actionRef(CategoryFormAction.class)),
      				new Transition[] {on (success(), FINISH), on (error(), ERROR)});



      • #4
        Solved it!

        The problem (and its solution) was staring me right in the face. All I needed to do was to override 'onBindAndValidate' and set some request attribute so that my view was updated properly. The flow was fine and SWF was not the problem.

        However, I have a quick question, does the following mean that you are not allowed to have any state that may potentialy generate an event between the submitting of a form and its' validation?
        Bind the parameters of the last event in given request context to the given form object using given data binder.
        Thanks in advance,



        • #5
          Thats one for Keith I think

          However, I do know that binding works on getLastEvent().getParameters() (lin 570 in FormAction) as oppose to getSourceEvent.

          I get around this by creating an AbstractChainedAction with the following methods:

          	public final Event success(final RequestContext context) {
          		return result(SUCCESS_RESULT_EVENT_ID, context.getSourceEvent().getParameters());
          	public final Event error(final RequestContext context) {
          		return result(ERROR_RESULT_EVENT_ID, context.getSourceEvent().getParameters());
          so parameters are propogated.


          • #6
            Hmm, Erwin and I debated what was more appropriate there: lastEvent or sourceEvent. It's a tough call.