0

ZK label without <span>

asked 2012-10-24 20:24:21 +0800

guiye gravatar image guiye
28 1

Hi,

I have in ZUL file an H2 tag

<h2 id="titleTextH2"></h2>

but I want to update from java side it's content, in order to have this result:

<h2 id="titleTextH2">RAW TEXT</h2>


If I append a Label component, the result is:

<h2 id="titleTextH2"><span class="...">RAW TEXT</span></h2>

but I want to avoid extra <span> tags.... how can I do it from Java side?

thanks!

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2012-10-25 04:24:39 +0800

vincentjian gravatar image vincentjian
2245 6

Hi guiye,

Try using Html component.

link publish delete flag offensive edit

answered 2012-10-25 12:05:08 +0800

guiye gravatar image guiye
28 1

thanks vicent for your answer, I've tried with Html component, but it renders <span> between the content

link publish delete flag offensive edit

answered 2012-10-25 12:23:12 +0800

gekkio gravatar image gekkio flag of Finland
899 1
http://gekkio.fi/blog

The h2 component doesn't have setLabel or setValue methods, but you can dynamically modify the contents like this:

H2 titleText = ... // wire this component somehow in Java code
titleText.getChildren().clear();
titleText.appendChild(new Text("NEW TEXT"));

link publish delete flag offensive edit

answered 2012-10-26 15:03:26 +0800

guiye gravatar image guiye
28 1

thanks gekkio, i've tried your snippet but it's still inserting <span> tags:

<h2 class="widget-title" id="wGBPzb">
    <span class="z-text" id="wGBP_c">NEW TEXT</span>
</h2>

link publish delete flag offensive edit

answered 2012-10-26 16:00:05 +0800

gekkio gravatar image gekkio flag of Finland
899 1
http://gekkio.fi/blog

Hmm, interesting, I had no idea ZK wraps all free text in z-text spans.
I don't see any easy or clean way out of this, because span wrapping is defined in the ZHTML language definition.

One way is to implement a custom H2 tag by extending ContentTag:

public class CustomH2 extends ContentTag {
  public CustomH2() {
    super("h2");
  }
}

You'll also need to register the component in a lang-addon.xml file if you want to use it in a ZUL file. All ContentTags have a method called setContent, which can be used to directly set content as a string without any wrapping.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-10-24 20:24:21 +0800

Seen: 175 times

Last updated: Oct 26 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More