Skip to main content

JSF2.0 - InputTextArea inside Dialog cannot be retrieved via Jquery during the dialog"s onShow event



I have the following dialog inside my .xhtml page.







<p:dialog widgetVar="exampleDialog" onShow="fillTextArea()" >

<p:tabView id="tabView">

<p:tab id="exampleTab" title="Example">

<p:inputTextarea id="someInputTextArea" autoResize="false"

value="" />

</p:tab>

</p:tabView>

</p:dialog>







The dialog is shown when a button is clicked. The fillTextArea javascript function is defined inside script tags at the head of the document.







function fillTextArea() {

console.log(jQuery("textarea[id='someInputTextArea']")); // logs empty array []

console.log($("[id='someInputTextArea']")); // logs empty array []

jQuery("textarea[id='someInputTextArea']").val('xxx'); // does nothing

}







What's the problem? Why can't I retrieve the input text area?





Instead of using the onShow event of the Dialog , I tried:







exampleDialog.show();

fillTextArea();







just in case. But this didn't work neither. I'm trying to set the contents of the inputTextArea .





Any help appreciated. Thanks.


Comments

  1. jQuery works on the JSF-generated HTML DOM tree, not on the JSF source code. JSF components do not necessarily generate the same client ID (the HTML element ID) as you have specified in the component ID. They may be prepended with IDs of the parent NamingContainer components. The <h:form> and <p:tabView> are such components.

    Open the page in webbrowser, rightclick and View Source and locate the generated HTML code of the <p:inputTextarea>. It'll look something like this:

    <textarea id="formId:tabViewId:textareaId">


    You need to specify exactly this ID in the jQuery selector.

    $("[id='formId:tabViewId:textareaId']");


    See also:


    How to refer to a JSF component Id in jquery?
    How to select PrimeFaces UI or JSF components using jQuery?

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.