You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Martin U <uf...@googlemail.com> on 2010/02/05 08:57:50 UTC

How to add and remove css classes the right way?

Hi Folks,

I'am getting totally confused how to add and remove css classes to and form
my text-input-fields on ajax-form-validation.

At first i try to add two css classes step by step:

Iterator<FeedbackMessage> iter =
Session.get().getFeedbackMessages().messages(getFeedbackMessageFilter()).iterator();
if(iter.hasNext()){
indicatorFor.add(new SimpleAttributeModifier("class","validation_error"));
indicatorFor.add(new SimpleAttributeModifier("class", "test"));
}

But gets the Markup only with "class='test' "

How can i add more than one "value" to "class"?

And how can i remove one special css-class from an component if the
validation is okay to this field?


Thanks in Advance for any help.

- Martin

Re: How to add and remove css classes the right way?

Posted by MattyDE <uf...@gmail.com>.
Ah i did it ..... but is this the best way?

@Override
	protected void onValidate() {		
		super.onValidate();
		
		visitFormComponents(new FormComponent.IVisitor() {

			@Override
			public Object formComponent(IFormVisitorParticipant formComponent) {
				Component _c = (Component)formComponent;
				
				if(formComponent instanceof IValidatingComponent){	
					
					
					if(((IValidatingComponent)_c).getField().hasErrorMessage()){
						AttributeAppender _attr = new AttributeAppender("class",new
Model<String>("validation_error"), " "){
							@Override
							public boolean isTemporary() {return true; }
						};
												
						((IValidatingComponent)_c).getField().add(_attr);						
					}
										
				}
				return _c;
			}
		});

		
	}






