I am trying to encapsulate Edit/View/Select markup into one Component.  I want to set the mode, then add the Fragment to the parent container. 

My first attempts went something like this:


parent.add( component.getFragment( "markupId", Mode.Edit ) );



... and in the component#getFragment(), something like this:

public Component getFragment( String id, Mode mode )
{
	if ( mode == Mode.Edit )
		return new Fragment( id, "edit", this );   // <-- the "this" forces markup from this component, right?
	return new Fragment( id, "view" );
}



This throws a NPE:

java.lang.NullPointerException
        at wicket.markup.html.panel.Fragment.renderFragment(Fragment.java:218)
        at wicket.markup.html.panel.Fragment.onComponentTagBody(Fragment.java:202)
        at wicket.Component.renderComponent(Component.java:1662)
        at wicket.MarkupContainer.onRender(MarkupContainer.java:917)
        at wicket.Component.render(Component.java:1507)
        at wicket.MarkupContainer.renderNext(MarkupContainer.java:1324)
	.... more ....

I saw a recent commit to Fragment#onComponentTagBody() by Eelco that will throw a more descriptive exception instead of this NPE indicating if the markup could not be found.  
Specifically, in the source code it says that the "component used to load the fragment" must be in the page heirarchy.  Is this true?  
A component cannot just provide fragments to container in the manner am I trying to illustrate above?  I basically need Edit/View/Select versions of
a component and I would like to put them all into the same markup file.

Aaron

Reply via email to