2010/5/20 Thiago H. de Paula Figueiredo <thiag...@gmail.com>

>
> The issue here is how to render something after you render the block. I
> guess you need to implement it as a RenderCommand. It receives the render
> queue (RenderQueue instance), so you can add more RenderCommands to it. To
> render a Block inside a RenderCommand, cast it to RenderCommand and add it
> to the queue.
>
> Thanks a lot!
I have not understood what you wrote completly, but it gave me direction to
search. I needed debugger, to discover what is going on, how rendering
mechanism really works. Now I understand what is RenderCommand and
RenderQueue and theirs relation to MarkupWriter. Now I know that RenderQueue
is not a queue but stack (!!!).

My problem I solved this way:
    public Object afterRender(MarkupWriter writer) {

            CompositeRenderCommand compositeRenderCommand = new
CompositeRenderCommand();

            compositeRenderCommand.addRenderCommand(new RenderCommand() {
                public void render(MarkupWriter writer, RenderQueue queue) {
                    writer.element("div", "id", messageBlockId, "style",
"display:none");
                }
            });
            compositeRenderCommand.addRenderCommand((RenderCommand)
messageBlock);

            compositeRenderCommand.addRenderCommand( new RenderCommand() {
                public void render(MarkupWriter writer, RenderQueue queue) {
                    writer.end();
                }
            });

            return compositeRenderCommand;
}

public class CompositeRenderCommand implements RenderCommand {
        private final List<RenderCommand> commands = new
ArrayList<RenderCommand>(10);

        public void addRenderCommand(RenderCommand command) {
            commands.add(command);
        }

        public void render(MarkupWriter writer, RenderQueue queue) {
            for (int i = commands.size() - 1; i >= 0; i--)
                queue.push(commands.get(i));
        }

}


Regards
Lukasz

Reply via email to