The problem is that you have two different component hierarchies in your if and else statement in the populateItem method, but not in your markup:

HTML:
   rows
      row
         myLink
            label
         nested

IF:
   rows
      row
         label
         nested

ELSE:
   rows
      row
         myLink
            label
         nested

in the IF statement structure you are trying to add the 'label' directly to the 'row'. But the 'row' doesn't have an associated 'label' component, only' myLink' and 'nested'. That is why you get the error 'unable to find label'.

Two solutions are available: use the same component hierarchy in both parts of the code, or externalize the two different hierarchies into seperate panels. The latter is described below.

In order to have different component hierarchies in your markup and Java, you need a second indirection; make two Panels for your 'row' component.

NestedLinkPanel.java:

public class NestedLinkPanel extends Panel {
   public NestedLinkPanel(String name, IModel model) {
       super(name, model);
add(new ExternalLink("myLink", "http://google.com";).add(new Label("label", "bar")));
       add(new Label("foo", "Hello, World!"));
   }
}

NestedLinkPanel.html:
<html>
<body>
<wicket:panel>
<a href="#" wicket:id="myLink"><span wicket:id="label">bar</span></a>
<span wicket:id="foo">message goes here</a>
</wicket:panel>
</body>
</html>

NestedStaticTextPanel.java:

public class NestedStaticTextPanel extends Panel {
   public NestedStaticTextPanel(String name, IModel model) {
       super(name, model);
       add(new Label("label", "bar"));
       add(new Label("foo", "Hello, World!")0;
   }
}
NestedStaticTextPanel.html:
<html>
<body>
<wicket:panel>
<span wicket:id="label">bar</span>
<span wicket:id="foo">message goes here</a>
</wicket:panel>
</body>
</html>

protected void populateItem(ListItem item) {
   Object modelObject = item.getModelObject();
   Panel panel = null;
   if(modelObject instanceof List) {
       panel = new NestedStaticTextPanel("row", null);
       panel.setVisible(false);
   } else {
       panel = new NestedLinkPanel("row", model);
   }
   item.add(panel);
}

Martijn


Francis Amanfo wrote:

No, I'm just trying to modify the NestedList example so that the list items (<li>) are displayed as an ExternalLink to a url.
Anyone can help?

----- Original Message ----- From: "Jonathan Locke" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, July 28, 2005 02:14
Subject: Re: [Wicket-user] NestedLint example



if you're trying to do a tree, have a look at the nested list example. it already does what you're trying to do (i think)

Francis Amanfo wrote:

Hi Jonathan,

Thanks for the suggestions. I've corrected my typo and added the label to "myLink" as you suggested but got this time the error:

java.lang.IllegalArgumentException: A child with id 'row' already exists: ...

Could you please demonstrate your suggestions with code?

Thanks in advance.

F.

----- Original Message ----- From: "Jonathan Locke" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, July 28, 2005 01:02
Subject: Re: [Wicket-user] NestedLint example



nesting of tags is strict.  you must add label to myLink, not row.
also, you typoed wicket as wicket.

Francis Amanfo wrote:

Hi,

Still struggling to get this work. I'm pasting part of the source in here.

Nested.html
==========

<html xmlns:wicket>
<wicket:panel>
 <ul>
   <span wicket:id="rows">
     <li wicket:id="row">
       <a wicked:id="myLink">
         <span wicket:id="label">the label</span>
       </a>
     </li>
     <span wicket:id="nested"/>
   </span>
 </ul>
</wicket:panel>
</html>

The populateItem method in NestedList.java
===============================
protected void populateItem(ListItem listItem)
       {
           Object modelObject = listItem.getModelObject();

           if(modelObject instanceof List)
           {
               // create a panel that renders the sub lis
NestedList nested = new NestedList("nested", (List)modelObject);
               listItem.add(nested);
// if the current element is a list, we create a dummy row/ label element // as we have to confirm to our HTML definition, and set it's visibility // property to false as we do not want LI tags to be rendered. WebMarkupContainer row = new WebMarkupContainer("row");
               row.setVisible(false);
               row.add(new WebMarkupContainer("label"));

               listItem.add(row);
           }
           else
           {
// if the current element is not a list, we create a dummy panel element // to confirm to our HTML definition, and set this panel's visibility // property to false to avoid having the UL tag rendered
               NestedList nested = new NestedList("nested", null);
               nested.setVisible(false);
               listItem.add(nested);
// add the row (with the LI element attached, and the label with the
               // row's actual value to display
WebMarkupContainer row = new WebMarkupContainer("row"); ExternalLink el = new ExternalLink("myLink", "http://www.google.com";, "Click this link to go to Google");
               el.add(new Label("label", modelObject.toString()));
               row.add(el);
               listItem.add(row);
           }
       }

I get the error:
wicket.markup.MarkupException: Unable to find component with id 'label' in [MarkupContainer ...

Any suggestion as to what I'm doing wrong?

Thanks.

F






----- Original Message ----- From: "Igor Vaynberg" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, July 27, 2005 19:29
Subject: RE: [Wicket-user] NestedLint example


<UL>
    <li><a href="www.javalobby.org">Click here</a></li>
    ...
<UL>




Also looks like

<a wicked:id="myLink">
   <li wicket:id="row"
        <span wicket:id="label">the label</span>
    </li>
</a>




Needs to be

<li wicket:id="row">
<a wicked:id="myLink">
<span wicket:id="label">the label</span>
</a>
</li>

This also means the label component "label" needs to be added to the link
component instead of listview item

Igor




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user






-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September
19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September
19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user






-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September
19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September
19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user






-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September
19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user




-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September
19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to