سؤال

When informing the enrollment of an employee who is not registered in the given database the system issues an error and inputText component loses focus. After a few attempts the component gets the focus but the cursor does not appear in the field.

<h:form id="findForm">

 <!-- Other -->

        <p:dialog id="mealRegisterDialog" widgetVar="mealRegisterDialog"
                header="#{lbl['mealRegisterControl']}" appendToBody="true"
                resizable="false" closable="true" width="100%" height="600"
                styleClass="container_24 clearfix grid_24">
                <h:form id="mealRegisterForm"
                    styleClass="container_24 clearfix grid_24">
                    <p:messages id="dialogMessages" closable="true" />                  
                    <div class="grid_24"
                        style="border: 1; border-color: gray; border-style: solid; font-size: 20px">
                        <p:outputLabel value="#{lbl['employee']}" styleClass="grid_3"
                            style="margin-top:5px;" />
                        <p:inputText id="employeeRegistrationInput"
                            widgetVar="employeeRegistrationInput"
                            value="#{mealFindController.employeeRegistration}"
                            styleClass="grid_21">
                            <f:convertNumber integerOnly="true" />
                            <p:focus for="employeeRegistrationInput"
                                rendered="if(document.getElementById('mealRegisterTabView:findForm:confirmDialogUser').visible)" />
                            <p:ajax event="change" process="@form employeeRegistrationInput"
                                update="@form dialogMessages"
                                oncomplete="setFocusRegistration();"
                                listener="#{mealFindController.loadDataEmployee}" />
                        </p:inputText>
                    </div>
                </h:form>       
            </p:dialog>     

<!-- Other -->

</h:form>

function setFocusRegistration() { employeeRegistrationInput.jq.focus(); }

هل كانت مفيدة؟

المحلول

RequestContext.getCurrentInstance().execute( "focus(employeeRegistrationInput)" );

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top