开发者

SmartGWT, appending HTML to HTMLPane

开发者 https://www.devze.com 2022-12-21 21:03 出处:网络
I am currently working with SmartGWT and have been trying to obtain a way of including a panel such as the gwt Standard VerticalPanel into a smart GWT window. The reason for the VerticalPanel is that

I am currently working with SmartGWT and have been trying to obtain a way of including a panel such as the gwt Standard VerticalPanel into a smart GWT window. The reason for the VerticalPanel is that I can append widgets to the verticalpanel object without having to re-set the entire content, for example:

HTMLPane hPaneObj = new HTMLPane();  
hPaneObj.setContents("Foo");

Now to append I can only see that I can do:

hPaneObj.setCo开发者_JAVA百科ntents(hPaneObj.getContents() + "Bar");

which is not what I need.

The problem arises after I've added the VerticalPanel, I cannot select any text within the window even with the 'setCanSelectText' method called with true as the parameter. Below is a short example I put together:

 public void onModuleLoad() {
  Window theWindow = new Window();
  theWindow.setTitle("Good evening");
  theWindow.setWidth(500);
  theWindow.setHeight(500);
  theWindow.setCanSelectText(true);

  VerticalPanel vp = new VerticalPanel();
  vp.add(new HTML("foo"));
  vp.add(new HTML("bar"));
  theWindow.addItem(vp);
  Canvas canvas = new Canvas();
  canvas.addChild(theWindow);
  canvas.draw();
 }

I am quite suprised however that HTMLPane doesn't allow me to append without resetting the entire contents.

Any advice would be appreciated however I need to do be able to 'append' to a panel. I don't particularly like the idea of using a vertical panel however I need to either find a method of allowing the aforementioned or allowing me to allow the verticalpanel to be accessible, i.e. selecting the text.

Many thanks

Christopher.


The VerticalPanel uses a html table to create it's content, and most likely not something you want in this case. In general, in HTML it's not possible to add plain HTML in addition to existing content, because of the xml like nature. For example if you have the following html <div>some text</div>. If you want to add text the point to add must be relative to the div tag, it's not possible to add something for example between some and text without reinserting that whole text.

In your case you might want to use FlowPanel (which is a div) and add the HTML with InlineHTML (which wraps the HTML with a span). In case you don't want the span wrapped you would have to reinsert the text as in your HTMLPane example.


You need to be setting canSelectText in the right place, not on the Window as a whole (which would include the header and icons), but just on the element where selection is allowed.

So two options:

1) when you add a plain GWT widget to a SmartGWT container it's auto-wrapped with a WidgetCanvas. You can wrap it yourself and setCanSelectText() on the WidgetCanvas.

http://www.smartclient.com/smartgwtee/javadoc/com/smartgwt/client/widgets/WidgetCanvas.html

2) subclass Canvas and override getInnerHTML() to return a DIV or other element with a known ID, and then use GWT's low-level DOM manipulation APIs to manipulate it's content.


Issue was solved by isomorphic on:

http://forums.smartclient.com/showthread.php?p=39351#post39351

0

精彩评论

暂无评论...
验证码 换一张
取 消