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 

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.


From: Paul Huang [mailto:paulhuan...@gmail.com]
To: users@wicket.apache.org
Sent: Sat, 10 Oct 2009 08:34:15 -0400
Subject: how to inject arbitrary javascript code to a component markup?

Suppose I write my own wicket component called XYZ that have the following
  <div wicket:id="id_xxx">
  How can I inject some js code into this markup so when it's rendered in a
  page, I got something like
  <div wicket:id="id_xxx">
   <script type="text/javascript">
       var data=["abc", "efg"];
  You may ask why I dont simply keep the js code into the component markup
  "XYZ.html", this is because the value of "data" variable will be provided by
  the user and is not fixed.

Reply via email to