Saturday, April 26, 2014

Re: HTMLPanel - How does it work?

You don't need to extend HTMLPanel when all you need is one tag. You can do that by just subclassing Widget instead and call setElement( Document.get().createHElement(1)) in the constructor.
Then you can make it implement HasText and HasHTML to set the contents (by using the Element.setInnerText or setInnerHTML methods).

f.ex (just typing from the top of my mind, so it can contain some typos):

public class HeadingWidget extends Widget implement HasHTML, HasText, HasSafeHtml, TakesValue<String> {
   public HeadingWidget( int level) {
       setElement( Document.get().createHElement(level));
   }
   public setText( String text ) {
     getElement().setInnerText(text);
   }

   public setHTML( String html ) {
     getElement().setInnerHTML(html);
   }
  ...
}

HTMLPanel is normally used for the case where you need a mix of plain HTML and widgets. It is for example used extensively in UiBinder.
It allows you to wrap an existing Element in the provided HTML in an actual widget.



On Sat, Apr 26, 2014 at 12:45 AM, Joshua Godi <joshuagodi@gmail.com> wrote:
I was curious if anyone could explain how the HTMLPanel works?

I am trying to create a custom Heading widget for my GWT Project that extends HTMLPanel but since the heading element can be h1, h2, ..., h6, I am having a hard time getting this to work for HTMLPanel, since it calls into the HTMLPanel(String html) constructor first.

I was going to write my own version of the HTMLPanel, any thoughts?

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment