Announcement Announcement Module
Collapse
No announcement yet.
Invoking the Validator manually - or a slightly unusal Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Invoking the Validator manually - or a slightly unusal

    Hallo,

    lets say, I have a serial Flow where the user is guided through the following states:

    Code:
    A -> B -> C -> D
    On each Screen the user has a button called next. This saves the input an navigates to the first state that does not validate. Normally this leads to an order like show above. But lets assume the user is in state C and wants to go back to A. When he then klicks an next he would assume to go back to C and not to B. Just the first page, with not validating data.

    In pratice I am doing this the following:
    Code:
      <action-state id="theMover">
        <evaluate expression="visitedStates.nextState(adData)" />
        <transition on="BASE"       to="baseData"       />
        <transition on="CONTENT"    to="contentData"    />
        <transition on="UPLOAD"     to="uploadData"     />
        <transition on="FORMATTING" to="formattingData" />
        <transition on="EXTRA"      to="extraData"      />
        <transition on="CONTACT"    to="contactData"    />
        <transition on="REVIEW"     to="review"         />
      </action-state>
    Every view-state navigates to the action-state "theMover". The visitedStates Bean then examines what the first not validating state is. This is my question:
    How can I invoke my Validators. The have Signatures like
    Code:
      public void validateBaseData(ValidationContext vcontext) {
    So I need a proper prepared ValidationContext. Has anyone an idea how to do this?

    Regards,
    Marc

  • #2
    Hello

    I dont understand very nice your requirement but, If I understood well, you are trying to do a manual validation in your action state, right?

    If the answer is yes,I suggest you do it automatically when you leave your view state, prior to enter to your action state, read more about the SWF for bind and validate attributes for the transition tag, because you need the data binding and validate the data when you leave the view state

    The action state you have seems be a huge desicion control, I think is well, but there the validation has no sense, I assume you are working with SWF 2.3.0 series, right?

    Comment


    • #3
      Originally posted by dr_pompeii View Post
      Hello

      I dont understand very nice your requirement but, If I understood well, you are trying to do a manual validation in your action state, right?

      If the answer is yes,I suggest you do it automatically when you leave your view state, prior to enter to your action state, read more about the SWF for bind and validate attributes for the transition tag, because you need the data binding and validate the data when you leave the view state

      The action state you have seems be a huge desicion control, I think is well, but there the validation has no sense, I assume you are working with SWF 2.3.0 series, right?
      You are right I want to validate in an action-state. Autamatic Validation when leaving the viewstate is not sufficient:

      Lets say you leave from C to A to redit something. Than you click next in state A. Than data-binding and validation will occur for state A. But where to go next. One possibility would be to go to B. This is the way most simply coded flows would do. But most often that is not what the user wants. The user just changed something in A. So most likely B is valid and the user don`t want to be annoyed with this form again. So he wanted to be forwared to C the last State where he was not finished with Data entry. Finding this new State could also be expressed by: the first view State where Validation fails. For now I recorded in my command-object in the case of automatic validation wether it succeded or not. But this is cumbersome on theire could be cases where this does not work correctly.

      Do you understand me?

      Comment


      • #4
        Hello

        Lets say you leave from C to A to redit something.
        OK, the same object or model is used for C and A ?, without matter the answer when you leave state C you could use or not use validation

        Than you click next in state A. Than data-binding and validation will occur for state A.
        OK when you leave view state A

        One possibility would be to go to B. This is the way most simply coded flows would do
        OK, from A to B

        The user just changed something in A. So most likely B is valid and the user don`t want to be annoyed with this form again
        If you changed something in A and you leave A, for the transition tag for A view state to anyware you should do the automatic validation, if fails it should return to A view state

        The validation happen when you leave a state, not when you enter to other state

        So he wanted to be forwared to C the last State where he was not finished with Data entry
        Always save your model object in flowscope

        some code would be useful

        Comment


        • #5
          Yes I use one commandbean for all states. Each state has its one validation method that gets executed automatically when leaving the state. And sure validation happens when leaving a state not when entering. This is for A totally OK. But when A validates than I just know that A is valid and not what is the next best state to enter. For this I want to find the first not validating on. For now I remember each time the automatic validation runs the result:

          public void validateContentData(ValidationContext vcontext) {
          MessageContext mcontext = vcontext.getMessageContext();
          if (this.ad.getText() != null && this.ad.getText().length() < 1) {
          mcontext.addMessage(new MessageBuilder().error().
          source("name").
          defaultText("Du musst einen Text angeben").build());
          }
          adjustValidatingStates(State.CONTENT, mcontext);
          }
          the last line is to this rememberence

          Than let me show you the method of the above ActionState I am invoking:

          public State nextState(PlaceAdCommand command) {
          State result = State.BASE;
          switch (lastValidating(command)) {
          case BASE : result = State.CONTENT; break;
          case CONTENT: if (command.isWithPicture())
          result = State.UPLOAD;
          else

          result = State.FORMATTING;
          break;
          case UPLOAD: result = State.FORMATTING; break;
          case FORMATTING: result = State.EXTRA; break;
          case EXTRA: result = State.CONTACT; break;
          case CONTACT: result = State.REVIEW; break;
          case REVIEW: result = State.REVIEW;
          }
          System.out.println("Nextone: " + result);
          return result;
          }
          See here what I am "switching" about. I retrieve the last validating State. In fact I just pretend to do do, in reality I inferre it from the saved values from the automatic validations. This works in most cases but let's assume a change in A makes B invalid (that was valid before the chang in A): this is the case where this trick does not work and I need a way to invoke the validation methos explicitly.

          No clear?

          Regards,

          Marc Gorzala

          Comment

          Working...
          X