You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2018/11/07 14:43:48 UTC

[myfaces-tobago] branch master updated: Using enum Outcome in demo

This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/master by this push:
     new 8ea0ab4  Using enum Outcome in demo
8ea0ab4 is described below

commit 8ea0ab46cc97b6e94a7220fcf16f00dcb02bf8ba
Author: Udo Schnurpfeil <lo...@apache.org>
AuthorDate: Wed Nov 7 15:43:34 2018 +0100

    Using enum Outcome in demo
---
 .../tobago/example/demo/ButtonLinkController.java  | 12 +++++-----
 .../tobago/example/demo/LoginController.java       |  6 ++---
 .../myfaces/tobago/example/demo/Outcome.java       | 27 ++++++++++++++++++++++
 3 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/ButtonLinkController.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/ButtonLinkController.java
index f6a77e1..f2c2389 100644
--- a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/ButtonLinkController.java
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/ButtonLinkController.java
@@ -30,18 +30,18 @@ public class ButtonLinkController implements Serializable {
 
   private static final Logger LOG = LoggerFactory.getLogger(ButtonLinkController.class);
 
-  public String linkToComponentsRoot() {
+  public Outcome linkToComponentsRoot() {
     LOG.info("link to components root");
-    return "/content/20-component/component.xhtml?faces-redirect=true";
+    return Outcome.COMPONENT_COMPONENT;
   }
 
-  public String actionPage() {
+  public Outcome actionPage() {
     LOG.info("link to action.xhtml");
-    return "/content/40-test/4000-button+link/x-action.xhtml?faces-redirect=true";
+    return Outcome.TEST_BUTTONLINK_XACTION;
   }
 
-  public String targetActionPage() {
+  public Outcome targetActionPage() {
     LOG.info("link to targetAction.xhtml");
-    return "/content/40-test/4000-button+link/x-targetAction.xhtml";
+    return Outcome.TEST_BUTTONLINK_XTARGETACTION;
   }
 }
diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/LoginController.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/LoginController.java
index ea5fbc6..426dd6c 100644
--- a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/LoginController.java
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/LoginController.java
@@ -28,7 +28,6 @@ import javax.faces.context.FacesContext;
 import javax.inject.Named;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 import java.io.IOException;
 
@@ -41,17 +40,16 @@ public class LoginController {
   private String username;
   private String password;
 
-  public String login() throws ServletException, IOException {
+  public Outcome login() throws ServletException {
     final FacesContext facesContext = FacesContext.getCurrentInstance();
     final ExternalContext externalContext = facesContext.getExternalContext();
     final HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
-    final HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
 
     LOG.info("Try to login user: '{}'", username);
     request.login(username, password);
     LOG.info("Successful login user: '{}'", username);
 
-    return "/content/30-concept/80-security/20-roles/x-login.xhtml?faces-redirect=true";
+    return Outcome.CONCEPT_SECURITY_ROLES_XLOGIN;
   }
 
   public String logout() throws ServletException, IOException {
diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Outcome.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Outcome.java
new file mode 100644
index 0000000..3a3d0e7
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Outcome.java
@@ -0,0 +1,27 @@
+package org.apache.myfaces.tobago.example.demo;
+
+/**
+ * Class to collect all the JSF outcomes.
+ */
+public enum Outcome {
+
+  CONCEPT_SECURITY_ROLES_XLOGIN(
+      "/content/30-concept/80-security/20-roles/x-login.xhtml?faces-redirect=true"),
+  COMPONENT_COMPONENT(
+      "/content/20-component/component.xhtml?faces-redirect=true"),
+  TEST_BUTTONLINK_XACTION(
+      "/content/40-test/4000-button+link/x-action.xhtml?faces-redirect=true"),
+  TEST_BUTTONLINK_XTARGETACTION(
+      "/content/40-test/4000-button+link/x-targetAction.xhtml");
+
+  private final String outcome;
+
+  Outcome(final String outcome) {
+    this.outcome = outcome;
+  }
+
+  @Override
+  public String toString() {
+    return outcome;
+  }
+}