Add a div to your page like below:

<meta http-equiv="Content-Type" content="text/html; 
charset=ISO-8859-1"> <title>Insert title here</title> </head> 

        <div wicket:id="csp"></div>


-----Original Message-----
From: PaulH98 [] 
Sent: 10 October 2009 14:58
Subject: Re: how to inject arbitrary javascript code to a component markup?

McIlwee, Craig wrote:
> If your component is a MarkupContainer you can override
> getAssociatedMarkupStream(boolean) and build the markup on the fly.  So
> maybe still have the HTML file that you read in as a template with some
> place holder string and in the override you replace the place holder with
> stuff you want to be assigned to the data variable.  Then use a
> StringResourceStream to create a MarkupResourceStream, use
> SimpleMarkupLoader to create a Markup instance from the
> MarkupResourceStream, and finally create a MarkupStream with your Markup
> instance.
> One thing to note is that if your markup container has child components
> that will be updated via AJAX AND you don't have an HTML file (you build
> the entire string on the fly) then you may also have to override
> hasAssociatedMarkupStream and always return true else the component being
> updated won't be able to locate its parent.
> Craig  

Here is the java code of my component "CategorySelectPanel" that extends

> public class CategorySelectPanel extends Panel{
>       private static final long serialVersionUID = 1L;
>       public CategorySelectPanel(String wicketId){
>               super(wicketId);
>               WebMarkupContainer cat0=new WebMarkupContainer("cat0");
>               cat0.setOutputMarkupId(true);
>               add(cat0);
>               MarkupStream ms=getAssociatedMarkupStream(true); 
>               System.out.println(ms.toString());
>       }
> }

and here is the associated markup file "CategorySelectPanel.html"

> <wicket:panel>
>   <div wicket:id="cat0" class="cat0"></div>
> </wicket:panel>

Now I have  a simple test

> public class TestPage extends WebPage{
>       public TestPage(){
>               CategorySelectPanel a= new CategorySelectPanel("csp");
>               add(a);
>       }
> }
with the the following page html 

> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
> <title>Insert title here</title>
> </head>
> <body>
> </body>
> </html>

when I run the test, I got the following exception 

> WicketMessage: Can't instantiate page using constructor public
> com.tree.TestPage()
> Root cause:
> java.lang.IllegalStateException: No Page found for component
> [MarkupContainer [Component id = csp]]
> at org.apache.wicket.Component.getPage(
> at
> at
> at org.apache.wicket.markup.MarkupCache.getMarkup(
> at
> org.apache.wicket.markup.MarkupCache.getMarkupStream(
> at
> at com.tree.CategorySelectPanel.<init>(
> at com.tree.TestPage.<init>(

Basically, "MarkupStream ms=getAssociatedMarkupStream(true) " caused this
exception. Can anyone shed some light on this? I am trying to Carig's
suggestion to get the MarkupStream and alter it with my stuff.

View this message in context:
Sent from the Wicket - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

Reply via email to