Announcement Announcement Module
Collapse
No announcement yet.
Custom errors after bindAndValidate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom errors after bindAndValidate

    Hello.
    I got a question.
    I searched on the forum but i didn't find any solution at this time.

    When i do a bindAndValidate action, i can play with Errors from
    Code:
    validate(Object obj, Errors errors)
    method

    but when i try to validate something under another action ie


    Code:
    public Event insert(RequestContext context) throws Exception {
        	setFormObjectClass(AdminValue.class);
        	super.bind(context);
        	final AdminValue admin = (AdminValue)getFormObject(context);
        	try {
    	        bd.insert(admin);
    		return success();
    	} catch (DuplicateNicknameException e) {
       getFormErrors(context).rejectValue("nickname","executives.form.duplicateNickname",new Object[]{admin.getNickname},"defaultmessage hey!");
               return error();
    		}
        }
    it does not seem to work.
    It seems that the Errors intance on bindAndValidate is different from the one given by getFormErrors(context), like a cloned one.
    how do i add a custom error on a method different from bindAndValidate?

    like:

    Code:
    getFormErrors(context).rejectValue("nickname","executives.form.duplicateNickname",new Object[]{admin.getNickname},"defaultmessage hey!");
    thank you all.

    kimbuba

  • #2
    Actually, the way you are trying to do it should work as far as I can see. The getFormErrors() method should pick up on the Errors instance prepared by bindAndValidate(), or if there is no such Errors instance it should create one and expose it in the request or flow scope.

    Maybe you can try to put a breakpoint in ensureFormErrorsExposed() to see what's happening there.

    Erwin

    Comment


    • #3
      Thanks for answering Erwin.
      My testCase found the bindexception error.

      My problem is that i can't show the bindexception on the jstl view.
      With a print on
      Code:
      context.getRequestScope().toString()
      inside the
      Code:
      insert(ReqestContext)
      method i can see my BindException on the request but i can't show it.
      Code:
      &#91;Scope@1b4d679 scopeType = &#91;class org.springframework.webflow.ScopeType.request &#40;0&#41;&#93;, attributes = map&#91;'command' -> it.kimbuba.milkcup.executive.business.AdminValue@fb2ac4&#91;<null>,blam,dk,ks,true,<null>,<null>,&#91;&#93;&#93;, 'org.springframework.validation.BindException.#formObject' -> org.springframework.validation.BindException&#58; BindException&#58; 1 errors; Field error in object 'command' on field 'nickname'&#58; rejected value &#91;blam&#93;; codes &#91;executives.form.duplicateNickname.command.nickname,executives.form.duplicateNickname.nickname,executives.form.duplicateNickname.java.lang.String,executives.form.duplicateNickname&#93;; arguments &#91;blam&#93;; default message &#91;defaultmessage ah ah!&#93;, 'org.springframework.validation.BindException.command' -> org.springframework.validation.BindException&#58; BindException&#58; 1 errors; Field error in object 'command' on field 'nickname'&#58; rejected value &#91;blam&#93;; codes &#91;executives.form.duplicateNickname.command.nickname,executives.form.duplicateNickname.nickname,executives.form.duplicateNickname.java.lang.String,executives.form.duplicateNickname&#93;; arguments &#91;blam&#93;; default message &#91;defaultmessage ah ah!&#93;, '#formObject' -> it.kimbuba.milkcup.executive.business.AdminValue@fb2ac4&#91;<null>,blam,dk,ks,true,<null>,<null>,&#91;&#93;&#93;&#93;&#93;
      I bound on the request a command either and i can show it with
      Code:
      $&#123;command.myProperty&#125;
      But no way to find an error with
      Code:
      $&#123;org.springframework.validation.BindException.command&#125;
      or

      Code:
      $&#123;org.springframework.validation.BindException.#formObject&#125;
      Where am i wrong?

      Thanks!

      kim.

      Comment


      • #4
        Try using the spring:bind or spring:hasBindErrors custom tags.
        http://static.springframework.org/sp...lib/index.html

        Erwin

        Comment


        • #5
          thanks Erwin.
          After some time i found the bug.
          My flow on error called a view that executed a ActionForm's default bind method.
          that bind killed my error with
          Code:
          public Event bind&#40;....
          ...
          setFormErrors&#40;context, binder.getErrors&#40;&#41;&#41;;
          ...
          Thanks.
          Kim

          Comment

          Working...
          X