2012-04-27 114 views
7

我想实现一些javas cript到我的JSF复合组件,但我有问题与id。我的Java脚本与:复合组件和ID

document.getElementById("myForm:customerId") 

不起作用,因为id是错的。我有JSF复合组成:

<composite:implementation> 
    <div id="element_customer"> 
     <h2 class="element_title">Customer</h2> 
     <h:form id="myForm"> 
      <h:inputText id="customerId" value="#{cc.attrs.customerId}"/> 
     </h:form> 
    </div> 
</composite:implementation> 

和HTML输出是:

<div id="element_customer"> 
    <h2 class="element_title">Customer</h2> 
    <form id="j_idt44:myForm" name="j_idt44:myForm" method="post" ... > 
     <input type="hidden" name="j_idt44:myForm" value="j_idt44:myForm" /> 
     <input id="j_idt44:myForm:customerId" ... name="j_idt44:myForm:customerId" /> 
    </form> 
</div> 

为什么在HTML输出 “j_idt44” 使用?

回答

13

复合组件是​​组件,如<h:form>,<h:dataTable>等。这允许您在同一个视图中有多个组件,但没有冲突的ID。

你需要给复合部件的固定ID为好。例如。

<my:composite id="someId" /> 

我也建议使用<div id="#{cc.id}">,而不是<div id="element_customer">。上面的例子将成为someId


无关到混凝土的问题,这是不完全是一个复合部件的右侧目的。一个复合组件的意图是相同的<h:inputText>等,你似乎宁愿标签文件或可能包含文件。另见When to use <ui:include>, tag files, composite components and/or custom components?

+0

谢谢。关于使用CC,我发布了关于正确使用的这个问题,但我仍然不确定:http://stackoverflow.com/questions/10056008/proper-using-of-facelet-templates-composite-components – Ziletka 2012-04-27 20:04:41

+0

看起来,我应该使用Facelet标签而不是复合组件。 – Ziletka 2012-04-27 20:15:49

+1

不客气。是的,我想是这样。 – BalusC 2012-04-27 21:11:19