Primefaces,JavaScript和JSF不能很好地协同工作,或者我做错了什么

Tha*_*ham 1 javascript jquery jsf primefaces

这是如此简单的事情

<p:commandLink value="Tom" onclick="document.getElementById('tom').focus()"/><br/>
<input id="tom"/>
Run Code Online (Sandbox Code Playgroud)

当您单击Tom时,文本框将获得焦点.好的,现在尝试一下

<p:commandLink value="Tom" onclick="document.getElementById('tom').focus()"/><br/>
<h:inputText id="tom"/> <br/>
Run Code Online (Sandbox Code Playgroud)

当我点击什么都没发生时,我查看了萤火虫,我明白了

document.getElementById("tom") is null
Run Code Online (Sandbox Code Playgroud)

当我尝试使用jQuery时$('#tom').focus(),没有任何事情发生,没有错误,但也没有获得焦点.response当我从firebug看到时,这是(不确定这是否是来自服务器的响应)

<?xml version="1.0" encoding="utf-8"?>
<partial-response>
    <changes>
       <update id="javax.faces.ViewState"><![CDATA[455334589763307998:-2971181471269134244]]></update>
    </changes>
    <extension primefacesCallbackParam="validationFailed">{"validationFailed":false}</extension>
</partial-response>
Run Code Online (Sandbox Code Playgroud)

Bal*_*usC 8

JSF将使用组件本身的ID 预先添加子项ID UINamingContainer(h:form,h:dataTable等)UINamingContainer.您可以通过将prependId属性设置为禁用此功能false.

<h:form prependId="false">
Run Code Online (Sandbox Code Playgroud)

您将无法再在同一视图中的其他位置动态包含同一段代码.禁用此功能时请记住这一点.