2014-01-29 54 views
0

成分我不知道爲什麼我無法從我的支持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"); 

,沒有任何問題,而不是組件lazyGridCMD

+0

你的代碼中沒有帶'id =「lazyGrid」'的組件? –

+0

對不起,是個排字錯誤 – Kkloe

回答

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"

希望這有助於鏈接!

+0

form_01:lazyGrid工作!謝謝@Zim和你鏈接 – Kkloe

0

也許你應該設置lazyGrid爲panelGrid的ID? 並關閉UIComponent component = viewRoot.findComponent("form_01:meterDialog:lazyGrid");的報價!

+0

是一個輸入錯誤「丟失了 – Kkloe

+1

試試看:'viewRoot.findComponent(」form_01:lazyGrid「);' – Zim

+0

form_01:lazyGrid工作! – Kkloe