MattyDE wrote:
> 
> Ohhkay.. i see
> 
> indicatorFor.add(new AttributeAppender("class",new
> Model<String>("validation_error"), " "));
> indicatorFor.add(new AttributeAppender("class",new Model<String>("test"),"
> "));
> 
> did it .. but how can i remove now an attribute from "class" .. or how
> could i access the attributes to replace one?
> 
> 
> 
> 
> 
> MattyDE wrote:
>> 
>> Hello Martin ;)
>> 
>> i tired
>> 
>> indicatorFor.add(new AttributeModifier("class",new
>> Model<String>("validation_error")));
>> inicatorFor.add(new AttributeModifier("class",new
>> Model<String>("test")));
>> 
>> but in the markup no "class" attribute appears?
>> 
>> - Martin
>> 
>> 
>> 
>> 
>> Martin Sachs wrote:
>>> 
>>> Hi Martin
>>> 
>>> user the AttributeModifier or AttributeAppender classes.
>>> 
>>> 
>>> 
>>> Martin
>>> 
>>> Martin U schrieb:
>>>> Hi Folks,
>>>>
>>>> I'am getting totally confused how to add and remove css classes to and
>>>> form
>>>> my text-input-fields on ajax-form-validation.
>>>>
>>>> At first i try to add two css classes step by step:
>>>>
>>>> Iterator<FeedbackMessage> iter =
>>>> Session.get().getFeedbackMessages().messages(getFeedbackMessageFilter()).iterator();
>>>> if(iter.hasNext()){
>>>> indicatorFor.add(new
>>>> SimpleAttributeModifier("class","validation_error"));
>>>> indicatorFor.add(new SimpleAttributeModifier("class", "test"));
>>>> }
>>>>
>>>> But gets the Markup only with "class='test' "
>>>>
>>>> How can i add more than one "value" to "class"?
>>>>
>>>> And how can i remove one special css-class from an component if the
>>>> validation is okay to this field?
>>>>
>>>>
>>>> Thanks in Advance for any help.
>>>>
>>>> - Martin
>>>>
>>>>   
>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/How-to-add-and-remove-css-classes-the-right-way--tp27464616p27465079.html
Sent from the Wicket - User 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: How to add and remove css classes the right way?

Posted by MattyDE <uf...@gmail.com>.
Ohhkay.. i see

indicatorFor.add(new AttributeAppender("class",new
Model<String>("validation_error"), " "));
indicatorFor.add(new AttributeAppender("class",new Model<String>("test"),"
"));

did it .. but how can i remove now an attribute from "class" .. or how could
i access the attributes to replace one?





MattyDE wrote:
> 
> Hello Martin ;)
> 
> i tired
> 
> indicatorFor.add(new AttributeModifier("class",new
> Model<String>("validation_error")));
> inicatorFor.add(new AttributeModifier("class",new Model<String>("test")));
> 
> but in the markup no "class" attribute appears?
> 
> - Martin
> 
> 
> 
> 
> Martin Sachs wrote:
>> 
>> Hi Martin
>> 
>> user the AttributeModifier or AttributeAppender classes.
>> 
>> 
>> 
>> Martin
>> 
>> Martin U schrieb:
>>> Hi Folks,
>>>
>>> I'am getting totally confused how to add and remove css classes to and
>>> form
>>> my text-input-fields on ajax-form-validation.
>>>
>>> At first i try to add two css classes step by step:
>>>
>>> Iterator<FeedbackMessage> iter =
>>> Session.get().getFeedbackMessages().messages(getFeedbackMessageFilter()).iterator();
>>> if(iter.hasNext()){
>>> indicatorFor.add(new
>>> SimpleAttributeModifier("class","validation_error"));
>>> indicatorFor.add(new SimpleAttributeModifier("class", "test"));
>>> }
>>>
>>> But gets the Markup only with "class='test' "
>>>
>>> How can i add more than one "value" to "class"?
>>>
>>> And how can i remove one special css-class from an component if the
>>> validation is okay to this field?
>>>
>>>
>>> Thanks in Advance for any help.
>>>
>>> - Martin
>>>
>>>   
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://old.nabble.com/How-to-add-and-remove-css-classes-the-right-way--tp27464616p27464823.html
Sent from the Wicket - User 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: How to add and remove css classes the right way?

Posted by MattyDE <uf...@gmail.com>.
Hello Martin ;)

i tired

indicatorFor.add(new AttributeModifier("class",new
Model<String>("validation_error")));
inicatorFor.add(new AttributeModifier("class",new Model<String>("test")));

but in the markup no "class" attribute appears?

- Martin




Martin Sachs wrote:
> 
> Hi Martin
> 
> user the AttributeModifier or AttributeAppender classes.
> 
> 
> 
> Martin
> 
> Martin U schrieb:
>> Hi Folks,
>>
>> I'am getting totally confused how to add and remove css classes to and
>> form
>> my text-input-fields on ajax-form-validation.
>>
>> At first i try to add two css classes step by step:
>>
>> Iterator<FeedbackMessage> iter =
>> Session.get().getFeedbackMessages().messages(getFeedbackMessageFilter()).iterator();
>> if(iter.hasNext()){
>> indicatorFor.add(new
>> SimpleAttributeModifier("class","validation_error"));
>> indicatorFor.add(new SimpleAttributeModifier("class", "test"));
>> }
>>
>> But gets the Markup only with "class='test' "
>>
>> How can i add more than one "value" to "class"?
>>
>> And how can i remove one special css-class from an component if the
>> validation is okay to this field?
>>
>>
>> Thanks in Advance for any help.
>>
>> - Martin
>>
>>   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/How-to-add-and-remove-css-classes-the-right-way--tp27464616p27464720.html
Sent from the Wicket - User 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: Simple question: RESTful page parameters

Posted by Igor Vaynberg <ig...@gmail.com>.
mount(new MountedMapper("user", new UrlPathPageParametersEncoder()));

-igor

On Mon, Oct 31, 2011 at 11:34 AM, Sky USC <sk...@hotmail.com> wrote:
>
> Hi This is a simple question with a simple answere I have not yet been able to figure out in wicket 1.5.2. I did get it working in 1.4 but since migration, have been unable to fix.I read the article at https://cwiki.apache.org/WICKET/request-mapping.html but I think I need a bit more explaination (exmple). Desired behavior:* My web page is "WebUser" extends "WebPage"* I would like it to take PageParameters such as: /www.app.com/user/nom/steve/color/green/color/blue In the past, I used successfully with wicket 1.4 :  mountBookmarkablePage( "user" , WebUser.class ) ;Now I tried using with wicket 1.5.2:   getRootRequestMapperAsCompound().add(new MountedMapper("user", WebUser.class));
>  mountPage( "user" , WebUser.class ) ; Can someone help how I can achieve this with wicket 1.5? I want named parameters, and ideally also be able to have multiple parameters for same name.
> I want parameters to be seperated by / and not by the query style"?&="  Thanks!- Sky
>

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


Simple question: RESTful page parameters

Posted by Sky USC <sk...@hotmail.com>.
Hi This is a simple question with a simple answere I have not yet been able to figure out in wicket 1.5.2. I did get it working in 1.4 but since migration, have been unable to fix.I read the article at https://cwiki.apache.org/WICKET/request-mapping.html but I think I need a bit more explaination (exmple). Desired behavior:* My web page is "WebUser" extends "WebPage"* I would like it to take PageParameters such as: /www.app.com/user/nom/steve/color/green/color/blue In the past, I used successfully with wicket 1.4 :  mountBookmarkablePage( "user" , WebUser.class ) ;Now I tried using with wicket 1.5.2:   getRootRequestMapperAsCompound().add(new MountedMapper("user", WebUser.class));
  mountPage( "user" , WebUser.class ) ; Can someone help how I can achieve this with wicket 1.5? I want named parameters, and ideally also be able to have multiple parameters for same name. 
I want parameters to be seperated by / and not by the query style"?&="  Thanks!- Sky
 		 	   		  

Re: How to add and remove css classes the right way?

Posted by ncollette <na...@gmail.com>.
Obviously this is an old thread, but I just wanted to throw out another way
to "remove" a css class whilst preserving any existing css classes.

new SimpleAttributeModifier("class",
String.valueOf(this.getMarkupAttributes().get("class")).replaceFirst("edit",
""));

In the case above - edit was the class I was removing.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-add-and-remove-css-classes-the-right-way-tp1868408p3082769.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: How to add and remove css classes the right way?

Posted by Martin Sachs <sa...@gmail.com>.
Hi Martin

user the AttributeModifier or AttributeAppender classes.



Martin

Martin U schrieb:
> Hi Folks,
>
> I'am getting totally confused how to add and remove css classes to and form
> my text-input-fields on ajax-form-validation.
>
> At first i try to add two css classes step by step:
>
> Iterator<FeedbackMessage> iter =
> Session.get().getFeedbackMessages().messages(getFeedbackMessageFilter()).iterator();
> if(iter.hasNext()){
> indicatorFor.add(new SimpleAttributeModifier("class","validation_error"));
> indicatorFor.add(new SimpleAttributeModifier("class", "test"));
> }
>
> But gets the Markup only with "class='test' "
>
> How can i add more than one "value" to "class"?
>
> And how can i remove one special css-class from an component if the
> validation is okay to this field?
>
>
> Thanks in Advance for any help.
>
> - Martin
>
>   


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