You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2012/10/12 15:38:09 UTC
[1/2] git commit: DELTASPIKE-281 add LocaleResolver for JSF projects
Updated Branches:
refs/heads/master c2951e9c0 -> 37ebe0b3c
DELTASPIKE-281 add LocaleResolver for JSF projects
if a ViewRoot is available, we take the Locale from there.
Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/37ebe0b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/37ebe0b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/37ebe0b3
Branch: refs/heads/master
Commit: 37ebe0b3c428cd64734a3dd3eee4d94a3f715e26
Parents: c3364f2
Author: Mark Struberg <st...@apache.org>
Authored: Fri Oct 12 15:37:30 2012 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Fri Oct 12 15:37:30 2012 +0200
----------------------------------------------------------------------
.../jsf/impl/message/JsfLocaleResolver.java | 54 +++++++++++++++
.../test/jsf/impl/message/JsfMessageTest.java | 41 +++++-------
2 files changed, 71 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/37ebe0b3/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfLocaleResolver.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfLocaleResolver.java b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfLocaleResolver.java
new file mode 100644
index 0000000..76d5f54
--- /dev/null
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/message/JsfLocaleResolver.java
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+package org.apache.deltaspike.jsf.impl.message;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Specializes;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+
+import java.util.Locale;
+
+import org.apache.deltaspike.core.impl.message.DefaultLocaleResolver;
+
+/**
+ * A LocaleResolver which evaluates the FacesContext.
+ */
+@ApplicationScoped
+@Specializes
+public class JsfLocaleResolver extends DefaultLocaleResolver
+{
+ @Override
+ public Locale getLocale()
+ {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ if (facesContext != null)
+ {
+ UIViewRoot viewRoot = facesContext.getViewRoot();
+ if (viewRoot != null)
+ {
+ // if a ViewRoot is present we return the Locale from there
+ return viewRoot.getLocale();
+ }
+ }
+
+ // if no FacesContext is present we return the default Locale
+ return super.getLocale();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/37ebe0b3/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java
index 2e1767a..b22b36a 100644
--- a/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java
+++ b/deltaspike/modules/jsf/impl/src/test/java/org/apache/deltaspike/test/jsf/impl/message/JsfMessageTest.java
@@ -1,21 +1,21 @@
/*
-* 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.
-*/
+ * 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.
+ */
package org.apache.deltaspike.test.jsf.impl.message;
@@ -39,7 +39,6 @@ import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
-import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
@@ -77,12 +76,7 @@ public class JsfMessageTest
{
driver.get(new URL(contextPath, "page.xhtml").toString());
- //X TODO remove, it's just for debugging the server side:
- //X Thread.sleep(600000L);
-
-
// check the JSF FacesMessages
-
Assert.assertNotNull(ExpectedConditions.presenceOfElementLocated(By.xpath("id('messages')")).apply(driver));
Assert.assertTrue(ExpectedConditions.textToBePresentInElement(
@@ -100,7 +94,6 @@ public class JsfMessageTest
// check the free message usage
Assert.assertTrue(ExpectedConditions.textToBePresentInElement(
By.id("test:valueOutput"), "a simple message without a param.").apply(driver));
-
}
}