使用Wicket生成注释掉的内容 [英] Generating commented-out content with Wicket

查看:133
本文介绍了使用Wicket生成注释掉的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于调试原因,我想在Wicket网页的HTML输出中包含某些信息,包含在HTML注释中。



输出会是...

  ! -  
< div wicket:id =foo> 1234< / div>
- >

...其中1234是一些有趣的动态创建的信息。

我试过,无效:




  • - < div wicket:id =foo>< / div> - > →Wicket抱怨HTML网页中缺少标识为foo的元素

  • remove> →这些栏目不能包含 wicket:id

  • .setVisible(false)→Wicket根本不输出标签

  • new Label(foo,< - + foo + - >)< > get escaped



那么,你能用Wicket做这件事吗p>

解决方案

如何解决?

  class CommentOutModifier extends AbstractBehavior {
private static final long serialVersionUID = 1L;

@Override
public void beforeRender(Component component){
component.getResponse()。write(<! - );
}

@Override
public void onRendered(Component component){
component.getResponse()。write( - >);
}
}

add(new Label(tohide,你能看到我吗?)add(new CommentOutModifier

那么:

 < span wicket:id =tohide>< / span>您的标记中的

会产生:

 <! - < span>您能看到我吗?< / span>  - > 


For debug reasons, and on a whim, I'd like to include certain information in a Wicket page's HTML output that is enclosed in HTML comments.

The output would be something like...

<!-- 
<div wicket:id="foo"> 1234 </div>
-->

...where "1234" is some interesting, dynamically created piece of information.

I have tried, to no avail:

  • <!-- <div wicket:id="foo"></div> --> → Wicket complains that element with id "foo" is missing from the HTML page
  • enclose in <wicket:remove> → such sections cannot contain elements with wicket:id
  • label.setVisible(false) → Wicket doesn't output the label at all
  • new Label("foo", "<!-- " + foo + " -->") → the < and > get escaped

So, can you do this with Wicket (easily), or should I just forget about it?

解决方案

How about this?

class CommentOutModifier extends AbstractBehavior {
    private static final long serialVersionUID = 1L;

    @Override
    public void beforeRender(Component component) {
        component.getResponse().write("<!--");
    }

    @Override
    public void onRendered(Component component) {
      component.getResponse().write("-->");
    }
}

add(new Label("tohide", "Hi, can you see me?").add(new CommentOutModifier()));

then, putting:

<span wicket:id="tohide"></span>

in your markup will yield:

<!--<span>Hi, can you see me?</span>-->

这篇关于使用Wicket生成注释掉的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