From 6766e90b804591f33ef28383ffd20470f3cb4d22 Mon Sep 17 00:00:00 2001
From: stephan
Date: Sun, 10 Jul 2016 13:57:10 +0200
Subject: [PATCH] Added a demo to demonstrate the `immediate` flag.
---
.../net/bootsfaces/demo/NumberGuessBean.java | 57 +++++++++++++++++++
src/main/webapp/forms/commandButton.xhtml | 41 +++++++++++++
2 files changed, 98 insertions(+)
create mode 100644 src/main/java/net/bootsfaces/demo/NumberGuessBean.java
diff --git a/src/main/java/net/bootsfaces/demo/NumberGuessBean.java b/src/main/java/net/bootsfaces/demo/NumberGuessBean.java
new file mode 100644
index 00000000..a0a1e6d3
--- /dev/null
+++ b/src/main/java/net/bootsfaces/demo/NumberGuessBean.java
@@ -0,0 +1,57 @@
+package net.bootsfaces.demo;
+
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.ViewScoped;
+import javax.faces.event.ActionEvent;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+
+import net.bootsfaces.utils.FacesMessages;
+
+@ManagedBean
+@ViewScoped
+public class NumberGuessBean {
+
+ private int counter = 1;
+
+ private int game = 1;
+
+ private int target=5;
+
+ @Min(1)
+ @Max(10)
+ private int guess=42;
+
+ public int getGuess() {
+ return guess;
+ }
+
+ public void setGuess(int guess) {
+ this.guess = guess;
+ }
+
+ public void submitGuess() {
+ String msg = "Guess #" + counter++;
+ if (guess > target) {
+ msg += " is to high.";
+ } else if (guess < target)
+ {
+ msg += " is to small.";
+ } else {
+ msg += " is correct!";
+ }
+ FacesMessages.info(msg);
+ }
+
+ public void newGame() {
+ FacesMessages.info("Start game #" + game++ + ".");
+ }
+
+ public void clearMessages() {
+
+ }
+
+ public void startNewGame(ActionEvent event) {
+ FacesMessages.info("Start game by actionListener #" + game++ + ".");
+ }
+}
diff --git a/src/main/webapp/forms/commandButton.xhtml b/src/main/webapp/forms/commandButton.xhtml
index 25d07b6a..81348372 100644
--- a/src/main/webapp/forms/commandButton.xhtml
+++ b/src/main/webapp/forms/commandButton.xhtml
@@ -480,6 +480,47 @@
instead of updating the entire form.
+ immediate
+ <b:commandButton />
supports the immediate
attribute, both in AJAX and non-AJAX requests.
+ This allows you to call a backend bean method even if the violation constraints are violated. The example below
+ allows you to start a new game no matter if the input field contains a legal value or not. The BootsFaces
+ ajax methods like onclick
execute the validations (but are executed even if there are validation
+ constraints), while the traditional actionListeners
+ bypass validation completely.
+ The classical usecase of the immediate
flag is the "cancel" button. Obviously, you don't
+ want to force the user to input correct data before they can cancel their input.
+
+
+
+ Guess a number. It has to be between 1 and 10.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Reference section