I have found the following problem realted to namespaces in wickect 2.0. 

If I have a template file like 

<html xmlns:wicket="" xmlns:sherpa="http://www.isencia.com/timbuktu/sherpa";>
<body>
<wicket:panel>
  <sherpa:table cellpadding="0" cellspacing="0" 
wicket:id="messages"></sherpa:table>
</wicket:panel>
</body>
</html>

that I want is to transform it to 

<html xmlns:wicket="" xmlns:sherpa="http://www.isencia.com/timbuktu/sherpa";>
<body>
        <table cellpadding="0" cellspacing="0" wicket:id="messages">The 
contents of 
my table dynamically generated here...</table>
  </body>
</html>

Then on my table component I do the following

@Override
        protected void onComponentTag(ComponentTag tag) {               
                if(tag.getNamespace().equals("sherpa")) {
                        tag.setNamespace(null);
                }               
                super.onComponentTag(tag);
        }

to get rid of the sherpa namespace but then the generated markup is

 
<html xmlns:wicket="" xmlns:sherpa="http://www.isencia.com/timbuktu/sherpa";>
<body>
        <table cellpadding="0" cellspacing="0" wicket:id="messages">The 
contents of 
my table dymamically generated here...</sherpa:table>
  </body>
</html>

which is not exactly well formed XML. The same happens if instead of 

<sherpa:table cellpadding="0" cellspacing="0" 
wicket:id="messages"></sherpa:table>

I write 

<sherpa:table cellpadding="0" cellspacing="0" wicket:id="messages"/>

Am I doing something forbidden or is this a bug?

After doing a bit of debugging I have found that there are to places were I 
have to alter the code on the class Component to get this working fine. Those 
are the methods

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());
                                        >> I HAVE TO ADD FOLLOWING CODE
                                        // change also the namespace if the 
name changed 
                                        
closeTag.setNamespace(openTag.getNamespace());
                                        >>
                                }

                                // 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);
                                }
                        }
                }
        }

and 

        public final void renderComponent(final MarkupStream markupStream)
        {
                this.markupIndex = markupStream.getCurrentIndex();

                // Get mutable copy of next tag and apply the changes recorded 
in 
markupAttributes
                final ComponentTag openTag = markupStream.getTag();
                final ComponentTag tag = openTag.mutable();
                if (this.markupAttributes != null)
                {
                        
tag.getAttributes().putAll(this.markupAttributes.getChangeMap());
                }

                // Call any tag handler
                onComponentTag(tag);

                // If we're an openclose tag
                if (!tag.isOpenClose() && !tag.isOpen())
                {
                        // We were something other than <tag> or <tag/>
                        markupStream
                                        .throwMarkupException("Method 
renderComponent called on bad markup 
element: "
                                                        + tag);
                }

                if (tag.isOpenClose() && openTag.isOpen())
                {
                        markupStream
                                        .throwMarkupException("You can not 
modify a open tag to open-close: " + 
tag);
                }

                try
                {
                        // Render open tag
                        if (getRenderBodyOnly() == false)
                        {
                                renderComponentTag(tag);
                        }
                        markupStream.next();

                        // Render the body only if open-body-close. Do not 
render if
                        // open-close.
                        if (tag.isOpen())
                        {
                                // Render the body
                                onComponentTagBody(markupStream, tag);
                        }

                        // Render close tag
                        if (tag.isOpen())
                        {
                                if (openTag.isOpen())
                                {
                                        renderClosingComponentTag(markupStream, 
tag, getRenderBodyOnly());
                                }
                                else
                                {
                                        // If a open-close tag has been to 
modified to be
                                        // open-body-close than a synthetic 
close tag must be
                                        // rendered.
                                        if (getRenderBodyOnly() == false)
                                        {
                                                // Close the manually opened 
panel tag.
                                                >> I HAVE TO ADD FOLLOWING CODE
                                                if(tag.getNameChanged())
                                                        
getResponse().write(tag.syntheticCloseTagString());
                                                else
                                                >>                              
                
                                                        
getResponse().write(openTag.syntheticCloseTagString());
                                        }
                                }
                        }
                }
                catch (RuntimeException re)
                {
                        if (re instanceof WicketRuntimeException || re 
instanceof AbortException)
                        {
                                throw re;
                        }
                        throw new WicketRuntimeException("Exception in 
rendering component: " + 
this, re);
                }
        }

where the modifications I did are enclosed as

>> I HAVE TO ADD FOLLOWING CODE

>>

I have tested on my application and it seems to work fine. Can any of the 
wicket mavens take a look to this? Please...  And  if they are fine could you 
include them on the trunk (or if I missunderstood it wrong just tell me which 
is the right way to achieve what I want!)

Kind regards 

Ernesto

Reply via email to