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
Panel
> 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(Component.java:1763)
> at
> org.apache.wicket.markup.html.WebMarkupContainer.getMarkupType(WebMarkupContainer.java:60)
> at
> org.apache.wicket.markup.DefaultMarkupCacheKeyProvider.getCacheKey(DefaultMarkupCacheKeyProvider.java:57)
> at org.apache.wicket.markup.MarkupCache.getMarkup(MarkupCache.java:291)
> at
> org.apache.wicket.markup.MarkupCache.getMarkupStream(MarkupCache.java:216)
> at
> org.apache.wicket.MarkupContainer.getAssociatedMarkupStream(MarkupContainer.java:351)
> at com.tree.CategorySelectPanel.<init>(CategorySelectPanel.java:37)
> at com.tree.TestPage.<init>(TestPage.java:7)
>
>
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:
http://www.nabble.com/how-to-inject-arbitrary-javascript-code-to-a-component-markup--tp25833726p25834380.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org