You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by msj121 <ms...@gmail.com> on 2011/02/01 16:51:34 UTC

Re: Dynamic tab question - now to pass a model to the panel?

I don't quite understand the problem... some code might help. But why can't
you do something like the following:

tabs.add(new AbstractTab(item.getModel()) {
     public Panel getPanel(String panelId) {
         return new AlbumPanel(panelId, );// can be item.getModelObject() or
something
     }
}); 

The above assumes your inside some sort of Wicket Repeater (I assumed this
as you mentioned it was dynamic). Like I said, some more code might help.

nimmy wrote:
> 
> Hi all,
> 
> I'm having a bit of confusion with dynamic tabs and would appreciate your
> help.
> 
> My page has a LDM model. The model wraps an AlbumGroup object, which has a
> list of Album objects.
> 
> I'm creating a tab for each Album object by extending AbstractTab. I'm
> passing in a Model<Album> as a constructor to the tab. This model is used
> to set the title of the tab and should also be used to populate the
> contents of the tab panel.
> 
> How can I pass the Model<Album> to the tab Panel?
> 
> I don't think I can hold the model as an instance variable in the Tab
> until the getPanel() method is called as detach will never be called on
> the LDM.
> 
> I cannot simply implement the IDetachable interface because AbstractTab is
> not a component and detach will not be called on it.
> 
> Am I overthinking the LDM?
> 
> Cheers,
> Nim
> 
> 

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Dynamic-tab-question-now-to-pass-a-model-to-the-panel-tp3250387p3251937.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: Dynamic tab question - now to pass a model to the panel?

Posted by msj121 <ms...@gmail.com>.
the method .detach() or some variation should be called on every Loadable
Detachable Model (LDM) if your model is being used as a default model to any
component in the page hierarchy. To make this LDM your page model, I think
there is a trick in the sense you should call super(<model>), and not just
set the page's default model. It should be detached automatically.

The best way is probably to test the code with a breakpoint or override the
method and print with log4j or something....

Sorry I misunderstood the question.

Matthew
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Dynamic-tab-question-now-to-pass-a-model-to-the-panel-tp3250387p3252947.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: Dynamic tab question - now to pass a model to the panel?

Posted by nimmy <ni...@hotmail.com>.
Hi,

Thanks for your reply. I'm pretty much doing what you suggested but have a
concrete Tab class as it is reused on another page:

public class AlbumTab extends AbstractTab {

	private static final long serialVersionUID = 1L;
	private IModel<Album> model;

	public AlbumTab(IModel<Album> model) {
		super(new PropertyModel<String>(model, "name"));
		this.model = model;
	}

	@Override
	public Panel getPanel(String id) {
		return new TabPanel(id, model);
	}
}

The Page has a hibernate backed LoadableDetachableModel - AlbumGroup.
AlbumGroup has a list of Albums. I iterate through the list and create a tab
for each Album and create a tabbed panel:

//create a tab for each album
List<ITab> tabs = new ArrayList<ITab>();
for (Album album: model.getObject().getAlbums()) {
	ITab tab = new AlbumTab(new Model<Album>(album));
	tabs.add(tab);
}
add(new TabbedPanel("content-tabs", tabs));

My confusion was/is on who calls detach() on the LDM. Each tab will have a
reference to the LDM.

I am now setting the LDM as the default model for the page (even though the
page does not use it). My reasoning is that once the page is Serialised, it
will call detach() on the LDM.


Any thoughts on my approach?
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Dynamic-tab-question-now-to-pass-a-model-to-the-panel-tp3250387p3252157.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