子级组件在构面中不包含ID父级 [英] Children component does not contain id parent in facet

查看:72
本文介绍了子级组件在构面中不包含ID父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在数据表中可以定义自定义构面.我要定义的构面包含一个p:menubutton,因为这些构面包含在分页器中,因此p:menubutton显示在数据表的顶部和底部.第一个问题是,客户ID重复了(并且我无法打开菜单按钮).我通过设置特定的ID来解决此问题,请参见 https://github.com/primefaces /primefaces/pull/2651/文件,但可以部分使用...

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

因为,如果放置两个p:menubutton (或另一个组件),我的修复将无法工作.一个UIpanelgetFacet()方法创建,当它包含多个元素时,它看起来像事件,尽管我强行设置一个id,但不会将此id设置为子元素.首先,让我们看看解决方法:

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);
}

输出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>

我希望p:menubutton包含父ID(例如table_form:table_form:table_paginator_top),但事实并非如此,为什么?

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?

推荐答案

首先,必须将PR合并到PF中.其次,创建一个像这样的虚拟复合物:

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>

用这种复合材料包裹内容,并且ID应该很好地生成.

Wrap content facet with this composite, and ids should be well generated.

重要提示:必须使用Mojarra 2.2.15 (尽管不了解MyFaces)

Important: Mojarra 2.2.15 have to be used (Don't know about MyFaces though)

这篇关于子级组件在构面中不包含ID父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