Re: highlight invalid fields with custom Validation Framework?

2012-11-25 Thread James Selvakumar
Martin,

Thank you so much. I was exactly in the position where delta458 was and
almost got through with it.
After following your suggestions, the ValidationMsgBehavior looks like this:

pre
public class ValidationMsgBehavior extends Behavior
{
@Override
public void onRendered(Component c)
{
FormComponent fc = (FormComponent) c;
if (!fc.isValid()) {
String error;
if (fc.hasFeedbackMessage()) {
error =
fc.getFeedbackMessages().first(FeedbackMessage.ERROR).toString();
} else {
error = Your input is invalid.;
}
fc.getResponse().write(
div class=\validationErrorMessage\ + error +
/div);
}
}
}
/pre

I'm using Wicket 6.3.0 and there is no onRendered method in Behavior.
I should be using afterRender(Component component) now, right?
That will make this code compatible with the latest wicket version.


On Wed, Oct 17, 2012 at 3:07 PM, Martin Grigorov mgrigo...@apache.orgwrote:

 On Wed, Oct 17, 2012 at 8:22 AM, delta458 delta...@hotmail.com wrote:
  Hi Martin,
  thanks so much for the replies... almost done, some little questions
 still
  there.. I got it working, could you verify that its right what I made? :)
 
  1)
  *//Had Error: Wrong number of type arguments, required 2 - It works when
 I
  do  IVisitorComponent,Void ;-)

 Trust the compiler and follow his recommendations ;-)

  public class ShinyFormVisitor implements
 IVisitorComponent,Serializable {*
 
  Set visited = new HashSet();
 
  public void component(final Component c, final IVisitVoid visit
  /*[2]*/) {
  if (!visited.contains(c)) {
  visited.add(c);
  c.add(new RequiredBorder());
  c.add(new ValidationMsgBehavior());
  c.add(new ErrorHighlightBehavior());
  }
  }
 
  ...
 
  private class ValidationMsgBehavior extends Behavior {
 
  public void onRendered(Component c) {
  FormComponent fc = (FormComponent) c;
  if (!fc.isValid()) {
  String error;
  if (fc.hasFeedbackMessage()) {
* //Had error, now working with this.. thats right?
  error =
  fc.getFeedbackMessages().first().getLevelAsString();*

 fc.getFeedbackMessages().first(FeedbackMessage.LEVEL_ERROR).toString();

 Or you may use the default registered converter to transform it to
 String. But this is more advanced and most probably you don't need it.

 
  } else {
  error = Your input is invalid.;
  }
  fc.getResponse().write(
  div class=\validationMsg\ + error +
 /div);
  }
  }
  }
  }
 
 
  2) Do you know any good wicket tutorials/example where I can learn how to
  work with customized FeedbackMessages?

 The source code is the best. It is really simple.
 Check
 https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/FeedbackPanel.java

 
  thanks..
 
 
 
 
  --
  View this message in context:
 http://apache-wicket.1842946.n4.nabble.com/highlight-invalid-fields-with-custom-Validation-Framework-tp4652949p4653024.html
  Sent from the Users forum mailing list archive at Nabble.com.
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 



 --
 Martin Grigorov
 jWeekend
 Training, Consulting, Development
 http://jWeekend.com

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




-- 
Thanks  regards
James Selvakumar


Re: highlight invalid fields with custom Validation Framework?

2012-11-25 Thread Martin Grigorov
On Mon, Nov 26, 2012 at 4:50 AM, James Selvakumar ja...@mcruncher.comwrote:

 Martin,

 Thank you so much. I was exactly in the position where delta458 was and
 almost got through with it.
 After following your suggestions, the ValidationMsgBehavior looks like
 this:

 pre
 public class ValidationMsgBehavior extends Behavior
 {
 @Override
 public void onRendered(Component c)
 {
 FormComponent fc = (FormComponent) c;
 if (!fc.isValid()) {
 String error;
 if (fc.hasFeedbackMessage()) {
 error =
 fc.getFeedbackMessages().first(FeedbackMessage.ERROR).toString();
 } else {
 error = Your input is invalid.;
 }
 fc.getResponse().write(
 div class=\validationErrorMessage\ + error +
 /div);
 }
 }
 }
 /pre



 I'm using Wicket 6.3.0 and there is no onRendered method in Behavior.
 I should be using afterRender(Component component) now, right?


