0
votes

I have this html markup:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org/" xml:lang="cs" lang="cs">
    <wicket:panel>
        <div id="nav">
            <ul>
                <li>
                    <a href="./page2.html" class="here">page 1</a>
                </li>
                <li>
                    <a href="./page3.html" class="">page 2</a>
                </li>
                <li>
                    <a href="./kontakt.html" class="">page 3</a>
                </li>
            </ul>
        </div>
    </wicket:panel>
</html>

and this is my very simple wicket code for panel:

public class PanelMenu extends Panel{
    private static final long serialVersionUID = 1L;

    public PanelMenu(String id){
        super(id);
        }
    }

    @Override
    protected void onBeforeRender(){
        String markup = this.getAssociatedMarkup().toString();
        markup = markup.replaceAll("a", "b");
        //how to write modyfied markup for panel to response?
        this.getResponse().write(markup);//this write to start of the page, not panel
        super.onBeforeRender();
        }

On my page I do:

this.add((new PanelMenu("panelMenu")).setRenderBodyOnly(true));

I need to know how to write modyfied html markup for panel in variable markup back into response. How can I do it? this.getResponse().write(markup) write at the start of the page.

1
You are asking for a weird thing. Try to explain whole task - there are few common and simple approaches to implement menus. - alexei-grigoriev
Why would you want to modify the markup directly? That's not really the way to. In most cases that can be solved by correct use of components or markup fragments. What is it you're trying to accomplish? - Buurman

1 Answers

0
votes

You try to change the markup way to late. To access and modify the component markup, you'll have to do so by implementing your own IResourceStream or extend wickets MarkupResourceStream to perform the modification and use this in your own MarkupFactory, that you set in Application.init() as.

@Override
public void init() {
    super.init();
    getMarkupSettings().setMarkupFactory(new MyMarkupFactory());
}