CommandButton в PrimeFaces Бин
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.primefaces.examples.view;
import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped;
import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent;
/** * * @author martyshov */ @ManagedBean @RequestScoped public class PersonBean {
/** * Creates a new instance of PersonBean */ public PersonBean() { }
private String firstname;
private String surname;
public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; }
public String getSurname() { return surname; } public void setSurname(String surname) { this.surname = surname; }
public void savePerson(ActionEvent actionEvent) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Добро пожаловать " + firstname + " " + surname + "!")); } }
Интерфейс <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:p="http://primefaces.org/ui" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"> <h:head> <title>Facelet Title</title> </h:head> <h:body>
<h:form id="form">
<p:panel id="panel" header="New Person" style="margin-bottom:10px;"> <p:messages id="messages" /> <h:panelGrid columns="3"> <h:outputLabel for="firstname" value="Фамилия *" /> <p:inputText id="firstname" value="#{personBean.firstname}" required="true" label="Firstname"> </p:inputText> <p:message for="firstname" />
<h:outputLabel for="surname" value="Имя *" /> <p:inputText id="surname" value="#{personBean.surname}" required="true" label="Surname"/> <p:message for="surname" /> </h:panelGrid> </p:panel>
<p:commandButton value="Ajax кнопка" update="panel,display" id="ajax" actionListener="#{personBean.savePerson}" styleClass="ui-priority-primary"/>
<p:commandButton value="Non-Ajax кнопка" actionListener="#{personBean.savePerson}" ajax="false" />
<p:commandButton value="With Icon" actionListener="#{personBean.savePerson}" id="withIcon" update="panel,display" icon="ui-icon-disk" />
<p:commandButton actionListener="#{personBean.savePerson}" update="panel,display" id="iconOnly" icon="ui-icon-disk" title="Icon Only"/>
<p:commandButton value="Отключена" disabled="true" id="disabled" />
<p:panel id="display" header="Информация" style="margin-top:10px;"> <h:panelGrid columns="2"> <h:outputText value="Firstname: " /> <h:outputText value="#{personBean.firstname}" />
<h:outputText value="Surname: " /> <h:outputText value="#{personBean.surname}" /> </h:panelGrid> </p:panel>
</h:form>
</h:body> </html>
update - указываем что обновляем через запятую по умолчанию выполняется ajax запрос, если нужен простой, то прописываем ajax="false" actionListener - указываем метод бина, который вызывается при нажатии
|