Re: editing response in onComponentTag

2015-06-05 Thread Martin Grigorov
Hi,

See
https://code.google.com/p/londonwicket/downloads/detail?name=LondonWicket-FormsWithFlair.pdfcan=2q=


Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Thu, Jun 4, 2015 at 6:59 PM, msalman mohammad_sal...@yahoo.com wrote:

 Thanks so much for your reply.

 I tried to do it as following.  But could not make it work. Obviously I
 have
 no idea what I am doing. I would appreciate very much if you will help me
 out here.  Thanks.

 private static class RequiredLabel extends SimpleFormComponentLabel
 {
 private static final long serialVersionUID =
 5132250047993256659L;

 //private boolean required;
 FormComponent fc;
 Behavior behaviour;
 boolean behaviourAdded;

 public RequiredLabel(String id, FormComponent fc)
 {
 super(id, fc);
 //this.required = fc.isRequired();
 this.fc = fc;

 behaviour = new Behavior() {

 public void onBeforeRender() {
 getResponse().write(*);
 // Can't remove the previously
 added red asterisk
 }



 public void beforeRender() {
 getResponse().write(*);
 // does not add anything.
 }
 };
 }


 /*
 @Override
 protected void onComponentTag(ComponentTag tag)
 {
 super.onComponentTag(tag);
 if (fc.isRequired()) {
 getResponse().write(*);
 }
 }*/

 @Override
 protected void onBeforeRender() {
 super.onBeforeRender();

 if (fc.isRequired()) {
 if (!behaviourAdded) {
 add(behaviour);
 behaviourAdded = true;
 }
 }
 else {
 if (behaviourAdded) {
 remove(behaviour);
 behaviourAdded = false;
 }
 }
 }
 }


 --
 View this message in context:
 http://apache-wicket.1842946.n4.nabble.com/editing-response-in-onComponentTag-tp4671062p4671076.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: editing response in onComponentTag

2015-06-04 Thread msalman
Thanks so much for your reply.  

I tried to do it as following.  But could not make it work. Obviously I have
no idea what I am doing. I would appreciate very much if you will help me
out here.  Thanks.

private static class RequiredLabel extends SimpleFormComponentLabel
{
private static final long serialVersionUID = 
5132250047993256659L;

//private boolean required;
FormComponent fc;
Behavior behaviour;
boolean behaviourAdded;

public RequiredLabel(String id, FormComponent fc)
{
super(id, fc);
//this.required = fc.isRequired();
this.fc = fc;

behaviour = new Behavior() {

public void onBeforeRender() {
getResponse().write(*); 
// Can't remove the previously added 
red asterisk
}



public void beforeRender() {

getResponse().write(*); 
// does not add anything.
}
};
}


/*
@Override
protected void onComponentTag(ComponentTag tag)
{
super.onComponentTag(tag);
if (fc.isRequired()) {
getResponse().write(*); 
}
}*/

@Override
protected void onBeforeRender() {
super.onBeforeRender();

if (fc.isRequired()) {  
if (!behaviourAdded) {
add(behaviour);
behaviourAdded = true;
}
}
else {  
if (behaviourAdded) {
remove(behaviour);
behaviourAdded = false;
}
}
}   
}


--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/editing-response-in-onComponentTag-tp4671062p4671076.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: editing response in onComponentTag

2015-06-04 Thread Martin Grigorov
Hi,

Better use a Behavior that is attached to SimpleFormComponentLabel.
Use #beforeRender() to prepend the asterisk.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Thu, Jun 4, 2015 at 5:14 AM, msalman mohammad_sal...@yahoo.com wrote:

 Please see the following code:

 private static class RequiredLabel extends SimpleFormComponentLabel
 {
 private static final long serialVersionUID =
 5132250047993256659L;

 //private boolean required;
 FormComponent fc;

 public RequiredLabel(String id, FormComponent fc)
 {
 super(id, fc);
 //this.required = fc.isRequired();
 this.fc = fc;
 }

 @Override
 protected void onComponentTag(ComponentTag tag)
 {
 super.onComponentTag(tag);
 if (fc.isRequired()) {
 getResponse().write(*);
 }
 else {
  // ?? how do I remove the previously
 placed
 *
 }
 }
 }

 RequiredLabel is a label that is used with a FormComponent. It is used to
 put the red asterisk to show that input to the field is required.   But
 what
 happens is that on an ajax request the red asterisks keep on piling up.
 And
 I have a case where the field may be changed to be not required.   How do I
 remove the previosly placed red asterisk?

 Thanks.


 --
 View this message in context:
 http://apache-wicket.1842946.n4.nabble.com/editing-response-in-onComponentTag-tp4671062.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




editing response in onComponentTag

2015-06-03 Thread msalman
Please see the following code:

private static class RequiredLabel extends SimpleFormComponentLabel
{
private static final long serialVersionUID = 
5132250047993256659L;

//private boolean required;
FormComponent fc;

public RequiredLabel(String id, FormComponent fc)
{
super(id, fc);
//this.required = fc.isRequired();
this.fc = fc;
}

@Override
protected void onComponentTag(ComponentTag tag)
{
super.onComponentTag(tag);
if (fc.isRequired()) {
getResponse().write(*); 
}
else {
 // ?? how do I remove the previously placed
*
}
}
}

RequiredLabel is a label that is used with a FormComponent. It is used to
put the red asterisk to show that input to the field is required.   But what
happens is that on an ajax request the red asterisks keep on piling up.  And
I have a case where the field may be changed to be not required.   How do I
remove the previosly placed red asterisk?

Thanks. 


--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/editing-response-in-onComponentTag-tp4671062.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