GWT RichTextArea ReadOnly Workaround

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 04:54:16

问题


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???

来源:https://stackoverflow.com/questions/29973784/gwt-richtextarea-readonly-workaround

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!