On 5/8/06, Aaron Hiniker <[EMAIL PROTECTED]> wrote:
 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" );
}


return new Fragment( id, "edit");   // <-- "this" is not required but
shouldn't make a difference



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?

yes. The markup file which contains the fragment must be either the
component (this) itself or any of its parents up the hierachy

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.


the basics seems to be ok. In the examples ExampleSubsets uses
Fragments and there are junit test as well.

I'm not sure how you want to replace the fragments. Based on your code
it looks like your adding, based on the mode, different fragments in
the constructor which means you are creating a new page every time?
You are not replacing the fragments? setMarkupTagReferenceId(String)
may be used to replace the fragments as well.

Juergen

Aaron





-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to