【发布时间】:2016-01-25 01:27:55
【问题描述】:
我正在尝试使用复合组件在我的 JSF 2 项目中干燥弹出窗口。
此代码库使用 Icefaces 3.3.0(出于历史原因,使用了 1.8.2 兼容层)、Mojarra 2.2.7 和 Glassfish 4.1。
我有 input.xhtml,它提供文本输入并使用 2 按钮弹出窗口(确定/取消),而后者又建立在基本弹出窗口之上。
input.xhtml:
<composite:interface>
<!-- ... -->
<composite:editableValueHolder name="forInput" targets="theInput"/>
</composite:interface>
<composite:implementation>
<my:popup2Buttons>
<ice:inputText id="theInput" value="..."/>
<script>setInputFocus("#{cc.clientId}:theInput");</script>
</my:popup2Buttons>
</composite:implementation>
popup2buttons.xhtml:
<composite:interface>
<!-- ... -->
</composite:interface>
<composite:implementation>
<my:popup>
<composite:insertChildren/>
<ice:commandButton id="OkButton"
value="Ok"
actionListener="..."/>
<ice:commandButton id="CancelButton"
value="Cancel"
actionListener="..."/>
</my:popup>
</composite:implementation>
popup.xhtml:
<composite:interface>
<!-- ... -->
</composite:interface>
<composite:implementation>
<script>
function setInputFocus(id) {
document.getElementById(id).focus();
}
</script>
<ice:panelPopup>
<f:facet name="body">
<h:panelGroup>
<composite:insertChildren/>
</h:panelGroup>
</f:facet>
</ice:panelPopup>
</composite:implementation>
弹出窗口大部分按预期工作,即我可以输入内容,确定和取消按钮工作,验证也工作。
不起作用的是我的 JavaScript 代码在弹出窗口打开时尝试聚焦输入。
当我在 Firebug 中查看页面时,我看到输入的 ID 是 MyForm:j_idt63:j_idt64:j_idt67:theInput,但 JavaScript 代码试图聚焦 ID 为 MyForm:j_idt63:theInput 的元素。
为什么input.xhtml 中的#{cc.clientId} 不是输入最终得到的正确ID?我需要做什么才能完成这项工作?
我见过BalusC's hint on adding a binding,但我不想要一个绑定,这样复合组件就可以独立于任何支持bean。
我还有什么遗漏的吗?
【问题讨论】:
标签: jsf jsf-2 icefaces composite-component