jQueryを使用してp:inputText(commentInput)コンポーネントのメソッドをオーバーライドonblur()
したいと思います。しかし、私はこのコンポーネントの固定HTMLIDを取得するのに苦労しています。私はこれまでに試しました:onfocus()
jQuery(document).ready(function() {
$(document.getElementById("[#{p:component('commentInput')}]")).onblur(function() {
$(this).css({'background-color':'#DFD8D1'});
});
});
または:
jQuery(document).ready(function() {
$("[id='#{p:component('commentInput')}']").onblur(function() {
$(this).css({'background-color':'#DFD8D1'});
});
});
どちらも同じ結果になります:Uncaught TypeError: Object [object Object] has no method 'onblur'
。
Xhtmlコードは次のようになります。
<h:form id="dtForm">
<p:outputPanel id="dataTablePanel">
<p:dataTable id="dataTable">
<p:column id="column">
<p:panel>
<p:inputText id="commentInput">
</p:inputText>
</p:panel>
</p:column>
</p:dataTable>
</p:outputPanel>
</h:form>
inputTextコンポーネントを使用しているときに、もう1つ問題があります。
<p:inputText id="commentInput" onkeypress="if (event.keyCode == 13) {onchange(); return false;}" required="#{not empty statusBean.newComment}">
<f:ajax event="change" listener="#{statusBean.test}" />
</p:inputText>
予期しない方法でイベントを発生させます。カーソルがinputTextにあると想定し、sthと入力します。そして、ページ内の別の場所をクリックすると、コンポーネントは、予期されていないときにajaxイベントを発生させます。このコンポーネントは、Facebookやsthのようなステータスへのコメントを取得するのには適していないと思います。