2013-06-17 4 views
2

에 GWT 위젯을 첨부하는 방법 : I 콘텐츠 클래스와 중첩 된 DIV에 위젯을 삽입 할 필요가이 같은 마크 업을 사용하여 내 사용자 정의 위젯에 GWT 복합을 확장 위젯에 연결해야하는 방법 요소

<div class="left"> 
    <div class="right"> 
    <div class="content">{content}</div> 
    </div> 
</div> 

합니다.

public class VideoPanel extends Component { 

public VideoPanel(final Widget content, 
     final VideoPanelAppearance appearance, final int width, 
     final int height) { 
    this.content = content; 
    this.appearance = appearance; 
    final SafeHtmlBuilder sb = new SafeHtmlBuilder(); 
    appearance.render(sb, 
      SafeHtmlUtils.fromTrustedString(content.toString())); 
    final XElement element = XDOM.create(sb.toSafeHtml()); 
    final XElement contentElement = appearance.getContentElement(element); 
    contentElement 
      .setSize(getContentWidth(width), getContentHeight(height)); 
    setElement(element); 
    setPixelSize(width, height); 
} 

} 

내가 문자열에 확실하지 않다 : 나는 내 사용자 정의 위젯의 생성자를 게시 아래

SafeHtmlUtils.fromTrustedString(content.toString()) 

내용은 비디오 플레이어 위젯입니다. 위 코드 결과는 HTML 페이지에 EMBED 태그가 표시되지 않습니다.

답변

1

콘텐츠 위젯을 코드의 contentElement에 추가 한 것처럼 보이지 않습니다. 논리적으로는 VideoPanelAppearance가 contentElement (코드에서 분명하지 않음)와 어떤 식 으로든 관련이 없으면 렌더링이 관련되지 않습니다. 그냥 "ContentElement에"의 자식으로 내용 요소를 추가하지 않는 이유 :

/*this will relate them via the DOM (so the widgets wouldn't know about it but 
but in your case it doesn't seem like it matters*/ 
contentElement.appendChild(content.getElement()); 

또한 appearance.getContentElement (요소) 클래스 "내용"으로 예상 요소를 반환되어 있는지 확인합니다. 희망이 도움이됩니다.

0

솔루션 :

public class VideoPanel extends Panel { 

public VideoPanel(final Composite content, final VideoPanelAppearance appearance, final int width, 
     final int height) { 
    this.content = content; 
    this.appearance = appearance; 
    final SafeHtmlBuilder sb = new SafeHtmlBuilder(); 
    appearance.render(sb, title); 
    setElement(XDOM.create(sb.toSafeHtml())); 

    DOM.appendChild(getContainerElement(), content.getElement()); 
    adopt(content); 
    getContainerElement().<XElement> cast().setSize(getContentWidth(width), 
      getContentHeight(height)); 
    setPixelSize(width, height); 
    sinkEvents(Event.ONCLICK); 
} 

public Element getContainerElement() { 
    return appearance.getContentElement(getElement().<XElement> cast()); 
} 

} 
관련 문제