📜  Primefaces CommandButton

📅  最后修改于: 2021-01-08 04:26:53             🧑  作者: Mango

PrimeFaces命令按钮

它是JSF标准h:commandButton的扩展版本。它包括ajax,部分处理和蒙皮功能。

组件用于在JSF应用程序中创建按钮。当我们要在Web应用程序中执行操作时,这很有用。

该组件具有下表列出的各种属性。

CommandButton属性

Attribute Default value Type Description
rendered true Boolean It is used to specify the rendering of the component.
value null String It is used to set label for the button.
action null MethodExpr/String It is used to set action when button is clicked.
actionListener null MethodExpr It is used to set actionlistener that’d be processed when button is clicked.
type submit String It sets the behavior of the button.
ajax true Boolean It specifies the submit mode.
async false Boolean When set to true, ajax requests are not queued.
process null String It is used to process partially instead of whole view.
update null String It is used for component to be updated with ajax.
global true Boolean It defines whether to trigger ajaxStatus or not.
delay null String It is used to set delay value.
partialSubmit false Boolean It enables serialization of values belonging to the partially
processed components only.
timeout 0 Integer It is used to set timeout for the ajax request in milliseconds.

在下面的示例中,我们正在实现组件。本示例包含以下文件。

JSF文件

// commandButton.xhtml





CommandButton








ManagedBean

// CommandButton.java

package com.javatpoint;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
@ManagedBean
public class CommandButton {
public void commandButtonAction(ActionEvent actionEvent) {
addMessage("You just clicked Button");
}
public void addMessage(String summary) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary,  null);
FacesContext.getCurrentInstance().addMessage(null, message);
}
}

输出: