0

I'm actually using JSF with Primefaces, and I have a little trouble with an p:inputText in a p:dialog. Indeed I don't know how to give/keep the focus on the inputText when I open my dialog.

Here is my XHTML file :

<body>
    ...
    <p:commandButton id="add-movie-button" value="Add movie" onclick="searchdlg.show()" update="movie-list,text-search" actionListener="#{layout.clearMovieList}"/>  
    <p:dialog id="search-movie" header="Add movie" widgetVar="searchdlg" modal="true" resizable="false">    
        <h:outputLabel for="text-search" value="Movie title"/>  
        <p:inputText id="text-search" autocomplete="true" size="57" value="#{layout.searchedMovie}" style="margin-bottom:10px">
            <p:ajax event="keyup" update="movie-list" listener="#{layout.searchMovie}"/>
        </p:inputText>
        ...
    </p:dialog>
    ...
</body>

I've tried this to give the focus on my inputText when keyDown, but it doesn't change anything.

So have you any tips/advice/solution to keep the focus on an InputText in a dialog after its opening ?

Community
  • 1
  • 1
Tako
  • 661
  • 12
  • 34
  • 2
    Looks like you can focus the `` using `onShow` JavaScript method on ``. As a side note, make sure the `` has its own `` and is not inside one bigger form that contains other elements. – Luiggi Mendoza Mar 23 '13 at 05:25
  • @Luiggi Mendoza Why the `` must have is own `` not inside one bigger form ? Because I use only 1 big form in all my web page, up to now it wasn't a problem so if I can avoid to modify all my code to remove this big form it should be good. What is the inpact of having only 1 big form ? – Tako Mar 23 '13 at 05:33
  • Usually, people use `` to edit a single element of a ``, in order to achieve this the `` should be outside in its own form. That's why I give you that advice, but if it works for you having the `` in a single big `` then go with it. – Luiggi Mendoza Mar 23 '13 at 05:38
  • I've tried your `onShow` solution and change `onclick="searchdlg.show()"` by `oncomplete="searchdlg.show()"` and it works now. Thanks for your solution – Tako Mar 23 '13 at 05:49

0 Answers0