Reputation: 860
So I do have my
public class MyClass extends WebPage {
static AjaxFallbackLink ddd = null;
static AjaxFallbackLink dddd = null;
(...) }
and in constructor I do have :
ddd = new AjaxFallbackLink("previous") {
@Override
public void onClick(AjaxRequestTarget target) {
//
}
};
ddd.setOutputMarkupId(true);
ddd.setOutputMarkupPlaceholderTag(true);
ddd.setVisible(false);
add(ddd);
now I want to create a method which will change the visibility of this item. However, calling ddd.setVisible(true); in this method does not work.
any sollutions?
Upvotes: 0
Views: 3649
Reputation: 383
Robert's answer is generally considered more correct, however I will provide an alternative.
You are close on your implementation, but to do the update you have to call target.add(myLink);
to get the ajax refresh of myLink
(In earlier versions of Wicket it is target.addComponent()
).
To change the visiblity with a method, you will have to pass an AjaxRequestTarget
. Within the onClick
methods for an AjaxButton
or AjaxLink
you can call the following method:
private void updateVisibility(AjaxRequestTarget target, AjaxLink myLink, Boolean isVisible) {
myLink.setVisible(isVisible);
target.add(myLink);
}
Hope that helps!
Upvotes: 1
Reputation: 16131
Create your link like this adn set the condition where in should be visible in the onConfigure()
method:
AjaxLink myLink = new AjaxLink("myLink") {
@Override
public void onClick(AjaxRequestTarget target) {
//click stuff done here
}
@Override
protected void onConfigure() {
super.onConfigure();
setVisible(hereTheVisibleCondition);
}
};
This way whenever the link get's rendered it will be made visible or not depending by the condition.
Upvotes: 4