Right.


 That will make this code compatible with the latest wicket version.


 On Wed, Oct 17, 2012 at 3:07 PM, Martin Grigorov mgrigo...@apache.org
 wrote:

  On Wed, Oct 17, 2012 at 8:22 AM, delta458 delta...@hotmail.com wrote:
   Hi Martin,
   thanks so much for the replies... almost done, some little questions
  still
   there.. I got it working, could you verify that its right what I made?
 :)
  
   1)
   *//Had Error: Wrong number of type arguments, required 2 - It works
 when
  I
   do  IVisitorComponent,Void ;-)
 
  Trust the compiler and follow his recommendations ;-)
 
   public class ShinyFormVisitor implements
  IVisitorComponent,Serializable {*
  
   Set visited = new HashSet();
  
   public void component(final Component c, final IVisitVoid visit
   /*[2]*/) {
   if (!visited.contains(c)) {
   visited.add(c);
   c.add(new RequiredBorder());
   c.add(new ValidationMsgBehavior());
   c.add(new ErrorHighlightBehavior());
   }
   }
  
   ...
  
   private class ValidationMsgBehavior extends Behavior {
  
   public void onRendered(Component c) {
   FormComponent fc = (FormComponent) c;
   if (!fc.isValid()) {
   String error;
   if (fc.hasFeedbackMessage()) {
 * //Had error, now working with this.. thats right?
   error =
   fc.getFeedbackMessages().first().getLevelAsString();*
 
  fc.getFeedbackMessages().first(FeedbackMessage.LEVEL_ERROR).toString();
 
  Or you may use the default registered converter to transform it to
  String. But this is more advanced and most probably you don't need it.
 
  
   } else {
   error = Your input is invalid.;
   }
   fc.getResponse().write(
   div class=\validationMsg\ + error +
  /div);
   }
   }
   }
   }
  
  
   2) Do you know any good wicket tutorials/example where I can learn how
 to
   work with customized FeedbackMessages?
 
  The source code is the best. It is really simple.
  Check
 
 https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/FeedbackPanel.java
 
  
   thanks..
  
  
  
  
   --
   View this message in context:
 
 http://apache-wicket.1842946.n4.nabble.com/highlight-invalid-fields-with-custom-Validation-Framework-tp4652949p4653024.html
   Sent from the Users forum mailing list archive at Nabble.com.
  
   -
   To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
   For additional commands, e-mail: users-h...@wicket.apache.org
  
 
 
 
  --
  Martin Grigorov
  jWeekend
  Training, Consulting, Development
  http://jWeekend.com
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 
 


 --
 Thanks  regards
 James Selvakumar




-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com http://jweekend.com/


Re: highlight invalid fields with custom Validation Framework?

2012-10-17 Thread delta458
Hi Martin,
thanks so much for the replies... almost done, some little questions still
there.. I got it working, could you verify that its right what I made? :)

1)
*//Had Error: Wrong number of type arguments, required 2 - It works when I
do  IVisitorComponent,Void ;-) 
public class ShinyFormVisitor implements IVisitorComponent,Serializable {*

Set visited = new HashSet();

public void component(final Component c, final IVisitVoid visit
/*[2]*/) {
if (!visited.contains(c)) {
visited.add(c);
c.add(new RequiredBorder());
c.add(new ValidationMsgBehavior());
c.add(new ErrorHighlightBehavior());
}
}

...

private class ValidationMsgBehavior extends Behavior {

public void onRendered(Component c) {
FormComponent fc = (FormComponent) c;
if (!fc.isValid()) {
String error;
if (fc.hasFeedbackMessage()) {
  * //Had error, now working with this.. thats right?
error =
fc.getFeedbackMessages().first().getLevelAsString();*
   
} else {
error = Your input is invalid.;
}
fc.getResponse().write(
div class=\validationMsg\ + error + /div);
}
}
}
}


2) Do you know any good wicket tutorials/example where I can learn how to
work with customized FeedbackMessages?

thanks..




--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/highlight-invalid-fields-with-custom-Validation-Framework-tp4652949p4653024.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: highlight invalid fields with custom Validation Framework?

