You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by miro <mi...@yahoo.com> on 2008/11/03 21:32:50 UTC
attribute modifier on onclick
I have a link this contains a label , now I want to change the style of
the label whenever user clicks on the link , to do this I override the
method onClick() in link component I am retrieving the label and adding
simpleattributemodifier to the label , but there is no change , when I see
the generated html it does not include the added style , can I change the
style of a component in any of the events of a component ?
--
View this message in context: http://www.nabble.com/attribute-modifier-on-onclick-tp20310246p20310246.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: attribute modifier on onclick
Posted by miro <mi...@yahoo.com>.
I found the problem its because of ListView setReuseItems(boolean
reuseItems) .
by default it is false setting it to true will not create new instances of
my ListItems.
Alex Objelean wrote:
>
> You probably want to use AjaxLink and when the link is clicked - add to
> the target the link itself, in order to see the change.
>
>
> miro wrote:
>>
>> upon debugging i found the constructor MyLink() was getting called
>> after onClick() so any changes I make in onClick to components
>> behaviour will get washed away because its adding the components again
>> , to better understand what happens when a link is clicked ? the
>> component is created again ?
>>
>>
>> here is the code
>> <code>
>> PageableListView batchesListView= new
>> PageableListView("batches",batches,10){
>>
>> /**
>> *
>> */
>> private static final long serialVersionUID = 1L;
>>
>> @Override
>> protected void populateItem(ListItem item) {
>> final BatcheModel batcheModel=(BatcheModel)item.getModelObject();
>>
>>
>> class MyLink extends Link {
>> public MyLink() {
>> super("batch", new Model(batcheModel));
>> add(new Label("name",batcheModel.getName()));
>> add(new Label("date", new Date().toString()));
>> }
>> @Override
>> public void onClick() {
>> final BatcheModel batcheModel=(BatcheModel)getModelObject();
>> AuditsModel auditsModel=null;
>> if(batcheModel.getName().equals("test1")){
>> auditsModel= new AuditsModel("test1","test1","test1");
>> }
>> if(batcheModel.getName().equals("test2")){
>> auditsModel= new AuditsModel("test2","test2","test2");
>> }
>> if(batcheModel.getName().equals("test3")){
>> auditsModel= new AuditsModel("test3","test3","test3");
>> }
>> List<AuditsModel> audits= new ArrayList<AuditsModel>();
>> audits.add(auditsModel);
>> PageableListView pageableListView= (PageableListView)
>> AuditSelectionPage.this.get("audits");
>> pageableListView.setModel(new Model((Serializable)audits));
>> Label label=(Label)get("name");
>> get("name").add(new SimpleAttributeModifier("style",
>> "color:blue;"));
>> get("date").add(new SimpleAttributeModifier("style",
>> "color:blue;"));
>> }
>> }
>>
>> item.add(new MyLink());
>>
>> </code>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/attribute-modifier-on-onclick-tp20310246p20324340.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: attribute modifier on onclick
Posted by Alex Objelean <al...@isdc.ro>.
You probably want to use AjaxLink and when the link is clicked - add to the
target the link itself, in order to see the change.
miro wrote:
>
> upon debugging i found the constructor MyLink() was getting called
> after onClick() so any changes I make in onClick to components
> behaviour will get washed away because its adding the components again
> , to better understand what happens when a link is clicked ? the
> component is created again ?
>
>
> here is the code
> <code>
> PageableListView batchesListView= new
> PageableListView("batches",batches,10){
>
> /**
> *
> */
> private static final long serialVersionUID = 1L;
>
> @Override
> protected void populateItem(ListItem item) {
> final BatcheModel batcheModel=(BatcheModel)item.getModelObject();
>
>
> class MyLink extends Link {
> public MyLink() {
> super("batch", new Model(batcheModel));
> add(new Label("name",batcheModel.getName()));
> add(new Label("date", new Date().toString()));
> }
> @Override
> public void onClick() {
> final BatcheModel batcheModel=(BatcheModel)getModelObject();
> AuditsModel auditsModel=null;
> if(batcheModel.getName().equals("test1")){
> auditsModel= new AuditsModel("test1","test1","test1");
> }
> if(batcheModel.getName().equals("test2")){
> auditsModel= new AuditsModel("test2","test2","test2");
> }
> if(batcheModel.getName().equals("test3")){
> auditsModel= new AuditsModel("test3","test3","test3");
> }
> List<AuditsModel> audits= new ArrayList<AuditsModel>();
> audits.add(auditsModel);
> PageableListView pageableListView= (PageableListView)
> AuditSelectionPage.this.get("audits");
> pageableListView.setModel(new Model((Serializable)audits));
> Label label=(Label)get("name");
> get("name").add(new SimpleAttributeModifier("style",
> "color:blue;"));
> get("date").add(new SimpleAttributeModifier("style",
> "color:blue;"));
> }
> }
>
> item.add(new MyLink());
>
> </code>
>
> Michael Sparer wrote:
>>
>> show us some code
>>
>> miro wrote:
>>>
>>> I have a link this contains a label , now I want to change the style
>>> of the label whenever user clicks on the link , to do this I
>>> override the method onClick() in link component I am retrieving the
>>> label and adding simpleattributemodifier to the label , but there is
>>> no change , when I see the generated html it does not include the added
>>> style , can I change the style of a component in any of the events
>>> of a component ?
>>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/attribute-modifier-on-onclick-tp20310246p20323946.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: attribute modifier on onclick
Posted by miro <mi...@yahoo.com>.
upon debugging i found the constructor MyLink() was getting called after
onClick() so any changes I make in onClick to components behaviour will get
washed away because its adding the components again , to better
understand what happens when a link is clicked ? the component is created
again ?
here is the code
<code>
PageableListView batchesListView= new
PageableListView("batches",batches,10){
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem item) {
final BatcheModel batcheModel=(BatcheModel)item.getModelObject();
class MyLink extends Link {
public MyLink() {
super("batch", new Model(batcheModel));
add(new Label("name",batcheModel.getName()));
add(new Label("date", new Date().toString()));
}
@Override
public void onClick() {
final BatcheModel batcheModel=(BatcheModel)getModelObject();
AuditsModel auditsModel=null;
if(batcheModel.getName().equals("test1")){
auditsModel= new AuditsModel("test1","test1","test1");
}
if(batcheModel.getName().equals("test2")){
auditsModel= new AuditsModel("test2","test2","test2");
}
if(batcheModel.getName().equals("test3")){
auditsModel= new AuditsModel("test3","test3","test3");
}
List<AuditsModel> audits= new ArrayList<AuditsModel>();
audits.add(auditsModel);
PageableListView pageableListView= (PageableListView)
AuditSelectionPage.this.get("audits");
pageableListView.setModel(new Model((Serializable)audits));
Label label=(Label)get("name");
get("name").add(new SimpleAttributeModifier("style", "color:blue;"));
get("date").add(new SimpleAttributeModifier("style", "color:blue;"));
}
}
item.add(new MyLink());
</code>
Michael Sparer wrote:
>
> show us some code
>
> miro wrote:
>>
>> I have a link this contains a label , now I want to change the style
>> of the label whenever user clicks on the link , to do this I
>> override the method onClick() in link component I am retrieving the
>> label and adding simpleattributemodifier to the label , but there is no
>> change , when I see the generated html it does not include the added
>> style , can I change the style of a component in any of the events of
>> a component ?
>>
>
>
--
View this message in context: http://www.nabble.com/attribute-modifier-on-onclick-tp20310246p20320579.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: attribute modifier on onclick
Posted by Michael Sparer <mi...@gmx.at>.
show us some code
miro wrote:
>
> I have a link this contains a label , now I want to change the style
> of the label whenever user clicks on the link , to do this I override
> the method onClick() in link component I am retrieving the label and
> adding simpleattributemodifier to the label , but there is no change ,
> when I see the generated html it does not include the added style , can
> I change the style of a component in any of the events of a component ?
>
-----
Michael Sparer
http://talk-on-tech.blogspot.com
--
View this message in context: http://www.nabble.com/attribute-modifier-on-onclick-tp20310246p20318681.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: attribute modifier on onclick
Posted by Wayne Pope <wa...@googlemail.com>.
not sure but perhaps try modelchanged on the label
On Mon, Nov 3, 2008 at 9:32 PM, miro <mi...@yahoo.com> wrote:
>
> I have a link this contains a label , now I want to change the style of
> the label whenever user clicks on the link , to do this I override
> the
> method onClick() in link component I am retrieving the label and adding
> simpleattributemodifier to the label , but there is no change , when I see
> the generated html it does not include the added style , can I change the
> style of a component in any of the events of a component ?
> --
> View this message in context:
> http://www.nabble.com/attribute-modifier-on-onclick-tp20310246p20310246.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
>
>