Reputation: 554
I've got a problem with creating new Tabs in Wicket on Runtime. When I add a new tab to the list of Tabs of my AjaxTabbedBar, I don't see any changes on the screen, maybe you can help me?
ExamplePage extends Webpage:
private AjaxTabbedPanel<AbstractTab> myTabBar;
tabs = new ArrayList<AbstractTab>();
tabs.add(new AbstractTab(new Model<String>("Übersicht")) {
private static final long serialVersionUID = 1L;
@Override
public Panel getPanel(String panelId) {
if (myOverviewTab == null) myOverviewTab = new OverviewTab(panelId, getInstance());
return myOverviewTab;
}
});
tabs.add(new AbstractTab(new Model<String>("Details")) {
private static final long serialVersionUID = 1L;
@Override
public Panel getPanel(String panelId) {
if (myDetailTab == null) myDetailTab = new DetailTab(panelId);
return myDetailTab;
}
});
myTabBar = new AjaxTabbedPanel<AbstractTab>("tabs", tabs);
add(myTabBar);
This is where I create the tabs on start and here comes my Runtimeaddition
public void newDetailTab(AjaxRequestTarget target){
System.out.println("newDetailtab");
tabs.add(new AbstractTab(new Model<String>("Details")) {
private static final long serialVersionUID = 1L;
@Override
public Panel getPanel(String panelId) {
return new DetailTab(panelId);
}
});
myTabBar.setSelectedTab(myTabBar.getSelectedTab()+1);
target.add(myTabBar);
}
So in the last line I want to change my actual tab, but actually it doesn't works. What makes me wonder is that the first tab has the number -1 (myTabBar.getSelectedtTab()), is this an error?
i also tried to update my tabbar with an AjaxRequestTarget, but there come different errors: cant update a page or Component with id [[tabs28]] was not found while trying to perform...
Hope you can help me.
edit: I found some people on google with an similiar problem, they tried to use LoadabledetachableModel... i just dont really know how to include this because its abstract, and i dont really know how to fill the methods these model wants to use...
Upvotes: 1
Views: 919
Reputation: 1235
Generally you should add the new tab and then update the entire AjaxTabbedPanel with the AjaxRequestTarget.
"Cannot update component with id=XY" most of the time is indicating that you are missing setOutputMarkupPlaceholderTag(true)
on the component you are trying to update via ajax.
Upvotes: 0
Reputation: 554
So, i got it... Finally i had to use the AjaxRequestTarget from my function from the other class to refresh it directly... When i give that as a parameter there seems to be a fault. I think that this is the point but i'm not totally sure because i changed a lot :)
Upvotes: 1
Reputation: 5681
TabbedPanel starts out with -1 for its selected tab. On rending it will automatically select the first visible tab.
It seems to me you're working on a new TabbedPanel instance in #newDetailTab().
Upvotes: 0