GWT RichTextArea ReadOnly Workaround

2019-07-21 04:48发布

GWT's RichTextArea doesn't have a method to make it "ReadOnly". There's a setEnabled() method, but if you call setEnabled(false), it doesn't work.

I'm trying a workaround for this that should work. My idea is to replace the RichTextArea for this behavior with a HTML widget.

The problem is, if I use an HTML widget to set the original RichTextArea's content, it will be affected by all the styling of my web application.

The RichTextArea achieves this wrapping the content inside an IFrame.

So i'm trying to mimick that, doing something like this:

public class RichTextAreaReadOnly extends Composite
{
    protected HTML instance;

    public RichTextAreaReadOnly() 
    {
        this.instance = new HTML();
        this.initWidget(this.instance);
    }

    public void setHTML(String html)
    {
        this.instance.setHTML("<iframe class=\"gwt-RichTextAreaReadOnly\">"
                        + "<html>"
                        + "<head></head>"
                        + "<body>"
                        + html
                        + "</body>"
                        + "</html>"
                        + "</iframe>");
    }   
}

The problem is, for some strange reason the body appears empty.

If I try this:

public void setHTML(String html)
{
    this.instance.setHTML("<html>"
                        + "<head></head>"
                        + "<body>"
                        + html
                        + "</body>"
                        + "</html>");
}

(note: without the iframe tag)

It works but the styling is incorrect because it is being affected by styles it shouldn't be.

Any idea of why when I use HTML.setHTML() to create an IFrame, the body tag appears empty???

0条回答
登录 后发表回答