2012-10-17 Thread Martin Grigorov
On Wed, Oct 17, 2012 at 8:22 AM, delta458 delta...@hotmail.com wrote:
 Hi Martin,
 thanks so much for the replies... almost done, some little questions still
 there.. I got it working, could you verify that its right what I made? :)

 1)
 *//Had Error: Wrong number of type arguments, required 2 - It works when I
 do  IVisitorComponent,Void ;-)

Trust the compiler and follow his recommendations ;-)

 public class ShinyFormVisitor implements IVisitorComponent,Serializable {*

 Set visited = new HashSet();

 public void component(final Component c, final IVisitVoid visit
 /*[2]*/) {
 if (!visited.contains(c)) {
 visited.add(c);
 c.add(new RequiredBorder());
 c.add(new ValidationMsgBehavior());
 c.add(new ErrorHighlightBehavior());
 }
 }

 ...

 private class ValidationMsgBehavior extends Behavior {

 public void onRendered(Component c) {
 FormComponent fc = (FormComponent) c;
 if (!fc.isValid()) {
 String error;
 if (fc.hasFeedbackMessage()) {
   * //Had error, now working with this.. thats right?
 error =
 fc.getFeedbackMessages().first().getLevelAsString();*

fc.getFeedbackMessages().first(FeedbackMessage.LEVEL_ERROR).toString();

Or you may use the default registered converter to transform it to
String. But this is more advanced and most probably you don't need it.


 } else {
 error = Your input is invalid.;
 }
 fc.getResponse().write(
 div class=\validationMsg\ + error + /div);
 }
 }
 }
 }


 2) Do you know any good wicket tutorials/example where I can learn how to
 work with customized FeedbackMessages?

The source code is the best. It is really simple.
Check 
https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/html/panel/FeedbackPanel.java


 thanks..




 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/highlight-invalid-fields-with-custom-Validation-Framework-tp4652949p4653024.html
 Sent from the Users forum mailing list archive at Nabble.com.

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




-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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



Re: highlight invalid fields with custom Validation Framework?

2012-10-16 Thread Martin Grigorov
On Mon, Oct 15, 2012 at 11:17 PM, delta458 delta...@hotmail.com wrote:
 Alright, I have something like this now: Problems/Errors are *bold*
 *
 //Here is a problem with the class: it says: ShinyFormVisitor is not
 abstract and does not override abstract method component(Object,IVisit) in
 IVisitor*
 public class *ShinyFormVisitor* implements IVisitor, Serializable {

Make it : implements IVisitorComponent, Serializable


 Set visited = new HashSet();

 *//Is that ok now? with IVisitor for wicket 6.0?*
 public void component(final Component c, final IVisitVoid visit) {
 if (!visited.contains(c)) {
 visited.add(c);
 c.add(new RequiredBorder());
 c.add(new ValidationMsgBehavior());
 c.add(new ErrorHighlightBehavior());
 }
visit.dontGoDeeper();

remove that ^^^. Let it go deeper

 }

 private class RequiredBorder extends BorderBehavior {

 public void renderAfter(Component component) {
 FormComponent fc = (FormComponent) component;
 if (fc.isRequired()) {
 super.afterRender(component);
 }
 }
 }

 private class ValidationMsgBehavior extends Behavior {

 public void onRendered(Component c) {
 FormComponent fc = (FormComponent) c;
 if (!fc.isValid()) {
 String error;
 if (fc.hasFeedbackMessage()) {
 *//getFeedbackMessage() could not be found*
 error =
 fc.*getFeedbackMessage()*.getMessage().toString();

fc.getFeedbackMessages().getFirst(Level.Error).toString  (or something
similar). Use an IDE to see the method signatures.

 } else {
 error = Your input is invalid.;
 }
 fc.getResponse().write(
 div class=\validationMsg\ + error + /div);
 }
 }
 }

 private class ErrorHighlightBehavior extends Behavior {

 @Override
 public void onComponentTag(Component c, ComponentTag tag) {
 FormComponent fc = (FormComponent) c;
 if (!fc.isValid()) {
 tag.put(class, error);
 }
 }
 }
 }



 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/highlight-invalid-fields-with-custom-Validation-Framework-tp4652949p4652990.html
 Sent from the Users forum mailing list archive at Nabble.com.

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




-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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



Re: highlight invalid fields with custom Validation Framework?

2012-10-15 Thread Bert
Hi,

