> Can you provide a quickstart of your panel (the one you already
> developed and which works nice)?
>
> Juergen
>
The idea is based of Loop with 'LayoutManager' (to write table around
children). Works with wicket 1.2.1. WithoutMarkup and HasMarkup are
interfaces to give hint if markup is in template or not.
public class MyPanel extends WebMarkupContainer implements WithoutMarkup
{
protected ILayoutManager layoutManager;
/**
* Construct.
*
* @param id
* See Component
* @see wicket.Component#Component(String)
*/
public MyPanel(final String id)
{
this(id, null);
}
/**
* Construct.
*
* @param id
* See Component
* @param model
* Must contain a Integer model object
* @see wicket.Component#Component(String, IModel)
*/
public MyPanel(final String id, final IModel model)
{
this(id, model, new TableLayoutManager());
}
/**
* Construct.
*
* @param id
* See Component
* @param model
* Must contain a Integer model object
* @see wicket.Component#Component(String, IModel)
*/
public MyPanel(final String id, final IModel model, ILayoutManager
layoutManager)
{
super(id, model);
this.layoutManager = layoutManager;
this.setRenderBodyOnly(true);
}
/**
* Renders this Loop container.
*/
protected void onRender(MarkupStream markupStream)
{
Application.get().getDebugSettings().setComponentUseCheck(false);
Response response = getResponse();
boolean writeTag = !getRenderBodyOnly();
if (writeTag) {
response.write(markupStream.get().toCharSequence());
}
if (layoutManager!=null) layoutManager.startLayout(response);
int currentIndex = markupStream.getCurrentIndex();
int iteration = 0;
// Iterate through children on this container
for (Iterator iterator = iterator(); iterator.hasNext();)
{
iteration ++;
// Get next child component
final Component component = (Component)iterator.next();
if (component == null)
{
throw new WicketRuntimeException(
"Loop item is null. Probably
the number of loop iterations were
changed between onBeginRequest and render time.");
}
if (layoutManager!=null)
layoutManager.startLayout(response, component);
// Rewind to start of markup for kids
markupStream.setCurrentIndex(currentIndex);
if (component.isVisible()) {
if (component instanceof WithoutMarkup)
{//Panel) {
component.render(markupStream);
} else if (component instanceof
WebMarkupContainerWithAssociatedMarkup) {
WebMarkupContainerWithAssociatedMarkup
markupContainer =
(WebMarkupContainerWithAssociatedMarkup) component;
markupContainer.renderAssociatedMarkup("panel", "exceptionMessage");
} else if (component instanceof
MarkupContainer) {
MarkupContainer markupContainer =
(MarkupContainer) component;
MarkupStream markupStream2 =
getApplication().getMarkupCache().getMarkupStream(markupContainer);
component.render(markupStream2);
} else if (component instanceof HasMarkup) {
component.render();
} else {
component.render();
}
}
if (layoutManager!=null)
layoutManager.endLayout(response, component);
}
if (layoutManager!=null) layoutManager.endLayout(response);
markupStream.setCurrentIndex(currentIndex);
while (!markupStream.atCloseTag())
markupStream.next();
if (writeTag) {
response.write(markupStream.get().toCharSequence());
}
}
public final void renderAssociatedMarkup(final String exceptionMessage)
{
// Get markup associated with Border or Panel component
final MarkupStream originalMarkupStream = getMarkupStream();
final MarkupStream associatedMarkupStream =
getAssociatedMarkupStream(true);
// skip until the targetted tag is found
// String openTagName = "test";
//associatedMarkupStream.skipUntil(openTagName);
setMarkupStream(associatedMarkupStream);
// Get open tag in associated markup of border component
final ComponentTag associatedMarkupOpenTag =
associatedMarkupStream.getTag();
// Check for required open tag name
if (!((associatedMarkupOpenTag != null) &&
associatedMarkupOpenTag.isOpen() &&
(associatedMarkupOpenTag instanceof WicketTag)))
{
associatedMarkupStream.throwMarkupException(exceptionMessage);
}
try
{
setIgnoreAttributeModifier(true);
renderComponentTag(associatedMarkupOpenTag);
associatedMarkupStream.next();
renderComponentTagBody(associatedMarkupStream,
associatedMarkupOpenTag);
renderClosingComponentTag(associatedMarkupStream,
associatedMarkupOpenTag, false);
setMarkupStream(originalMarkupStream);
}
finally
{
setIgnoreAttributeModifier(false);
}
}
@SuppressWarnings ({"all"})
final void renderClosingComponentTag(final MarkupStream markupStream,
final ComponentTag openTag, final boolean renderTagOnly)
{
// Tag should be open tag and not openclose tag
if (openTag.isOpen())
{
// If we found a close tag and it closes the open tag,
we're good
if (markupStream.atCloseTag() &&
markupStream.getTag().closes(openTag))
{
// Get the close tag from the stream
ComponentTag closeTag = markupStream.getTag();
// If the open tag had its id changed
if (openTag.getNameChanged())
{
// change the id of the close tag
closeTag = closeTag.mutable();
closeTag.setName(openTag.getName());
}
// Render the close tag
if (renderTagOnly == false)
{
renderComponentTag(closeTag);
}
markupStream.next();
}
else
{
if (openTag.requiresCloseTag())
{
// Missing close tag
markupStream.throwMarkupException("Expected close tag for " + openTag);
}
}
}
}
public void setLayoutManager(ILayoutManager layoutManager) {
this.layoutManager = layoutManager;
}
public ILayoutManager getLayoutManager() {
return layoutManager;
}
}
> On 10/27/06, Petr Sakar <[EMAIL PROTECTED]> wrote:
>> > Can you be more specific as to why you don't want to inherit from
>> > Border, Panel or Fragment?
>>
>>
>> The usage is mainly for dynamic forms.
>> 1. you define your components and their markup (TextField,
>> DropDownChoice,
>> ...) and some panel
>> 2. adds them to panel, which is doing their layout to some table
>>
>> You can then write forms without need to write html templates for forms.
>>
>> Basically you would not have to use panel as wrapper instead of that you
>> would be able to use existing components, subclass them to implement
>> such
>> interface and define their html template.
>>
>> I've alredy done such panel for one our project, and it works nice.
>> It saves a lot of work ...
>> saki
>>
>> >
>> > Martijn
>> >
>> > On 10/27/06, Petr Sakar <[EMAIL PROTECTED]> wrote:
>> >> Hi,
>> >> currently (wicket 1.2) if I want to make component with own markup, I
>> >> must
>> >> extend Panel, or override some method to provide markup.
>> >> Can you use as well interfaces to give framework hint that the
>> component
>> >> has its own markup in html template ?
>> >>
>> >> For example if component would implement interface BodyMarkup, the
>> html
>> >> template would be looked up. If it would implement interface
>> >> HeadContributor, you would know it is contributing to page head.
>> >>
>> >> saki
>> >>
>> >
>> >
>> > --
>> > <a
>> href="http://www.thebeststuffintheworld.com/vote_for/wicket">Vote</a>
>> > for <a
>> > href="http://www.thebeststuffintheworld.com/stuff/wicket">Wicket</a>
>> > at the <a href="http://www.thebeststuffintheworld.com/">Best Stuff in
>> > the World!</a>
>> >
>>
>>
>