问题
In a datatable there is the possibility to define custom facet. The facet I'm trying to define contains one p:menubutton
, because those facets are contained in a paginator, p:menubutton
is display on top and bottom of the datatable. First issue was, client id was duplicated (and i couldn't open the menubutton). I fixed this issue by setting a specific id, see https://github.com/primefaces/primefaces/pull/2651/files, but works partially...
Because, if a put two p:menubutton
(or another component) my fix won't work. A UIpanel
is created by getFacet()
method when it contains more than one element, and it looks like event though I force an id it won't set this id to the children. Firts, let's see the fix:
UIComponent elementFacet = uidata.getFacet(element);
if(elementFacet != null) {
// Determines a new id
String facetName = element.replaceAll("[\\W+]", "_").toLowerCase();
elementFacet.setId(uidata.getId() + facetName + position);
elementFacet.encodeAll(context);
}
The output HTML
<div id="table_form:table_form:table_paginator_top">
<span id="table_form:table_form:j_idt246" class="ui-menubutton">
<button id="table_form:table_form:j_idt246_button" />
</span>
</div>
I would expect the p:menubutton
contains the parent id (e.g table_form:table_form:table_paginator_top
) but it does not that, why that?
回答1:
First, the PR has to be merged in PF. Second, create a dummy composite like this one:
<ui:component
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:cc="http://xmlns.jcp.org/jsf/composite">
<cc:interface>
</cc:interface>
<cc:implementation>
<cc:insertChildren />
</cc:implementation>
</ui:component>
Wrap content facet with this composite, and ids should be well generated.
Important: Mojarra 2.2.15 have to be used (Don't know about MyFaces though)
来源:https://stackoverflow.com/questions/46171478/children-component-does-not-contain-id-parent-in-facet