无法从bean中找到组件

时间:2014-01-29 09:18:02

标签: java jsf primefaces javabeans

我想知道为什么我无法从我的支持bean中找到一个组件,bean的代码确实如此:

UIComponent component = viewRoot.findComponent("form_01:meterDialog:lazyGrid");
component.toString();

和jsf是:

<h:form id="form_01">
    <p:dialog id="meterDialog" header="Meters" widgetVar="meter_data"
    minimizable="true" maximizable="true" draggable="true"
    resizable="true" height="auto" width="auto" onShow="enableForm()">

        <p:remoteCommand id="cmd" name="enableForm" update="lazyGrid">
        <f:setPropertyActionListener value="#{true}"
            target="#{chartBean.formEnable}" />
        </p:remoteCommand>

        <p:panelGrid id="lazyGrid" rendered="true">
        </p:panelGrid>
    </p:dialog>
</h:form>

问题是它无法找到 lazyGrid ,它可以找到 meterDialog

viewRoot.findComponent("form_01:meterDialog");

没有问题,但没有组件 lazyGrid cmd

2 个答案:

答案 0 :(得分:1)

如果您的表单具有属性prependId =“false”,那么您可以找到实际的组件ID。

由于您没有设置该属性,因此必须从UIViewRoot进行引用。如果p:dialog是命名容器(我不确定)那么你必须将lazyGrid称为“form_01:meterDialog:lazyGrid”,否则“form_01:lazyGrid”。

以下链接将为您提供更多见解 How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"

希望这有帮助!!!

答案 1 :(得分:0)

也许您应该将lazyGrid设置为panelGrid ID? 并关闭UIComponent component = viewRoot.findComponent("form_01:meterDialog:lazyGrid");中的引号!