简体   繁体   English

外部数据表中的参考表格组件<h:form>

[英]Reference form component from datatable outside <h:form>

I'd like to refer to the component id=contractIdInputText in the form below from a datatable tag in a commandlink. 我想从命令链接的datatable标签中以下面的形式引用组件id = contractIdInputText。 I want to use its' id in the render attribute instead of @all. 我想在render属性中使用其ID,而不是@all。 I used @all below only because i was not able to refer to the id. 我在下面使用@all仅是因为我无法引用ID。 The datatable is outside and above the tags. 数据表位于标记的上方和上方。

<h:form id="contracts">
   <h:outputScript library="js" name="common.js" target="head"/>
   <h:panelGrid columns="3"   columnClasses="rightalign,leftalign,leftalign">

   <h:outputLabel for="contractIdInputText" rendered="true" value="Contract Nooo.: " />
   <h:inputText id="contractIdInputText" required="true"                                         value="#contractManager.newContractId}" />
</form>

This is the datatable's commandlink: 这是数据表的命令链接:

 <h:commandLink id="editLink" value="#{bundle.ListUnitEditLink}" 
     action="#{contractManager.updateContract}">
     <f:ajax onevent="disablePK" render="@all" />
 </h:commandLink>

The whole purpose of the ajax in the link is to disable the form component when i click the commandlink and populate the form. 链接中Ajax的全部目的是当我单击命令链接并填充表单时禁用表单组件。 I've also noticed that much as using the @all does what i want (populate the form with the inputText disabled), it results in me needing to click the commandlink twice on an commandlink in he datatable for the form to be populated with another item. 我还注意到,与使用@all一样,我想要做很多事情(在禁用inputText的情况下填充表单),这导致我需要在数据表中的命令链接上单击命令链接两次,以使用另一个表单填充该表单。项目。 why is this happening? 为什么会这样呢?

If they are not in the same NamingContainer parent, then you should just reference the other component by its absolute client ID instead of a (invalid) relative client ID. 如果它们不在同一NamingContainer父级中,那么您应该仅通过其绝对客户端ID而不是(无效的)相对客户端ID来引用另一个组件。 The absolute client ID is the full client ID (as you can see in the generated HTML output), prefixed with the naming container separator character (which defaults to : ). 绝对客户ID是完整的客户端ID(如可以在生成的HTML输出中看到),用命名容器分隔符前缀(默认为: )。

So, this should do 所以,这应该做

<f:ajax ... render=":contracts:contractIdInputText" />

(assuming that the <form id="contracts"> is by itself not in another NamingContainer parent, again, just check the generated HTML output to be sure) (假设<form id="contracts">本身不在另一个NamingContainer父级中,同样,只需检查生成的HTML输出即可)

As to why you need to click the command link twice, this is most likely related to JSF spec issue 790 . 至于为什么需要单击两次命令链接,这很可能与JSF规范问题790有关 A fix would be to explicitly include the other form in the render . 解决方法是在render明确包含其他形式。 See also Ajax rendering of content which contains other form . 另请参见内容的Ajax呈现,其中包含其他形式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM