Merhaba,
PrimeFaces'in odaklanma(focus) bileşeni oluşan uyarı sonucu uyarının çıkmasına sebep olan bileşene otomatik olarak odaklanmasını sağlar. Örneğin bir formda gerekli olan bir alanı boş geçmek istediğimizde uyarı vererek imlecin o alana gelmesini istiyorsak bu bileşeni kullanabiliriz.
Bunun için yapmamız gereken
<p:focus context="display"/>
şeklinde kullanmak olacaktır.
Burada
display : h:panelGroup u ifade eder. Yani bileşenlerin içinde bulundu div'i ifade eder. Focus'u uygulamak istediğimiz div'in id sini vermemiz yeterli olacaktır.
<h:form id="CustomerCreateForm">
<h:panelGroup id="display" rendered="#{customerController.selected != null}">
<p:focus context="display"/>
<p:panelGrid columns="2" columnClasses="column">
<p:outputLabel value="#{messages.CreateCustomerLabel_customerId}" for="customerId" />
<p:inputText id="customerId" value="#{customerController.selected.customerId}" title="#{messages.CreateCustomerTitle_customerId}" required="true" requiredMessage="#{messages.CreateCustomerRequiredMessage_customerId}"/>
<p:outputLabel value="#{messages.CreateCustomerLabel_name}" for="name" />
<p:inputText id="name" required="true" value="#{customerController.selected.name}" title="#{messages.CreateCustomerTitle_name}" size="30" maxlength="30"/>
<p:outputLabel value="#{messages.CreateCustomerLabel_addressline1}" for="addressline1" />
<p:inputText id="addressline1" required="true" value="#{customerController.selected.addressline1}" title="#{messages.CreateCustomerTitle_addressline1}" size="30" maxlength="30"/>
<p:outputLabel value="#{messages.CreateCustomerLabel_addressline2}" for="addressline2" />
<p:inputText id="addressline2" value="#{customerController.selected.addressline2}" title="#{messages.CreateCustomerTitle_addressline2}" size="30" maxlength="30"/>
<p:outputLabel value="#{messages.CreateCustomerLabel_city}" for="city" />
<p:inputText id="city" value="#{customerController.selected.city}" title="#{messages.CreateCustomerTitle_city}" size="25" maxlength="25"/>
<p:outputLabel value="#{messages.CreateCustomerLabel_state}" for="state" />
<p:inputText id="state" value="#{customerController.selected.state}" title="#{messages.CreateCustomerTitle_state}" size="2" maxlength="2"/>
<p:outputLabel value="#{messages.CreateCustomerLabel_zip}" for="zip" />
<p:selectOneMenu id="zip" value="#{customerController.selected.zip}" required="true" requiredMessage="#{messages.CreateCustomerRequiredMessage_zip}" converter="microMarketConverter">
<f:selectItem itemLabel="#{messages.SelectOneMessage}"/>
<f:selectItems value="#{microMarketController.items}"
var="zipItem"
itemValue="#{zipItem}"
itemLabel="#{zipItem.zipCode.toString()}"
/>
</p:selectOneMenu>
<p:outputLabel value="#{messages.CreateCustomerLabel_discountCode}" for="discountCode" />
<p:selectOneMenu id="discountCode" value="#{customerController.selected.discountCode}" required="true" requiredMessage="#{messages.CreateCustomerRequiredMessage_discountCode}" converter="discountCodeConverter">
<f:selectItem itemLabel="#{messages.SelectOneMessage}"/>
<f:selectItems value="#{discountCodeController.items}"
var="discountCodeItem"
itemValue="#{discountCodeItem}"
itemLabel="#{discountCodeItem.discountCode.toString()}"
/>
</p:selectOneMenu>
</p:panelGrid>
<p:commandButton actionListener="#{customerController.saveNew}" value="#{messages.Save}" update="display,:CustomerListForm:datalist,:growl" oncomplete="handleSubmit(xhr,status,args,PF('CustomerCreateDialog'));">
<p:confirm header="#{messages.ConfirmationHeader}" message="#{messages.ConfirmCreateMessage}" icon="ui-icon-alert"/>
</p:commandButton>
<p:commandButton value="#{messages.Cancel}" oncomplete="PF('CustomerCreateDialog').hide()" update="display" process="@this" immediate="true" resetValues="true"/>
</h:panelGroup>
</h:form>
0 Yorumlar