From e56e1a3348059463ff2fe15ad3c9871fa4ea51f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20P=C3=B3=C5=82grabia?= Date: Tue, 5 Jan 2021 18:40:18 +0100 Subject: [PATCH] Updating button class on hitting button. --- .../javaee/controllers/HelloController.java | 15 ++++++++++++--- javaee-demo1-jsf/src/main/webapp/index.xhtml | 5 +++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/javaee-demo1-jsf/src/main/java/pl/tpolgrabia/trainings/javaee/controllers/HelloController.java b/javaee-demo1-jsf/src/main/java/pl/tpolgrabia/trainings/javaee/controllers/HelloController.java index 0021e93..f78c5ca 100644 --- a/javaee-demo1-jsf/src/main/java/pl/tpolgrabia/trainings/javaee/controllers/HelloController.java +++ b/javaee-demo1-jsf/src/main/java/pl/tpolgrabia/trainings/javaee/controllers/HelloController.java @@ -9,12 +9,15 @@ import pl.tpolgrabia.trainings.javaee.javaeedemo.entities.User; import javax.annotation.PostConstruct; import javax.ejb.EJB; import javax.enterprise.context.RequestScoped; +import javax.faces.view.ViewScoped; import javax.inject.Named; +import java.io.Serializable; import java.util.List; @Named -@RequestScoped -public class HelloController { +@ViewScoped +public class HelloController implements Serializable { + private static final long serialVersionUID = 2780964279445984180L; private static final Logger logger = LoggerFactory.getLogger(HelloController.class); @EJB @@ -24,6 +27,7 @@ public class HelloController { private UserDao userDao; private String message; + private boolean markedAsDanger = false; public String getMessage() { return message; @@ -37,6 +41,10 @@ public class HelloController { return todosDao.findAll(); } + public boolean isMarkedAsDanger() { + return markedAsDanger; + } + public List getAllUsers() { return userDao.findAll(); } @@ -46,7 +54,8 @@ public class HelloController { return "index"; } - public void handleSimpleAction() { + public void toggleButtonClass() { + this.markedAsDanger = !markedAsDanger; logger.info("Hello action"); } diff --git a/javaee-demo1-jsf/src/main/webapp/index.xhtml b/javaee-demo1-jsf/src/main/webapp/index.xhtml index f96917b..af485fa 100644 --- a/javaee-demo1-jsf/src/main/webapp/index.xhtml +++ b/javaee-demo1-jsf/src/main/webapp/index.xhtml @@ -90,9 +90,10 @@
-