are you looking for a generic way to highlight invalid components? If
so, have a look at
https://code.google.com/p/londonwicket/downloads/detail?name=LondonWicket-FormsWithFlair.pdf

as an inspiration point. Depending on the wicket version, you might
have to adopt the code a bit.

Hope that helps

On Sun, Oct 14, 2012 at 12:37 PM, delta458 delta...@hotmail.com wrote:
 Hello,

 How can I highlight my form fields when I use a custom validation framework.
 The validation process itself is already working. I am using Oval Validation
 Framework as my custom validation framework.

 Code of JAVA File:
 ...
public InvoiceForm() {
 setPageTitle(Invoice);


 CompoundPropertyModelInvoice formModel = new
 CompoundPropertyModelInvoice(new Rechnung());
 FormInvoice form = new Form(inputForm, formModel) {
 @Override
 public void onSubmit() {
 System.out.println(Working. +
 getDefaultModelObjectAsString());
 }

* //Custom Validation starts here. Using Oval Validation
 Framework*
 @Override
 public void onValidateModelObjects() {
 *Validator val = new Validator();
 ListConstraintViolation violations =
 val.validate(getDefaultModelObject());
 *
 if (violations.size()  0) {
 System.out.println(Object  +
 getDefaultModelObjectAsString() +  is invalid.);
 }
 }
 };

 form.add(new TextFieldString(Empfänger));
 form.add(new TextFieldString(Details));
 ...




 Code of HTML File:


 It would be great if you give me a short example on how to do that. Or links
 with good tutorials?



 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/highlight-invalid-fields-with-custom-Validation-Framework-tp4652949.html
 Sent from the Users forum mailing list archive at Nabble.com.

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


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



Re: highlight invalid fields with custom Validation Framework?

2012-10-15 Thread Martin Grigorov
What exactly doesn't work ?

On Mon, Oct 15, 2012 at 1:26 PM, delta458 delta...@hotmail.com wrote:
 Yes I tried it. But its not working with the wicket 6.0 version...
 As a newbie its hard to adopt for me, where can I see the new changes? or
 what I should change?



 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/highlight-invalid-fields-with-custom-Validation-Framework-tp4652949p4652970.html
 Sent from the Users forum mailing list archive at Nabble.com.

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




-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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



Re: highlight invalid fields with custom Validation Framework?

2012-10-15 Thread delta458
I used the ShinyFormVisitor principle as described in the pdf: and I get
following errors(in bold):

public class ShinyFormVisitor implements IVisitor, Serializable {

Set visited = new HashSet();

public Object component(Component c) {
if (!visited.contains(c)) {
visited.add(c);
c.setComponentBorder(new RequiredBorder());
c.add(new ValidationMsgBehavior());
c.add(new ErrorHighlightBehavior());
}
*//CONTINUE_TRAVERSAL could not be found*
return *IVisitor.CONTINUE_TRAVERSAL*;
}

private class RequiredBorder extends BorderBehavior {

public void renderAfter(Component component) {
FormComponent fc = (FormComponent) component;
if (fc.isRequired()) {
super.afterRender(component);
}
}
}

*//AbstractBehaviour could not be found*
private class ValidationMsgBehavior extends *AbstractBehavior* {

public void onRendered(Component c) {
FormComponent fc = (FormComponent) c;
if (!fc.isValid()) {
String error;
if (fc.hasFeedbackMessage()) {
*//getFeedbackMessage() could not be found*
error =*
fc.getFeedbackMessage()*.getMessage().toString();
} else {
error = Your input is invalid.;
}
fc.getResponse().write(
div class=\validationMsg\ + error + /div);
}
}
}

*//AbstractBehaviour could not be found*
private class ErrorHighlightBehavior extends *AbstractBehavior* {

public void onComponentTag(Component c, ComponentTag tag) {
FormComponent fc = (FormComponent) c;
if (!fc.isValid()) {
tag.put(class, error);
}
}
}
}



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/highlight-invalid-fields-with-custom-Validation-Framework-tp4652949p4652978.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: highlight invalid fields with custom Validation Framework?

2012-10-15 Thread Martin Grigorov
On Mon, Oct 15, 2012 at 4:58 PM, delta458 delta...@hotmail.com wrote:
 I used the ShinyFormVisitor principle as described in the pdf: and I get
 following errors(in bold):

 public class ShinyFormVisitor implements IVisitor, Serializable {

 Set visited = new HashSet();

 public Object component(Component c) {
 if (!visited.contains(c)) {
 visited.add(c);
 c.setComponentBorder(new RequiredBorder());

Since RequiredBorder is a behavior, you can just #add() it.

 c.add(new ValidationMsgBehavior());
 c.add(new ErrorHighlightBehavior());
 }
 *//CONTINUE_TRAVERSAL could not be found*
 return *IVisitor.CONTINUE_TRAVERSAL*;

IVisitor has been improved for Wicket 1.5.0.
Example:
new IVisitorComponent, Void()
{
public void component(final Component component, final 
IVisitVoid visit)
{
add(component);
visit.dontGoDeeper();
}
});

I.e. you need to use visit#XYZ methods to stop the visitor. Don't call
anything and it will continue.

 }

 private class RequiredBorder extends BorderBehavior {

 public void renderAfter(Component component) {
 FormComponent fc = (FormComponent) component;
 if (fc.isRequired()) {
 super.afterRender(component);
 }
 }
 }

 *//AbstractBehaviour could not be found*
 private class ValidationMsgBehavior extends *AbstractBehavior* {

AbstractBehavior is renamed to Behavior.


 public void onRendered(Component c) {
 FormComponent fc = (FormComponent) c;
 if (!fc.isValid()) {
 String error;
 if (fc.hasFeedbackMessage()) {
 *//getFeedbackMessage() could not be found*
 error =*
 fc.getFeedbackMessage()*.getMessage().toString();
 } else {
 error = Your input is invalid.;
 }
 fc.getResponse().write(
 div class=\validationMsg\ + error + /div);
 }
 }
 }

 *//AbstractBehaviour could not be found*
 private class ErrorHighlightBehavior extends *AbstractBehavior* {

 public void onComponentTag(Component c, ComponentTag tag) {
 FormComponent fc = (FormComponent) c;
 if (!fc.isValid()) {
 tag.put(class, error);
 }
 }
 }
 }

