我想在使用复合组件的JSF 2项目中干掉弹出窗口。在JavaScript中访问JSF嵌套复合组件元素
此代码库使用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>
弹出作品大多不如预期,即我可以进入的东西,ok和cancel按钮工作,并且验证也起作用。
什么不起作用是我的JavaScript代码,当弹出窗口打开时,我的JavaScript代码试图集中输入。
当我查看Firebug中的页面时,发现输入的ID是MyForm:j_idt63:j_idt64:j_idt67:theInput
,但JavaScript代码尝试集中ID为MyForm:j_idt63:theInput
的元素。
为什么#{cc.clientId}
在input.xhtml
不是输入结束后得到的正确ID?我需要做些什么来完成这项工作?
我见过BalusC's hint on adding a binding但我不想绑定,以便复合组件可以独立于任何后备bean。
有什么我在这里失踪?
绑定方法似乎只适用于输入,但不适用于例如“CommandButton”。这是正确的还是我错过了什么?当我添加一个'binding =“#{okButton}”''属性到一个按钮时,它不会被渲染。这不是原始问题的一部分;我尝试在输入上使用onKeyPress事件处理程序,并在用户按下enter键时单击确定按钮,而在用户按下esc时单击取消按钮。 – Robert
如果多个按钮组件共享相同的“绑定”,则可能发生这种情况。你应该按照答案中的解释使用'binding =“#{cc.okButton}”'。 – BalusC