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

[myfaces-tobago] branch master updated: TOBAGO-1929 Wrong severity for message on form elements

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

hnoeth 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 db26410  TOBAGO-1929 Wrong severity for message on form elements
db26410 is described below

commit db2641055151676bdf4832bd1cdddd682c0caf2d
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Fri Nov 9 15:36:36 2018 +0100

    TOBAGO-1929 Wrong severity for message on form elements
    
    * severity is now correct for MyFaces 2.2 and 2.3
    * add QUnitTest
---
 .../tobago/renderkit/css/BootstrapClass.java       | 28 ++++++-------
 .../content/40-test/4950-severity/severity.test.js | 46 ++++++++++++++++++++++
 .../content/40-test/4950-severity/severity.xhtml   | 34 ++++++++++++++++
 3 files changed, 92 insertions(+), 16 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java
index d7ebbff..c272548 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/BootstrapClass.java
@@ -40,6 +40,7 @@ import java.util.Map;
 
 /**
  * CSS classes for the Bootstrap Library.
+ *
  * @since 3.0.0
  */
 public enum BootstrapClass implements CssItem {
@@ -533,29 +534,24 @@ public enum BootstrapClass implements CssItem {
     if (severity == null) {
       return null;
     }
-
-    switch (severity.getOrdinal()) {
-      case 1:
-        return BootstrapClass.BORDER_INFO;
-      case 2:
-        return BootstrapClass.BORDER_WARNING;
-      default:
-        return BootstrapClass.BORDER_DANGER;
-    }
+    return getSeverityCssItem(severity, BORDER_INFO, BORDER_WARNING, BORDER_DANGER);
   }
 
   public static CssItem buttonColor(final FacesMessage.Severity severity) {
     if (severity == null) {
       return null;
     }
+    return getSeverityCssItem(severity, BTN_INFO, BTN_WARNING, BTN_DANGER);
+  }
 
-    switch (severity.getOrdinal()) {
-      case 1:
-        return BootstrapClass.BTN_INFO;
-      case 2:
-        return BootstrapClass.BTN_WARNING;
-      default:
-        return BootstrapClass.BTN_DANGER;
+  private static CssItem getSeverityCssItem(FacesMessage.Severity severity,
+      BootstrapClass info, BootstrapClass warning, BootstrapClass error) {
+    if (severity.equals(FacesMessage.SEVERITY_INFO)) {
+      return info;
+    } else if (severity.equals(FacesMessage.SEVERITY_WARN)) {
+      return warning;
+    } else {
+      return error;
     }
   }
 
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/4950-severity/severity.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/4950-severity/severity.test.js
new file mode 100644
index 0000000..e0bd5f5
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/4950-severity/severity.test.js
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+QUnit.test("Check severity CSS classes", function (assert) {
+  var submitButtonFn = jQueryFrameFn("#page\\:mainForm\\:submit");
+  var fatalInputFieldFn = jQueryFrameFn("#page\\:mainForm\\:fatal\\:\\:field");
+  var errorInputFieldFn = jQueryFrameFn("#page\\:mainForm\\:error\\:\\:field");
+  var warnInputFieldFn = jQueryFrameFn("#page\\:mainForm\\:warn\\:\\:field");
+  var infoInputFieldFn = jQueryFrameFn("#page\\:mainForm\\:info\\:\\:field");
+  var fatalButtonFn = jQueryFrameFn("#page\\:mainForm\\:fatal .tobago-messages-button");
+  var errorButtonFn = jQueryFrameFn("#page\\:mainForm\\:error .tobago-messages-button");
+  var warnButtonFn = jQueryFrameFn("#page\\:mainForm\\:warn .tobago-messages-button");
+  var infoButtonFn = jQueryFrameFn("#page\\:mainForm\\:info .tobago-messages-button");
+
+  var TTT = new TobagoTestTool(assert);
+  TTT.action(function () {
+    submitButtonFn().click();
+  });
+  TTT.waitForResponse();
+  TTT.asserts(8, function () {
+    assert.ok(fatalInputFieldFn().hasClass("border-danger"));
+    assert.ok(errorInputFieldFn().hasClass("border-danger"));
+    assert.ok(warnInputFieldFn().hasClass("border-warning"));
+    assert.ok(infoInputFieldFn().hasClass("border-info"));
+
+    assert.ok(fatalButtonFn().hasClass("btn-danger"));
+    assert.ok(errorButtonFn().hasClass("btn-danger"));
+    assert.ok(warnButtonFn().hasClass("btn-warning"));
+    assert.ok(infoButtonFn().hasClass("btn-info"));
+  });
+  TTT.startTest();
+});
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/4950-severity/severity.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/4950-severity/severity.xhtml
new file mode 100644
index 0000000..432a45f
--- /dev/null
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/40-test/4950-severity/severity.xhtml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<ui:composition template="/main.xhtml"
+                xmlns="http://www.w3.org/1999/xhtml"
+                xmlns:tc="http://myfaces.apache.org/tobago/component"
+                xmlns:ui="http://java.sun.com/jsf/facelets"
+>
+  <ui:param name="title" value="messages"/>
+  <tc:button id="submit" label="Submit"/>
+
+  <tc:section label="Severity">
+    <tc:in id="fatal" label="Fatal" validator="#{severityController.addFatal}"/>
+    <tc:in id="error" label="Error" validator="#{severityController.addError}"/>
+    <tc:in id="warn" label="Warn" validator="#{severityController.addWarn}"/>
+    <tc:in id="info" label="Info" validator="#{severityController.addInfo}"/>
+  </tc:section>
+</ui:composition>