You face all these problems because you migrate code from version X to
version X + Y, where Y is  1, i.e. you need to read the migration
guides for all the steps.
Or just ask here and we will try to help you :-)




 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/highlight-invalid-fields-with-custom-Validation-Framework-tp4652949p4652978.html
 Sent from the Users forum mailing list archive at Nabble.com.

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




-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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



Re: highlight invalid fields with custom Validation Framework?

2012-10-15 Thread delta458
Alright, I have something like this now: Problems/Errors are *bold*
*
//Here is a problem with the class: it says: ShinyFormVisitor is not
abstract and does not override abstract method component(Object,IVisit) in
IVisitor*
public class *ShinyFormVisitor* implements IVisitor, Serializable {

Set visited = new HashSet();

*//Is that ok now? with IVisitor for wicket 6.0?*
public void component(final Component c, final IVisitVoid visit) {
if (!visited.contains(c)) {
visited.add(c);
c.add(new RequiredBorder());
c.add(new ValidationMsgBehavior());
c.add(new ErrorHighlightBehavior());
}
   visit.dontGoDeeper();
}

private class RequiredBorder extends BorderBehavior {

public void renderAfter(Component component) {
FormComponent fc = (FormComponent) component;
if (fc.isRequired()) {
super.afterRender(component);
}
}
}

private class ValidationMsgBehavior extends Behavior {

public void onRendered(Component c) {
FormComponent fc = (FormComponent) c;
if (!fc.isValid()) {
String error;
if (fc.hasFeedbackMessage()) {
*//getFeedbackMessage() could not be found*
error =
fc.*getFeedbackMessage()*.getMessage().toString();
} else {
error = Your input is invalid.;
}
fc.getResponse().write(
div class=\validationMsg\ + error + /div);
}
}
}

private class ErrorHighlightBehavior extends Behavior {

@Override
public void onComponentTag(Component c, ComponentTag tag) {
FormComponent fc = (FormComponent) c;
if (!fc.isValid()) {
tag.put(class, error);
}
}
}
}



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/highlight-invalid-fields-with-custom-Validation-Framework-tp4652949p4652990.html
Sent from the Users forum mailing list archive at Nabble.com.

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