0

I have a TabView whose tabs i generated with :

<p:tabView>
    <c:forEach var="app" items="#{data.apps}">
        <p:tab title="#{app.name}" closable="true" id="app_#{app.id}">
            <object data="#{app.startUri}" height="800" width="1150" />
        </p:tab>
    </c:forEach>
</p:tabView>

However, I had a problem with adding new tabs. I had to update the TabView which caused the tabs and their contents to reload which was a problem for my situation.

I then switched to create my TabView with a TabViewHelper bean.

But then there was a problem with adding the object tag as a child to the tab:

public TabView initializeTabView(List<App> apps) {
    tv = new TabView();
    Tab tab;
    for (App app : apps) {
        tab = new Tab();
        tab.setTitle(app.getName());
        HTMLObjectElementImpl content = new HTMLObjectElementImpl(owner, "test-object");
        tab.getChildren().add(content);
    tv.getChildren().add(tab);
    }
    return tv;
}

I get the following error:

The method add(UIComponent) in the type List is not applicable for the arguments (HTMLObjectElementImpl)

I can only add an UIComponent.

I'm not sure if HTMLObjectElementImpl is right for <object> but I did not find something better.

Is there an UIComponent for the HTML <object>-tag or is there another class available for HTML <object>?

Did anyone else have this problem and found a solution?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Patrick
  • 3
  • 4
  • You'll have the same problem when updating though… you just converted simple xhtml to complex java. PF tabs just does not support the 'add-a-tab-dynamically-at-runtime without-reloading-all-others' – Kukeltje Jul 14 '15 at 15:54
  • @Kukeltje Adding a tab dynamicly is easily possible with `tv.getChildren().add(tab)`. This workes well for me. – Patrick Jul 17 '15 at 06:57
  • Yes but to make it visible, you have to render the whole tabview, including all other tabs. That is what I stated in my previous comment. I knowhere said you cannot add a tab. – Kukeltje Jul 17 '15 at 07:02

1 Answers1

0

<object> is not a JSF component. It's basically considered as plain text.

Simplest way would be to create a HtmlOutputText with escape set to false.

HtmlOutputText html = new HtmlOutputText();
html.setEscape(false);
html.setValue("<object>...</object>");

Beware of XSS attack holes in case you pass user-controlled variables to that.

In future you try to create a JSF component programmatically, use a subclass of UIComponent and not some random JAXP implementation specific class. Or, better, fix that update problem so you can keep using XHTML code to create the view instead of verbose Java code.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555