You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by delta458 <de...@hotmail.com> on 2012/11/04 03:08:05 UTC

Handle feedback-Messages with a custom validation framework

Hi all,

I am using my own validation, but the view of the form (e.g. if a component
is invalid) should be highlighted or customized within wicket...

So e.g. I have my Wicket Form

/<form wicket:id="inputForm">
         <p>
             <label for="Recipient">Recipient</label>
             <input wicket:id="Recipient" id="Recipient" type="text"
size="40"/>
         </p>
         <p>
             <label for="Details">Details</label>
             <input wicket:id="Details" id="Details" type="text" size="40"/>
         </p>
</form>/

Then I have my Form.java: Here I set the values of my Java Object "Invoice"
and use *onValidateModelObjects* to override the wicket validation and use
my own validation... This method just calls a simple own created
ValidatorObject that takes care of the validation...
/
public InvoiceForm() {
    ...

    Form<Invoice> form = new Form("inputForm", formModel) {
        /*
         * Validation takes place here
         */
        @Override
        public void onValidateModelObjects() {
            ValidationProcess vp = new ValidationProcess();
            vp.validate("Rules.js", r);
            msg = "";
            if (vp.getConstraintViolations().size() > 0) {

                for (String s : vp.getConstraintViolations()) {
                    msg = msg + s;
                }
            } else {
                msg = "no errors.";
            }
        }
    };

    //adding Textfields to the Form etc...

...
}/

What I need: Above you can see that my errorMessages will be saved into the
msg String! Now what I want is Wicket to take this String and apply it to
the Wicket FeedBackMessage System or however...

*1. I need to get the component that will be rendered at the moment...
2. I have to set the error Message of this component to my component...

how can I do that?*

I guess I need to override some methods, but I dont know which ones and
where...




--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Handle-feedback-Messages-with-a-custom-validation-framework-tp4653599.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Handle feedback-Messages with a custom validation framework

Posted by delta458 <de...@hotmail.com>.
I already got it working... with the following code:

/...
//Textfields or Form Components GO HERE...

        @Override
        public void onValidateModelObjects() {
            ValidationProcess vp = new ValidationProcess();
            vp.validate("Rules.js", r);
            msg = "";
            if (vp.getConstraintViolations().size() > 0) {

                for (String s : vp.getConstraintViolations()) {
                    if (s.contains(";")) {
                        String[] splitted = s.split(";");
                        String elementname = splitted[0];
                        String errorMessage = splitted[1];

                        if (elementname.equals("price")) {
                            //SET Error of Component, will be automatically
display by FeedbackPanel...
                            price.error(elementname + " " + errorMessage +
". ");
                          } else if (elementname.equals("recipient")) {
                            recipient.error(elementname + " " +
errorMessage);
                        }
                    }
                }
            }
        }

//Rest of the Code/



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Handle-feedback-Messages-with-a-custom-validation-framework-tp4653599p4653605.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org