JBoss Rich Faces SVN: r19043 - in modules/tests/metamer/trunk: ftest-source and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: ppitonak(a)redhat.com
Date: 2010-08-31 09:47:09 -0400 (Tue, 31 Aug 2010)
New Revision: 19043
Modified:
modules/tests/metamer/trunk/ftest-source/pom.xml
modules/tests/metamer/trunk/ftest/pom.xml
Log:
* richfaces-selenium changed from final to snapshot
Modified: modules/tests/metamer/trunk/ftest/pom.xml
===================================================================
--- modules/tests/metamer/trunk/ftest/pom.xml 2010-08-31 13:36:49 UTC (rev 19042)
+++ modules/tests/metamer/trunk/ftest/pom.xml 2010-08-31 13:47:09 UTC (rev 19043)
@@ -25,7 +25,7 @@
<parent>
<artifactId>functional-test-jboss-ci-template</artifactId>
<groupId>org.jboss.test.richfaces-selenium</groupId>
- <version>1.5.1.Final</version>
+ <version>1.5.2-SNAPSHOT</version>
</parent>
<groupId>org.richfaces.tests</groupId>
Modified: modules/tests/metamer/trunk/ftest-source/pom.xml
===================================================================
--- modules/tests/metamer/trunk/ftest-source/pom.xml 2010-08-31 13:36:49 UTC (rev 19042)
+++ modules/tests/metamer/trunk/ftest-source/pom.xml 2010-08-31 13:47:09 UTC (rev 19043)
@@ -37,7 +37,7 @@
<dependency>
<artifactId>root</artifactId>
<groupId>org.jboss.test.richfaces-selenium</groupId>
- <version>1.5.1.Final</version>
+ <version>1.5.2-SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
14 years, 3 months
JBoss Rich Faces SVN: r19042 - branches/RF-7560.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-08-31 09:36:49 -0400 (Tue, 31 Aug 2010)
New Revision: 19042
Modified:
branches/RF-7560/
Log:
Initialized merge tracking via "svnmerge" with revisions "1-19037" from
https://svn.jboss.org/repos/richfaces/trunk
Property changes on: branches/RF-7560
___________________________________________________________________
Name: svnmerge-integrated
- /branches/RFPL-434:1-19024 /branches/RFPL-754:1-18909
+ /trunk:1-19037 /branches/RFPL-754:1-18909 /branches/RFPL-434:1-19024
14 years, 3 months
JBoss Rich Faces SVN: r19041 - trunk.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-08-31 09:16:54 -0400 (Tue, 31 Aug 2010)
New Revision: 19041
Modified:
trunk/
Log:
Removed merge tracking for "svnmerge" for
https://svn.jboss.org/repos/richfaces/branches/RFPL-434
Property changes on: trunk
___________________________________________________________________
Name: svnmerge-integrated
- /branches/RFPL-754:1-18909 /branches/RFPL-434:1-19038
+ /branches/RFPL-754:1-18909
14 years, 3 months
JBoss Rich Faces SVN: r19040 - branches.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-08-31 09:16:28 -0400 (Tue, 31 Aug 2010)
New Revision: 19040
Removed:
branches/RFPL-434/
Log:
branch is now closed
14 years, 3 months
JBoss Rich Faces SVN: r19039 - in trunk: core/api/src/main/java/org/richfaces/application and 2 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-08-31 09:13:39 -0400 (Tue, 31 Aug 2010)
New Revision: 19039
Added:
trunk/core/impl/src/test/java/org/richfaces/application/MessageFactoryImplTest.java
Removed:
trunk/core/impl/src/test/java/org/richfaces/application/MessageFactoryImpltest.java
Modified:
trunk/
trunk/core/api/src/main/java/org/richfaces/application/MessageFactory.java
trunk/core/impl/src/main/java/org/richfaces/application/MessageFactoryImpl.java
Log:
Merged revisions 19030-19031,19034 via svnmerge from
https://svn.jboss.org/repos/richfaces/branches/RFPL-434
Property changes on: trunk
___________________________________________________________________
Name: svnmerge-integrated
- /branches/RFPL-434:1-19024 /branches/RFPL-754:1-18909
+ /branches/RFPL-754:1-18909 /branches/RFPL-434:1-19038
Modified: trunk/core/api/src/main/java/org/richfaces/application/MessageFactory.java
===================================================================
--- trunk/core/api/src/main/java/org/richfaces/application/MessageFactory.java 2010-08-31 12:41:57 UTC (rev 19038)
+++ trunk/core/api/src/main/java/org/richfaces/application/MessageFactory.java 2010-08-31 13:13:39 UTC (rev 19039)
@@ -35,4 +35,6 @@
public FacesMessage createMessage(FacesContext facesContext, Severity severity, Enum<?> messageKey, Object... args);
+ public String getMessageText(FacesContext facesContext, Enum<?> messageKey, Object... args);
+
}
Modified: trunk/core/impl/src/main/java/org/richfaces/application/MessageFactoryImpl.java
===================================================================
--- trunk/core/impl/src/main/java/org/richfaces/application/MessageFactoryImpl.java 2010-08-31 12:41:57 UTC (rev 19038)
+++ trunk/core/impl/src/main/java/org/richfaces/application/MessageFactoryImpl.java 2010-08-31 13:13:39 UTC (rev 19039)
@@ -40,6 +40,53 @@
*/
public class MessageFactoryImpl implements MessageFactory {
+ protected static interface Factory<T> {
+
+ public T create(ResourceBundle bundle, Enum<?> messageKey, Object... args) throws MissingResourceException;
+
+ }
+
+ private static final Factory<FacesMessage> MESSAGE_FACTORY = new Factory<FacesMessage>() {
+
+ public FacesMessage create(ResourceBundle bundle, Enum<?> messageKey, Object... args)
+ throws MissingResourceException {
+
+ String messageId = messageKey.toString();
+
+ String summary = null;
+ String detail = null;
+
+ try {
+ summary = bundle.getString(messageId);
+ detail = bundle.getString(messageId + "_detail");
+ } catch (MissingResourceException e) {
+ // do nothing
+ }
+
+ if (summary != null) {
+ String formattedSummary = MessageFormat.format(summary, args);
+ String formattedDetail = null;
+
+ if (detail != null) {
+ formattedDetail = MessageFormat.format(detail, args);
+ }
+
+ return new FacesMessage(formattedSummary, formattedDetail);
+ }
+
+ return null;
+ }
+ };
+
+ private static final Factory<String> LABEL_FACTORY = new Factory<String>() {
+
+ public String create(ResourceBundle bundle, Enum<?> messageKey, Object... args) throws MissingResourceException {
+ String pattern = bundle.getString(messageKey.toString());
+ return MessageFormat.format(pattern, args);
+ }
+
+ };
+
private BundleLoader bundleLoader;
public MessageFactoryImpl(BundleLoader bundleLoader) {
@@ -73,26 +120,46 @@
throw new NullPointerException("messageKey");
}
- FacesMessage result = null;
+ FacesMessage result = detectLocalesAndCreate(facesContext, MESSAGE_FACTORY, messageKey, args);
- Locale locale = detectLocale(facesContext);
+ if (result != null) {
+ result.setSeverity(severity);
+ }
+
+ return result;
+ }
+
+ public String getMessageText(FacesContext facesContext, Enum<?> messageKey, Object... args) {
+ String text = detectLocalesAndCreate(facesContext, LABEL_FACTORY, messageKey, args);
+ if (text == null) {
+ text = "???" + messageKey + "???";
+ }
+
+ return text;
+ }
+
+ protected <T> T detectLocalesAndCreate(FacesContext context, Factory<T> factory, Enum<?> messageKey, Object... args) {
+
+ T result = null;
+
+ Locale locale = detectLocale(context);
if (locale != null) {
- result = createMessage(facesContext, severity, locale, messageKey, args);
+ result = create(context, factory, locale, messageKey, args);
}
if (result == null) {
Locale defaultLocale = Locale.getDefault();
if (!defaultLocale.equals(locale)) {
- result = createMessage(facesContext, severity, defaultLocale, messageKey, args);
+ result = create(context, factory, defaultLocale, messageKey, args);
}
}
-
+
return result;
}
-
- protected FacesMessage createMessage(FacesContext context, Severity severity, Locale locale, Enum<?> messageKey,
+
+ protected <T> T create(FacesContext context, Factory<T> factory, Locale locale, Enum<?> messageKey,
Object... args) {
MessageBundle messageBundle = messageKey.getClass().getAnnotation(MessageBundle.class);
@@ -101,41 +168,25 @@
return null;
}
- String messageId = messageKey.toString();
+ T result = null;
- String summary = null;
- String detail = null;
-
try {
ResourceBundle bundle = bundleLoader.getApplicationBundle(context, messageKey, locale);
- summary = bundle.getString(messageId);
- detail = bundle.getString(messageId + "_detail");
+ result = factory.create(bundle, messageKey, args);
} catch (MissingResourceException e) {
// do nothing
}
- if (summary == null) {
+ if (result == null) {
try {
ResourceBundle bundle = bundleLoader.getBundle(messageKey, locale);
- summary = bundle.getString(messageId);
- detail = bundle.getString(messageId + "_detail");
+ result = factory.create(bundle, messageKey, args);
} catch (MissingResourceException e) {
// do nothing
}
}
- if (summary == null) {
- return null;
- }
-
- String formattedSummary = MessageFormat.format(summary, args);
- String formattedDetail = null;
-
- if (detail != null) {
- formattedDetail = MessageFormat.format(detail, args);
- }
-
- return new FacesMessage(severity, formattedSummary, formattedDetail);
+ return result;
}
}
Copied: trunk/core/impl/src/test/java/org/richfaces/application/MessageFactoryImplTest.java (from rev 19034, branches/RFPL-434/core/impl/src/test/java/org/richfaces/application/MessageFactoryImplTest.java)
===================================================================
--- trunk/core/impl/src/test/java/org/richfaces/application/MessageFactoryImplTest.java (rev 0)
+++ trunk/core/impl/src/test/java/org/richfaces/application/MessageFactoryImplTest.java 2010-08-31 13:13:39 UTC (rev 19039)
@@ -0,0 +1,162 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.richfaces.application;
+
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Locale;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIViewRoot;
+
+import org.jboss.test.faces.mock.MockFacesEnvironment;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.richfaces.l10n.BundleLoader;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class MessageFactoryImplTest {
+
+ private MockFacesEnvironment facesEnvironment;
+
+ private MessageFactory messageFactory;
+
+ @Before
+ public void setUp() throws Exception {
+ Locale.setDefault(Locale.US);
+
+ facesEnvironment = MockFacesEnvironment.createEnvironment().withApplication();
+
+ messageFactory = new MessageFactoryImpl(new BundleLoader());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ facesEnvironment.verify();
+ facesEnvironment.release();
+ facesEnvironment = null;
+
+ messageFactory = null;
+ }
+
+ @Test
+ public void testCreateMessageFromFacesBundle() throws Exception {
+ expect(facesEnvironment.getFacesContext().getViewRoot()).andStubReturn(null);
+ expect(facesEnvironment.getApplication().getMessageBundle()).andStubReturn(null);
+ facesEnvironment.replay();
+
+ // {1}: Could not convert ''{0}'' to a string.
+ FacesMessage stringConverterMessage = messageFactory.createMessage(facesEnvironment.getFacesContext(),
+ FacesMessages.CONVERTER_STRING, "something", "Message");
+
+ assertNotNull(stringConverterMessage);
+ assertEquals(FacesMessage.SEVERITY_INFO, stringConverterMessage.getSeverity());
+ assertEquals("Message: Could not convert 'something' to a string.", stringConverterMessage.getSummary());
+ assertEquals(stringConverterMessage.getSummary(), stringConverterMessage.getDetail());
+
+ // javax.faces.converter.EnumConverter.ENUM={2}: ''{0}'' must be convertible to an enum.
+ // javax.faces.converter.EnumConverter.ENUM_detail={2}: ''{0}'' must be convertible to an enum from the enum that contains the constant ''{1}''.
+ FacesMessage longConverterMessage = messageFactory.createMessage(facesEnvironment.getFacesContext(),
+ FacesMessage.SEVERITY_ERROR, FacesMessages.ENUM_CONVERTER_ENUM, "field", "anotherField", "Failed");
+ assertNotNull(longConverterMessage);
+ assertEquals(FacesMessage.SEVERITY_ERROR, longConverterMessage.getSeverity());
+ assertEquals("Failed: 'field' must be convertible to an enum.", longConverterMessage.getSummary());
+ assertEquals(
+ "Failed: 'field' must be convertible to an enum from the enum that contains the constant 'anotherField'.",
+ longConverterMessage.getDetail());
+ }
+
+ @Test
+ public void testGetMessageTextFromFacesBundle() throws Exception {
+ expect(facesEnvironment.getFacesContext().getViewRoot()).andStubReturn(null);
+ expect(facesEnvironment.getApplication().getMessageBundle()).andStubReturn(null);
+ facesEnvironment.replay();
+
+ // {1}: Could not convert ''{0}'' to a string.
+ String message = messageFactory.getMessageText(facesEnvironment.getFacesContext(),
+ FacesMessages.CONVERTER_STRING, "something", "Message");
+
+ assertEquals("Message: Could not convert 'something' to a string.", message);
+ }
+
+ @Test
+ public void testCreateMessageFromApplicationBundle() throws Exception {
+ UIViewRoot mockViewRoot = facesEnvironment.createMock(UIViewRoot.class);
+ expect(mockViewRoot.getLocale()).andStubReturn(new Locale("ru", "RU"));
+ expect(facesEnvironment.getFacesContext().getViewRoot()).andStubReturn(mockViewRoot);
+ expect(facesEnvironment.getApplication().getMessageBundle()).andStubReturn("org.richfaces.application.MessageFactoryImplTest");
+ facesEnvironment.replay();
+
+ // {1}: ''{0}'' ne konvertiruyetsia v stroku.
+ FacesMessage stringConverterMessage = messageFactory.createMessage(facesEnvironment.getFacesContext(),
+ FacesMessages.CONVERTER_STRING, "something", "Message");
+
+ assertNotNull(stringConverterMessage);
+ assertEquals(FacesMessage.SEVERITY_INFO, stringConverterMessage.getSeverity());
+ assertEquals("Message: 'something' ne konvertiruyetsia v stroku.", stringConverterMessage.getSummary());
+ assertEquals(stringConverterMessage.getSummary(), stringConverterMessage.getDetail());
+
+ // javax.faces.converter.EnumConverter.ENUM={2}: ''{0}'' dolzhno konvertirovat''sia v enum.
+ // javax.faces.converter.EnumConverter.ENUM_detail={2}: ''{0}'' dolzhno konvertirovat''sia v enum iz enum s konstantoj ''{1}''.
+ FacesMessage longConverterMessage = messageFactory.createMessage(facesEnvironment.getFacesContext(),
+ FacesMessage.SEVERITY_ERROR, FacesMessages.ENUM_CONVERTER_ENUM, "field", "anotherField", "Failed");
+ assertNotNull(longConverterMessage);
+ assertEquals(FacesMessage.SEVERITY_ERROR, longConverterMessage.getSeverity());
+ assertEquals("Failed: 'field' dolzhno konvertirovat'sia v enum.", longConverterMessage.getSummary());
+ assertEquals(
+ "Failed: 'field' dolzhno konvertirovat'sia v enum iz enum s konstantoj 'anotherField'.",
+ longConverterMessage.getDetail());
+
+ // javax.faces.component.UIInput.CONVERSION={0}: Conversion error occurred.
+ FacesMessage inputConversionMessage = messageFactory.createMessage(facesEnvironment.getFacesContext(),
+ FacesMessages.UIINPUT_CONVERSION, "Failure message");
+ assertNotNull(inputConversionMessage);
+ assertEquals(FacesMessage.SEVERITY_INFO, inputConversionMessage.getSeverity());
+ assertEquals("Failure message: Conversion error occurred.", inputConversionMessage.getSummary());
+ }
+
+ @Test
+ public void testGetMessageTextFromApplicationBundle() throws Exception {
+ UIViewRoot mockViewRoot = facesEnvironment.createMock(UIViewRoot.class);
+ expect(mockViewRoot.getLocale()).andStubReturn(new Locale("ru", "RU"));
+ expect(facesEnvironment.getFacesContext().getViewRoot()).andStubReturn(mockViewRoot);
+ expect(facesEnvironment.getApplication().getMessageBundle()).andStubReturn("org.richfaces.application.MessageFactoryImplTest");
+ facesEnvironment.replay();
+
+ // {1}: ''{0}'' ne konvertiruyetsia v stroku.
+ String message = messageFactory.getMessageText(facesEnvironment.getFacesContext(),
+ FacesMessages.CONVERTER_STRING, "something", "Message");
+
+ assertEquals("Message: 'something' ne konvertiruyetsia v stroku.", message);
+
+ // javax.faces.component.UIInput.CONVERSION={0}: Conversion error occurred.
+ String otherMessage = messageFactory.getMessageText(facesEnvironment.getFacesContext(),
+ FacesMessages.UIINPUT_CONVERSION, "Failure message");
+ assertEquals("Failure message: Conversion error occurred.", otherMessage);
+ }
+}
Deleted: trunk/core/impl/src/test/java/org/richfaces/application/MessageFactoryImpltest.java
===================================================================
--- trunk/core/impl/src/test/java/org/richfaces/application/MessageFactoryImpltest.java 2010-08-31 12:41:57 UTC (rev 19038)
+++ trunk/core/impl/src/test/java/org/richfaces/application/MessageFactoryImpltest.java 2010-08-31 13:13:39 UTC (rev 19039)
@@ -1,129 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.richfaces.application;
-
-import static org.easymock.EasyMock.expect;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Locale;
-
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIViewRoot;
-
-import org.jboss.test.faces.mock.MockFacesEnvironment;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.richfaces.l10n.BundleLoader;
-
-/**
- * @author Nick Belaevski
- *
- */
-public class MessageFactoryImpltest {
-
- private MockFacesEnvironment facesEnvironment;
-
- private MessageFactory messageFactory;
-
- @Before
- public void setUp() throws Exception {
- Locale.setDefault(Locale.US);
-
- facesEnvironment = MockFacesEnvironment.createEnvironment().withApplication();
-
- messageFactory = new MessageFactoryImpl(new BundleLoader());
- }
-
- @After
- public void tearDown() throws Exception {
- facesEnvironment.verify();
- facesEnvironment.release();
- facesEnvironment = null;
-
- messageFactory = null;
- }
-
- @Test
- public void testCreateMessageFromFacesBundle() throws Exception {
- expect(facesEnvironment.getFacesContext().getViewRoot()).andStubReturn(null);
- expect(facesEnvironment.getApplication().getMessageBundle()).andStubReturn(null);
- facesEnvironment.replay();
-
- // {1}: Could not convert ''{0}'' to a string.
- FacesMessage stringConverterMessage = messageFactory.createMessage(facesEnvironment.getFacesContext(),
- FacesMessages.CONVERTER_STRING, "something", "Message");
-
- assertNotNull(stringConverterMessage);
- assertEquals(FacesMessage.SEVERITY_INFO, stringConverterMessage.getSeverity());
- assertEquals("Message: Could not convert 'something' to a string.", stringConverterMessage.getSummary());
- assertEquals(stringConverterMessage.getSummary(), stringConverterMessage.getDetail());
-
- // javax.faces.converter.EnumConverter.ENUM={2}: ''{0}'' must be convertible to an enum.
- // javax.faces.converter.EnumConverter.ENUM_detail={2}: ''{0}'' must be convertible to an enum from the enum that contains the constant ''{1}''.
- FacesMessage longConverterMessage = messageFactory.createMessage(facesEnvironment.getFacesContext(),
- FacesMessage.SEVERITY_ERROR, FacesMessages.ENUM_CONVERTER_ENUM, "field", "anotherField", "Failed");
- assertNotNull(longConverterMessage);
- assertEquals(FacesMessage.SEVERITY_ERROR, longConverterMessage.getSeverity());
- assertEquals("Failed: 'field' must be convertible to an enum.", longConverterMessage.getSummary());
- assertEquals(
- "Failed: 'field' must be convertible to an enum from the enum that contains the constant 'anotherField'.",
- longConverterMessage.getDetail());
- }
-
- @Test
- public void testCreateMessageFromApplicationBundle() throws Exception {
- UIViewRoot mockViewRoot = facesEnvironment.createMock(UIViewRoot.class);
- expect(mockViewRoot.getLocale()).andStubReturn(new Locale("ru", "RU"));
- expect(facesEnvironment.getFacesContext().getViewRoot()).andStubReturn(mockViewRoot);
- expect(facesEnvironment.getApplication().getMessageBundle()).andStubReturn("org.richfaces.application.MessageFactoryImplTest");
- facesEnvironment.replay();
-
- // {1}: ''{0}'' ne konvertiruyetsia v stroku.
- FacesMessage stringConverterMessage = messageFactory.createMessage(facesEnvironment.getFacesContext(),
- FacesMessages.CONVERTER_STRING, "something", "Message");
-
- assertNotNull(stringConverterMessage);
- assertEquals(FacesMessage.SEVERITY_INFO, stringConverterMessage.getSeverity());
- assertEquals("Message: 'something' ne konvertiruyetsia v stroku.", stringConverterMessage.getSummary());
- assertEquals(stringConverterMessage.getSummary(), stringConverterMessage.getDetail());
-
- // javax.faces.converter.EnumConverter.ENUM={2}: ''{0}'' dolzhno konvertirovat''sia v enum.
- // javax.faces.converter.EnumConverter.ENUM_detail={2}: ''{0}'' dolzhno konvertirovat''sia v enum iz enum s konstantoj ''{1}''.
- FacesMessage longConverterMessage = messageFactory.createMessage(facesEnvironment.getFacesContext(),
- FacesMessage.SEVERITY_ERROR, FacesMessages.ENUM_CONVERTER_ENUM, "field", "anotherField", "Failed");
- assertNotNull(longConverterMessage);
- assertEquals(FacesMessage.SEVERITY_ERROR, longConverterMessage.getSeverity());
- assertEquals("Failed: 'field' dolzhno konvertirovat'sia v enum.", longConverterMessage.getSummary());
- assertEquals(
- "Failed: 'field' dolzhno konvertirovat'sia v enum iz enum s konstantoj 'anotherField'.",
- longConverterMessage.getDetail());
-
- // javax.faces.component.UIInput.CONVERSION={0}: Conversion error occurred.
- FacesMessage inputConversionMessage = messageFactory.createMessage(facesEnvironment.getFacesContext(),
- FacesMessages.UIINPUT_CONVERSION, "Failure message");
- assertNotNull(inputConversionMessage);
- assertEquals(FacesMessage.SEVERITY_INFO, inputConversionMessage.getSeverity());
- assertEquals("Failure message: Conversion error occurred.", inputConversionMessage.getSummary());
- }
-}
14 years, 3 months
JBoss Rich Faces SVN: r19038 - branches.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-08-31 08:41:57 -0400 (Tue, 31 Aug 2010)
New Revision: 19038
Added:
branches/RF-7560/
Log:
Created branch for RF-7560
Copied: branches/RF-7560 (from rev 19037, trunk)
14 years, 3 months
JBoss Rich Faces SVN: r19037 - in trunk/ui/input/ui/src/main: resources/META-INF/resources/org.richfaces and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: abelevich
Date: 2010-08-31 08:35:45 -0400 (Tue, 31 Aug 2010)
New Revision: 19037
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java
trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js
trunk/ui/input/ui/src/main/templates/inplaceInput.template.xml
Log:
add defaultLabel func
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java 2010-08-31 12:14:40 UTC (rev 19036)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/InplaceInputBaseRenderer.java 2010-08-31 12:35:45 UTC (rev 19037)
@@ -35,7 +35,6 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.javascript.JSFunction;
-import org.ajax4jsf.renderkit.RendererBase;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.richfaces.component.AbstractInplaceInput;
import org.richfaces.component.InplaceState;
@@ -51,7 +50,7 @@
@ResourceDependency(name = "richfaces-base-component.js"),
@ResourceDependency(library="org.richfaces", name = "inplaceInput.js"),
@ResourceDependency(library="org.richfaces", name = "inplaceInput.ecss") })
-public class InplaceInputBaseRenderer extends RendererBase {
+public class InplaceInputBaseRenderer extends InputRendererBase {
public static final String OPTIONS_EDIT_EVENT = "editEvent";
@@ -61,12 +60,14 @@
public static final String OPTIONS_FOCUS = "focusElement";
- public static final String OPTIONS_BTN_OK = "okbtn";
+ public static final String OPTIONS_BUTTON_OK = "okbtn";
public static final String OPTIONS_LABEL = "label";
- public static final String OPTIONS_BTN_CANCEL = "cancelbtn";
+ public static final String OPTIONS_DEFAULT_LABEL = "defaultLabel";
+ public static final String OPTIONS_BUTTON_CANCEL = "cancelbtn";
+
public static final String OPTIONS_SHOWCONTROLS = "showControls";
public static final String OPTIONS_NONE_CSS = "noneCss";
@@ -115,17 +116,6 @@
setComponentAttributeName("onselect")
));
-
- @Override
- protected void doDecode(FacesContext facesContext, UIComponent component) {
- AbstractInplaceInput inplaceInput = (AbstractInplaceInput)component;
- Map <String, String> parameterMap = facesContext.getExternalContext().getRequestParameterMap();
- String newValue = (String)parameterMap.get(inplaceInput.getClientId(facesContext));
- if (newValue != null) {
- inplaceInput.setSubmittedValue(newValue);
- }
- }
-
protected void renderInputHandlers(FacesContext facesContext, UIComponent component) throws IOException {
RenderKitUtils.renderPassThroughAttributesOptimized(facesContext, component, INPLACEINPUT_HANDLER_ATTRIBUTES);
}
@@ -134,12 +124,15 @@
return ((AbstractInplaceInput) component).getState();
}
- public String getValue(FacesContext context, UIComponent component) throws IOException {
- // TODO: convert?
- String value = (String) ((AbstractInplaceInput) component).getValue();
+ public String getValue(FacesContext facesContext, UIComponent component) throws IOException {
+ AbstractInplaceInput inplaceInput = (AbstractInplaceInput)component;
+ String value = getInputValue(facesContext, inplaceInput);
+ if(value == null || "".equals(value)) {
+ value = inplaceInput.getDefaultLabel();
+ }
return value;
}
-
+
public String getResourcePath(FacesContext context, String resourceName) {
if (resourceName != null) {
ResourceHandler resourceHandler = context.getApplication().getResourceHandler();
@@ -188,12 +181,13 @@
options.put(OPTIONS_INPUT, clientId + ":input");
options.put(OPTIONS_LABEL, clientId + ":label");
options.put(OPTIONS_FOCUS, clientId + ":focus");
+ options.put(OPTIONS_DEFAULT_LABEL, inplaceInput.getDefaultLabel());
boolean showControls = inplaceInput.isShowControls();
options.put(OPTIONS_SHOWCONTROLS, showControls);
if(showControls) {
- options.put(OPTIONS_BTN_OK, clientId + ":okbtn");
- options.put(OPTIONS_BTN_CANCEL, clientId + ":cancelbtn");
+ options.put(OPTIONS_BUTTON_OK, clientId + ":okbtn");
+ options.put(OPTIONS_BUTTON_CANCEL, clientId + ":cancelbtn");
}
function.addParameter(options);
Modified: trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js
===================================================================
--- trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js 2010-08-31 12:14:40 UTC (rev 19036)
+++ trunk/ui/input/ui/src/main/resources/META-INF/resources/org.richfaces/inplaceInput.js 2010-08-31 12:35:45 UTC (rev 19037)
@@ -28,21 +28,26 @@
$super.constructor.call(this, id);
this.attachToDom(id);
- this.namespace = this.namespace || "."+rf.Event.createNamespace(this.name, this.id);
+ this.namespace = this.namespace || "." + rf.Event.createNamespace(this.name, this.id);
this.currentState = options.state;
this.editEvent = options.editEvent;
this.noneCss = options.noneCss;
this.changedCss = options.changedCss;
this.showControls = options.showControls;
+ this.defaultLabel = options.defaultLabel;
this.element = $(document.getElementById(id));
this.editContainer = $(document.getElementById(options.editContainer));
this.input = $(document.getElementById(options.input));
this.label = $(document.getElementById(options.label));
this.focusElement = $(document.getElementById(options.focusElement));
- this.initialValue = this.label.text();
+ var label = this.label.text();
+ var inputLabel = this.input.val();
+
+ this.initialValue = (label == inputLabel) ? label : "";
+
this.element.bind(this.editEvent, $.proxy(this.__editHandler, this));
this.input.bind("focus", $.proxy(this.__editHandler, this));
this.input.bind("change", $.proxy(this.__changeHandler, this));
@@ -66,7 +71,8 @@
$.extend(rf.ui.InplaceInput.prototype, ( function () {
var isSaved = false;
-
+ var isValueChanged = false;
+
return {
name : "inplaceInput",
@@ -86,6 +92,10 @@
var inputValue = this.input.val();
if(inputValue.length > 0) {
this.label.text(inputValue);
+ isValueChanged = true;
+ } else {
+ this.label.text(this.defaultLabel);
+ isValueChanged = false;
}
if(inputValue != this.initialValue) {
@@ -98,7 +108,10 @@
},
cancel: function() {
- var text = this.label.text();
+ var text = "";
+ if(isValueChanged) {
+ text = this.label.text();
+ }
this.input.val(text);
isSaved = true;
this.__hide();
Modified: trunk/ui/input/ui/src/main/templates/inplaceInput.template.xml
===================================================================
--- trunk/ui/input/ui/src/main/templates/inplaceInput.template.xml 2010-08-31 12:14:40 UTC (rev 19036)
+++ trunk/ui/input/ui/src/main/templates/inplaceInput.template.xml 2010-08-31 12:35:45 UTC (rev 19037)
@@ -26,7 +26,7 @@
<input id="#{clientId}:focus" type="image" style="position: absolute; top: 0px; left: 0px; outline-style: none;" class="rf-ii-none"/>
<span id="#{clientId}:edit" class="#{getEditStyleClass(component, inplaceState)}">
<input id="#{clientId}:input" autocomplete="off" name="#{clientId}:input"
- type="text" value="#{inplaceValue}" class="rf-ii-f" style="width: #{component.attributes['inputWidth']};"
+ type="text" value="#{getInputValue(facesContext, component)}" class="rf-ii-f" style="width: #{component.attributes['inputWidth']};"
cdk:passThrough="tabIndex">
<cdk:call expression="renderInputHandlers(facesContext, component);"/>
</input>
14 years, 3 months
JBoss Rich Faces SVN: r19036 - branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2010-08-31 08:14:40 -0400 (Tue, 31 Aug 2010)
New Revision: 19036
Modified:
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteEncodeStrategy.java
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java
Log:
Modified: branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java
===================================================================
--- branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java 2010-08-31 12:12:43 UTC (rev 19035)
+++ branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java 2010-08-31 12:14:40 UTC (rev 19036)
@@ -29,7 +29,6 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.AbstractAutocomplete;
public class AutocompleteDivLayoutStrategy extends AbstractAutocompleteLayoutStrategy implements
AutocompleteEncodeStrategy {
@@ -46,41 +45,21 @@
ResponseWriter responseWriter = facesContext.getResponseWriter();
responseWriter.startElement(HTML.DIV_ELEM, component);
responseWriter.writeAttribute(HTML.ID_ATTRIBUTE, getContainerElementId(facesContext, component), null);
- // responseWriter.writeAttribute(HTML.CLASS_ATTRIBUTE, "cb_list_ul", null);
}
public void encodeItemsContainerEnd(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
responseWriter.endElement(HTML.DIV_ELEM);
}
-
- public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox, Object item) throws IOException {
+
+ public void encodeItemBegin(FacesContext facesContext, UIComponent component) throws IOException {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ writer.startElement(HTML.DIV_ELEM, component);
+ }
+
+ public void encodeItemEnd(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.DIV_ELEM, comboBox);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-au-option rf-au-font rf-au-input", null);
-
- if (comboBox.getChildCount() > 0) {
- for (UIComponent child : comboBox.getChildren()) {
- child.encodeAll(facesContext);
- }
- } else {
- if (item != null) {
- // TODO nick - use converter
- String value = null;
- if (comboBox.getItemConverter() != null) {
- value = comboBox.getItemConverter().getAsString(facesContext, comboBox, item);
- }
- if (value != null) {
- writer.writeText(value, null);
- }
- writer.writeText(item, null);
- // writer.writeText(InputUtils.getConvertedValue(facesContext, comboBox, item), null);
- }
- }
-
writer.endElement(HTML.DIV_ELEM);
-
}
}
Modified: branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteEncodeStrategy.java
===================================================================
--- branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteEncodeStrategy.java 2010-08-31 12:12:43 UTC (rev 19035)
+++ branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteEncodeStrategy.java 2010-08-31 12:14:40 UTC (rev 19036)
@@ -5,18 +5,18 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
-import org.richfaces.component.AbstractAutocomplete;
public interface AutocompleteEncodeStrategy {
void encodeItemsContainerBegin(FacesContext facesContext, UIComponent component) throws IOException ;
void encodeItemsContainerEnd(FacesContext facesContext, UIComponent component) throws IOException ;
+
+ void encodeItemBegin(FacesContext facesContext, UIComponent component) throws IOException ;
+
+ void encodeItemEnd(FacesContext facesContext, UIComponent component) throws IOException ;
void encodeFakeItem(FacesContext facesContext, UIComponent component) throws IOException ;
- void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox,
- Object nextItem) throws IOException;
-
- public String getContainerElementId(FacesContext facesContext, UIComponent component);
+ String getContainerElementId(FacesContext facesContext, UIComponent component);
}
Modified: branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java
===================================================================
--- branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java 2010-08-31 12:12:43 UTC (rev 19035)
+++ branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java 2010-08-31 12:14:40 UTC (rev 19036)
@@ -7,7 +7,6 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.AbstractAutocomplete;
public class AutocompleteListLayoutStrategy extends AbstractAutocompleteLayoutStrategy implements
AutocompleteEncodeStrategy {
@@ -31,33 +30,15 @@
ResponseWriter responseWriter = facesContext.getResponseWriter();
responseWriter.endElement(HTML.UL_ELEMENT);
}
-
- public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox, Object item) throws IOException {
+
+ public void encodeItemBegin(FacesContext facesContext, UIComponent component) throws IOException {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ writer.startElement(HTML.LI_ELEMENT, component);
+ }
+
+ public void encodeItemEnd(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.LI_ELEMENT, comboBox);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-au-option rf-au-font rf-au-input", null);
-
- if (comboBox.getChildCount() > 0) {
- for (UIComponent child : comboBox.getChildren()) {
- child.encodeAll(facesContext);
- }
- } else {
- if (item != null) {
- // TODO nick - use converter
- String value = null;
- if (comboBox.getItemConverter() != null) {
- value = comboBox.getItemConverter().getAsString(facesContext, comboBox, item);
- }
- if (value != null) {
- writer.writeText(value, null);
- }
- writer.writeText(item, null);
- }
- }
-
writer.endElement(HTML.LI_ELEMENT);
-
}
}
Modified: branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
===================================================================
--- branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2010-08-31 12:12:43 UTC (rev 19035)
+++ branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2010-08-31 12:14:40 UTC (rev 19036)
@@ -37,6 +37,7 @@
import javax.faces.context.FacesContext;
import javax.faces.context.PartialResponseWriter;
import javax.faces.context.PartialViewContext;
+import javax.faces.context.ResponseWriter;
import javax.faces.model.ArrayDataModel;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
@@ -47,6 +48,7 @@
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.RendererUtils;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.ajax4jsf.util.InputUtils;
import org.richfaces.component.AbstractAutocomplete;
import org.richfaces.component.AutocompleteLayout;
@@ -88,10 +90,12 @@
utils.addToScriptHash(options, "onerror", attributes.get("onerror"));
utils.addToScriptHash(options, "onbeforedomupdate", attributes.get("onbeforedomupdate"));
utils.addToScriptHash(options, "onchange", attributes.get("onchange"));
- if (attributes.get("mode").equals("ajax")){
- utils.addToScriptHash(options, "isCachedAjax", false, "true");
- } else if (attributes.get("mode").equals("client")) {
- utils.addToScriptHash(options, "ajaxMode", false, "true");
+ if (attributes.get("mode") != null) {
+ if (attributes.get("mode").equals("ajax")){
+ utils.addToScriptHash(options, "isCachedAjax", false, "true");
+ } else if (attributes.get("mode").equals("client")) {
+ utils.addToScriptHash(options, "ajaxMode", false, "true");
+ }
}
StringBuilder builder = new StringBuilder();
builder.append(ScriptUtils.toScript(options));
@@ -185,12 +189,17 @@
Object nextItem = items.next();
setVar(facesContext, comboBox.getVar(), nextItem);
- strategy.encodeItem(facesContext, comboBox, nextItem);
+ this.encodeItem(facesContext, comboBox, nextItem, strategy);
if (comboBox.getFetchValue() != null) {
fetchValues.add(comboBox.getFetchValue());
} else {
// TODO use converter
- fetchValues.add(nextItem);
+ if (comboBox.getItemConverter() != null) {
+ fetchValues.add(comboBox.getItemConverter().getAsString(facesContext, component, nextItem));
+ } else{
+ fetchValues.add(nextItem);
+ }
+
}
}
@@ -205,25 +214,52 @@
protected void encodeItemsContainer(FacesContext facesContext, UIComponent component) throws IOException {
AutocompleteEncodeStrategy strategy = getStrategy(component);
- strategy.encodeItemsContainerBegin(facesContext, component);
- if (component.getAttributes().get("mode").equals("client")) {
+ Object mode = component.getAttributes().get("mode");
+ if (mode!= null && mode.equals("client")) {
List<Object> fetchValues = new ArrayList<Object>();
this.encodeItems(facesContext, component, fetchValues);
- } else {
+ } else if (mode!= null && mode.equals("lazyClient")){
+ strategy.encodeItemsContainerBegin(facesContext, component);
+ strategy.encodeItemsContainerEnd(facesContext, component);
+ } else{
+ strategy.encodeItemsContainerBegin(facesContext, component);
strategy.encodeFakeItem(facesContext, component);
+ strategy.encodeItemsContainerEnd(facesContext, component);
}
- strategy.encodeItemsContainerEnd(facesContext, component);
}
+ public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox, Object item, AutocompleteEncodeStrategy strategy) throws IOException {
+ strategy.encodeItemBegin(facesContext, comboBox);
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-au-option rf-au-font rf-au-input", null);
+
+ if (comboBox.getChildCount() > 0) {
+ for (UIComponent child : comboBox.getChildren()) {
+ child.encodeAll(facesContext);
+ }
+ } else {
+ if (item != null) {
+ // TODO nick - use converter
+ String value = null;
+ if (comboBox.getItemConverter() != null) {
+ value = comboBox.getItemConverter().getAsString(facesContext, comboBox, item);
+ }
+ if (value != null) {
+ writer.writeText(value, null);
+ }
+ writer.writeText(item, null);
+ }
+ }
+
+ }
+
private AutocompleteEncodeStrategy getStrategy(UIComponent component) {
AbstractAutocomplete comboBox = (AbstractAutocomplete) component;
if (comboBox.getLayout() != null) {
if (comboBox.getLayout().equals(AutocompleteLayout.div.toString())) {
return new AutocompleteDivLayoutStrategy();
}
- if (comboBox.getLayout().equals(AutocompleteLayout.grid.toString())) {
- return new AutocompleteGridLayoutStrategy();
- }
if (comboBox.getLayout().equals(AutocompleteLayout.list.toString())) {
return new AutocompleteListLayoutStrategy();
}
Modified: branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java
===================================================================
--- branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java 2010-08-31 12:12:43 UTC (rev 19035)
+++ branches/autocomplete/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java 2010-08-31 12:14:40 UTC (rev 19036)
@@ -7,16 +7,17 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.AbstractAutocomplete;
public class AutocompleteTableLayoutStrategy extends AbstractAutocompleteLayoutStrategy implements
AutocompleteEncodeStrategy {
public void encodeFakeItem(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
+ responseWriter.startElement(HTML.TR_ELEMENT, component);
responseWriter.startElement(HTML.TD_ELEM, component);
responseWriter.writeAttribute(HTML.STYLE_ATTRIBUTE, "display:none", null);
responseWriter.endElement(HTML.TD_ELEM);
+ responseWriter.endElement(HTML.TR_ELEMENT);
}
@@ -25,42 +26,24 @@
responseWriter.startElement(HTML.TABLE_ELEMENT, component);
responseWriter.writeAttribute(HTML.ID_ATTRIBUTE, getContainerElementId(facesContext, component), null);
responseWriter.startElement(HTML.TBODY_ELEMENT, component);
- // responseWriter.writeAttribute(HTML.CLASS_ATTRIBUTE, "cb_list_ul", null);
}
public void encodeItemsContainerEnd(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
- responseWriter.endElement(HTML.TABLE_ELEMENT);
responseWriter.endElement(HTML.TBODY_ELEMENT);
+ responseWriter.endElement(HTML.TABLE_ELEMENT);
}
-
- public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox, Object item) throws IOException {
+
+ public void encodeItemBegin(FacesContext facesContext, UIComponent component) throws IOException {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ writer.startElement(HTML.TR_ELEMENT, component);
+ writer.startElement(HTML.TD_ELEM, component);
+ }
+
+ public void encodeItemEnd(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.TD_ELEM, comboBox);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-au-option rf-au-font rf-au-input", null);
-
- if (comboBox.getChildCount() > 0) {
- for (UIComponent child : comboBox.getChildren()) {
- child.encodeAll(facesContext);
- }
- } else {
- if (item != null) {
- // TODO nick - use converter
- String value = null;
- if (comboBox.getItemConverter() != null) {
- value = comboBox.getItemConverter().getAsString(facesContext, comboBox, item);
- }
- if (value != null) {
- writer.writeText(value, null);
- }
- writer.writeText(item, null);
- // writer.writeText(InputUtils.getConvertedValue(facesContext, comboBox, item), null);
- }
- }
-
writer.endElement(HTML.TD_ELEM);
-
+ writer.endElement(HTML.TR_ELEMENT);
}
}
14 years, 3 months
JBoss Rich Faces SVN: r19035 - trunk/ui/input/ui/src/main/java/org/richfaces/renderkit.
by richfaces-svn-commits@lists.jboss.org
Author: amarkhel
Date: 2010-08-31 08:12:43 -0400 (Tue, 31 Aug 2010)
New Revision: 19035
Removed:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteGridLayoutStrategy.java
Modified:
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteEncodeStrategy.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java
Log:
Fix Null pointer in autocomplete
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java 2010-08-31 12:12:12 UTC (rev 19034)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteDivLayoutStrategy.java 2010-08-31 12:12:43 UTC (rev 19035)
@@ -29,7 +29,6 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.AbstractAutocomplete;
public class AutocompleteDivLayoutStrategy extends AbstractAutocompleteLayoutStrategy implements
AutocompleteEncodeStrategy {
@@ -46,41 +45,21 @@
ResponseWriter responseWriter = facesContext.getResponseWriter();
responseWriter.startElement(HTML.DIV_ELEM, component);
responseWriter.writeAttribute(HTML.ID_ATTRIBUTE, getContainerElementId(facesContext, component), null);
- // responseWriter.writeAttribute(HTML.CLASS_ATTRIBUTE, "cb_list_ul", null);
}
public void encodeItemsContainerEnd(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
responseWriter.endElement(HTML.DIV_ELEM);
}
-
- public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox, Object item) throws IOException {
+
+ public void encodeItemBegin(FacesContext facesContext, UIComponent component) throws IOException {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ writer.startElement(HTML.DIV_ELEM, component);
+ }
+
+ public void encodeItemEnd(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.DIV_ELEM, comboBox);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-au-option rf-au-font rf-au-input", null);
-
- if (comboBox.getChildCount() > 0) {
- for (UIComponent child : comboBox.getChildren()) {
- child.encodeAll(facesContext);
- }
- } else {
- if (item != null) {
- // TODO nick - use converter
- String value = null;
- if (comboBox.getItemConverter() != null) {
- value = comboBox.getItemConverter().getAsString(facesContext, comboBox, item);
- }
- if (value != null) {
- writer.writeText(value, null);
- }
- writer.writeText(item, null);
- // writer.writeText(InputUtils.getConvertedValue(facesContext, comboBox, item), null);
- }
- }
-
writer.endElement(HTML.DIV_ELEM);
-
}
}
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteEncodeStrategy.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteEncodeStrategy.java 2010-08-31 12:12:12 UTC (rev 19034)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteEncodeStrategy.java 2010-08-31 12:12:43 UTC (rev 19035)
@@ -5,18 +5,18 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
-import org.richfaces.component.AbstractAutocomplete;
public interface AutocompleteEncodeStrategy {
void encodeItemsContainerBegin(FacesContext facesContext, UIComponent component) throws IOException ;
void encodeItemsContainerEnd(FacesContext facesContext, UIComponent component) throws IOException ;
+
+ void encodeItemBegin(FacesContext facesContext, UIComponent component) throws IOException ;
+
+ void encodeItemEnd(FacesContext facesContext, UIComponent component) throws IOException ;
void encodeFakeItem(FacesContext facesContext, UIComponent component) throws IOException ;
- void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox,
- Object nextItem) throws IOException;
-
- public String getContainerElementId(FacesContext facesContext, UIComponent component);
+ String getContainerElementId(FacesContext facesContext, UIComponent component);
}
Deleted: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteGridLayoutStrategy.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteGridLayoutStrategy.java 2010-08-31 12:12:12 UTC (rev 19034)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteGridLayoutStrategy.java 2010-08-31 12:12:43 UTC (rev 19035)
@@ -1,34 +0,0 @@
-package org.richfaces.renderkit;
-
-import java.io.IOException;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-import org.richfaces.component.AbstractAutocomplete;
-
-public class AutocompleteGridLayoutStrategy extends AbstractAutocompleteLayoutStrategy implements
- AutocompleteEncodeStrategy {
-
- public void encodeFakeItem(FacesContext facesContext, UIComponent component) throws IOException {
- // TODO Auto-generated method stub
-
- }
-
- public void encodeItemsContainerBegin(FacesContext facesContext, UIComponent component) throws IOException {
- // TODO Auto-generated method stub
-
- }
-
- public void encodeItemsContainerEnd(FacesContext facesContext, UIComponent component) throws IOException {
- // TODO Auto-generated method stub
-
- }
-
- public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox, Object nextItem)
- throws IOException {
- // TODO Auto-generated method stub
-
- }
-
-}
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java 2010-08-31 12:12:12 UTC (rev 19034)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteListLayoutStrategy.java 2010-08-31 12:12:43 UTC (rev 19035)
@@ -7,7 +7,6 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.AbstractAutocomplete;
public class AutocompleteListLayoutStrategy extends AbstractAutocompleteLayoutStrategy implements
AutocompleteEncodeStrategy {
@@ -31,33 +30,15 @@
ResponseWriter responseWriter = facesContext.getResponseWriter();
responseWriter.endElement(HTML.UL_ELEMENT);
}
-
- public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox, Object item) throws IOException {
+
+ public void encodeItemBegin(FacesContext facesContext, UIComponent component) throws IOException {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ writer.startElement(HTML.LI_ELEMENT, component);
+ }
+
+ public void encodeItemEnd(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.LI_ELEMENT, comboBox);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-au-option rf-au-font rf-au-input", null);
-
- if (comboBox.getChildCount() > 0) {
- for (UIComponent child : comboBox.getChildren()) {
- child.encodeAll(facesContext);
- }
- } else {
- if (item != null) {
- // TODO nick - use converter
- String value = null;
- if (comboBox.getItemConverter() != null) {
- value = comboBox.getItemConverter().getAsString(facesContext, comboBox, item);
- }
- if (value != null) {
- writer.writeText(value, null);
- }
- writer.writeText(item, null);
- }
- }
-
writer.endElement(HTML.LI_ELEMENT);
-
}
}
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2010-08-31 12:12:12 UTC (rev 19034)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteRendererBase.java 2010-08-31 12:12:43 UTC (rev 19035)
@@ -37,6 +37,7 @@
import javax.faces.context.FacesContext;
import javax.faces.context.PartialResponseWriter;
import javax.faces.context.PartialViewContext;
+import javax.faces.context.ResponseWriter;
import javax.faces.model.ArrayDataModel;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
@@ -47,6 +48,7 @@
import org.ajax4jsf.context.AjaxContext;
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.RendererUtils;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.ajax4jsf.util.InputUtils;
import org.richfaces.component.AbstractAutocomplete;
import org.richfaces.component.AutocompleteLayout;
@@ -88,10 +90,12 @@
utils.addToScriptHash(options, "onerror", attributes.get("onerror"));
utils.addToScriptHash(options, "onbeforedomupdate", attributes.get("onbeforedomupdate"));
utils.addToScriptHash(options, "onchange", attributes.get("onchange"));
- if (attributes.get("mode").equals("ajax")){
- utils.addToScriptHash(options, "isCachedAjax", false, "true");
- } else if (attributes.get("mode").equals("client")) {
- utils.addToScriptHash(options, "ajaxMode", false, "true");
+ if (attributes.get("mode") != null) {
+ if (attributes.get("mode").equals("ajax")){
+ utils.addToScriptHash(options, "isCachedAjax", false, "true");
+ } else if (attributes.get("mode").equals("client")) {
+ utils.addToScriptHash(options, "ajaxMode", false, "true");
+ }
}
StringBuilder builder = new StringBuilder();
builder.append(ScriptUtils.toScript(options));
@@ -185,12 +189,17 @@
Object nextItem = items.next();
setVar(facesContext, comboBox.getVar(), nextItem);
- strategy.encodeItem(facesContext, comboBox, nextItem);
+ this.encodeItem(facesContext, comboBox, nextItem, strategy);
if (comboBox.getFetchValue() != null) {
fetchValues.add(comboBox.getFetchValue());
} else {
// TODO use converter
- fetchValues.add(nextItem);
+ if (comboBox.getItemConverter() != null) {
+ fetchValues.add(comboBox.getItemConverter().getAsString(facesContext, component, nextItem));
+ } else{
+ fetchValues.add(nextItem);
+ }
+
}
}
@@ -205,25 +214,52 @@
protected void encodeItemsContainer(FacesContext facesContext, UIComponent component) throws IOException {
AutocompleteEncodeStrategy strategy = getStrategy(component);
- strategy.encodeItemsContainerBegin(facesContext, component);
- if (component.getAttributes().get("mode").equals("client")) {
+ Object mode = component.getAttributes().get("mode");
+ if (mode!= null && mode.equals("client")) {
List<Object> fetchValues = new ArrayList<Object>();
this.encodeItems(facesContext, component, fetchValues);
- } else {
+ } else if (mode!= null && mode.equals("lazyClient")){
+ strategy.encodeItemsContainerBegin(facesContext, component);
+ strategy.encodeItemsContainerEnd(facesContext, component);
+ } else{
+ strategy.encodeItemsContainerBegin(facesContext, component);
strategy.encodeFakeItem(facesContext, component);
+ strategy.encodeItemsContainerEnd(facesContext, component);
}
- strategy.encodeItemsContainerEnd(facesContext, component);
}
+ public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox, Object item, AutocompleteEncodeStrategy strategy) throws IOException {
+ strategy.encodeItemBegin(facesContext, comboBox);
+ ResponseWriter writer = facesContext.getResponseWriter();
+
+ writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-au-option rf-au-font rf-au-input", null);
+
+ if (comboBox.getChildCount() > 0) {
+ for (UIComponent child : comboBox.getChildren()) {
+ child.encodeAll(facesContext);
+ }
+ } else {
+ if (item != null) {
+ // TODO nick - use converter
+ String value = null;
+ if (comboBox.getItemConverter() != null) {
+ value = comboBox.getItemConverter().getAsString(facesContext, comboBox, item);
+ }
+ if (value != null) {
+ writer.writeText(value, null);
+ }
+ writer.writeText(item, null);
+ }
+ }
+
+ }
+
private AutocompleteEncodeStrategy getStrategy(UIComponent component) {
AbstractAutocomplete comboBox = (AbstractAutocomplete) component;
if (comboBox.getLayout() != null) {
if (comboBox.getLayout().equals(AutocompleteLayout.div.toString())) {
return new AutocompleteDivLayoutStrategy();
}
- if (comboBox.getLayout().equals(AutocompleteLayout.grid.toString())) {
- return new AutocompleteGridLayoutStrategy();
- }
if (comboBox.getLayout().equals(AutocompleteLayout.list.toString())) {
return new AutocompleteListLayoutStrategy();
}
Modified: trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java
===================================================================
--- trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java 2010-08-31 12:12:12 UTC (rev 19034)
+++ trunk/ui/input/ui/src/main/java/org/richfaces/renderkit/AutocompleteTableLayoutStrategy.java 2010-08-31 12:12:43 UTC (rev 19035)
@@ -7,16 +7,17 @@
import javax.faces.context.ResponseWriter;
import org.ajax4jsf.renderkit.RendererUtils.HTML;
-import org.richfaces.component.AbstractAutocomplete;
public class AutocompleteTableLayoutStrategy extends AbstractAutocompleteLayoutStrategy implements
AutocompleteEncodeStrategy {
public void encodeFakeItem(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
+ responseWriter.startElement(HTML.TR_ELEMENT, component);
responseWriter.startElement(HTML.TD_ELEM, component);
responseWriter.writeAttribute(HTML.STYLE_ATTRIBUTE, "display:none", null);
responseWriter.endElement(HTML.TD_ELEM);
+ responseWriter.endElement(HTML.TR_ELEMENT);
}
@@ -25,42 +26,24 @@
responseWriter.startElement(HTML.TABLE_ELEMENT, component);
responseWriter.writeAttribute(HTML.ID_ATTRIBUTE, getContainerElementId(facesContext, component), null);
responseWriter.startElement(HTML.TBODY_ELEMENT, component);
- // responseWriter.writeAttribute(HTML.CLASS_ATTRIBUTE, "cb_list_ul", null);
}
public void encodeItemsContainerEnd(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
- responseWriter.endElement(HTML.TABLE_ELEMENT);
responseWriter.endElement(HTML.TBODY_ELEMENT);
+ responseWriter.endElement(HTML.TABLE_ELEMENT);
}
-
- public void encodeItem(FacesContext facesContext, AbstractAutocomplete comboBox, Object item) throws IOException {
+
+ public void encodeItemBegin(FacesContext facesContext, UIComponent component) throws IOException {
+ ResponseWriter writer = facesContext.getResponseWriter();
+ writer.startElement(HTML.TR_ELEMENT, component);
+ writer.startElement(HTML.TD_ELEM, component);
+ }
+
+ public void encodeItemEnd(FacesContext facesContext, UIComponent component) throws IOException {
ResponseWriter writer = facesContext.getResponseWriter();
-
- writer.startElement(HTML.TD_ELEM, comboBox);
- writer.writeAttribute(HTML.CLASS_ATTRIBUTE, "rf-au-option rf-au-font rf-au-input", null);
-
- if (comboBox.getChildCount() > 0) {
- for (UIComponent child : comboBox.getChildren()) {
- child.encodeAll(facesContext);
- }
- } else {
- if (item != null) {
- // TODO nick - use converter
- String value = null;
- if (comboBox.getItemConverter() != null) {
- value = comboBox.getItemConverter().getAsString(facesContext, comboBox, item);
- }
- if (value != null) {
- writer.writeText(value, null);
- }
- writer.writeText(item, null);
- // writer.writeText(InputUtils.getConvertedValue(facesContext, comboBox, item), null);
- }
- }
-
writer.endElement(HTML.TD_ELEM);
-
+ writer.endElement(HTML.TR_ELEMENT);
}
}
14 years, 3 months
JBoss Rich Faces SVN: r19034 - in branches/RFPL-434/core: impl/src/main/java/org/richfaces/application and 1 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2010-08-31 08:12:12 -0400 (Tue, 31 Aug 2010)
New Revision: 19034
Modified:
branches/RFPL-434/core/api/src/main/java/org/richfaces/application/MessageFactory.java
branches/RFPL-434/core/impl/src/main/java/org/richfaces/application/MessageFactoryImpl.java
branches/RFPL-434/core/impl/src/test/java/org/richfaces/application/MessageFactoryImplTest.java
Log:
Added getMessageText method to MessageFactory
Modified: branches/RFPL-434/core/api/src/main/java/org/richfaces/application/MessageFactory.java
===================================================================
--- branches/RFPL-434/core/api/src/main/java/org/richfaces/application/MessageFactory.java 2010-08-31 11:26:53 UTC (rev 19033)
+++ branches/RFPL-434/core/api/src/main/java/org/richfaces/application/MessageFactory.java 2010-08-31 12:12:12 UTC (rev 19034)
@@ -35,4 +35,6 @@
public FacesMessage createMessage(FacesContext facesContext, Severity severity, Enum<?> messageKey, Object... args);
+ public String getMessageText(FacesContext facesContext, Enum<?> messageKey, Object... args);
+
}
Modified: branches/RFPL-434/core/impl/src/main/java/org/richfaces/application/MessageFactoryImpl.java
===================================================================
--- branches/RFPL-434/core/impl/src/main/java/org/richfaces/application/MessageFactoryImpl.java 2010-08-31 11:26:53 UTC (rev 19033)
+++ branches/RFPL-434/core/impl/src/main/java/org/richfaces/application/MessageFactoryImpl.java 2010-08-31 12:12:12 UTC (rev 19034)
@@ -40,6 +40,53 @@
*/
public class MessageFactoryImpl implements MessageFactory {
+ protected static interface Factory<T> {
+
+ public T create(ResourceBundle bundle, Enum<?> messageKey, Object... args) throws MissingResourceException;
+
+ }
+
+ private static final Factory<FacesMessage> MESSAGE_FACTORY = new Factory<FacesMessage>() {
+
+ public FacesMessage create(ResourceBundle bundle, Enum<?> messageKey, Object... args)
+ throws MissingResourceException {
+
+ String messageId = messageKey.toString();
+
+ String summary = null;
+ String detail = null;
+
+ try {
+ summary = bundle.getString(messageId);
+ detail = bundle.getString(messageId + "_detail");
+ } catch (MissingResourceException e) {
+ // do nothing
+ }
+
+ if (summary != null) {
+ String formattedSummary = MessageFormat.format(summary, args);
+ String formattedDetail = null;
+
+ if (detail != null) {
+ formattedDetail = MessageFormat.format(detail, args);
+ }
+
+ return new FacesMessage(formattedSummary, formattedDetail);
+ }
+
+ return null;
+ }
+ };
+
+ private static final Factory<String> LABEL_FACTORY = new Factory<String>() {
+
+ public String create(ResourceBundle bundle, Enum<?> messageKey, Object... args) throws MissingResourceException {
+ String pattern = bundle.getString(messageKey.toString());
+ return MessageFormat.format(pattern, args);
+ }
+
+ };
+
private BundleLoader bundleLoader;
public MessageFactoryImpl(BundleLoader bundleLoader) {
@@ -73,26 +120,46 @@
throw new NullPointerException("messageKey");
}
- FacesMessage result = null;
+ FacesMessage result = detectLocalesAndCreate(facesContext, MESSAGE_FACTORY, messageKey, args);
- Locale locale = detectLocale(facesContext);
+ if (result != null) {
+ result.setSeverity(severity);
+ }
+
+ return result;
+ }
+
+ public String getMessageText(FacesContext facesContext, Enum<?> messageKey, Object... args) {
+ String text = detectLocalesAndCreate(facesContext, LABEL_FACTORY, messageKey, args);
+ if (text == null) {
+ text = "???" + messageKey + "???";
+ }
+
+ return text;
+ }
+
+ protected <T> T detectLocalesAndCreate(FacesContext context, Factory<T> factory, Enum<?> messageKey, Object... args) {
+
+ T result = null;
+
+ Locale locale = detectLocale(context);
if (locale != null) {
- result = createMessage(facesContext, severity, locale, messageKey, args);
+ result = create(context, factory, locale, messageKey, args);
}
if (result == null) {
Locale defaultLocale = Locale.getDefault();
if (!defaultLocale.equals(locale)) {
- result = createMessage(facesContext, severity, defaultLocale, messageKey, args);
+ result = create(context, factory, defaultLocale, messageKey, args);
}
}
-
+
return result;
}
-
- protected FacesMessage createMessage(FacesContext context, Severity severity, Locale locale, Enum<?> messageKey,
+
+ protected <T> T create(FacesContext context, Factory<T> factory, Locale locale, Enum<?> messageKey,
Object... args) {
MessageBundle messageBundle = messageKey.getClass().getAnnotation(MessageBundle.class);
@@ -101,41 +168,25 @@
return null;
}
- String messageId = messageKey.toString();
+ T result = null;
- String summary = null;
- String detail = null;
-
try {
ResourceBundle bundle = bundleLoader.getApplicationBundle(context, messageKey, locale);
- summary = bundle.getString(messageId);
- detail = bundle.getString(messageId + "_detail");
+ result = factory.create(bundle, messageKey, args);
} catch (MissingResourceException e) {
// do nothing
}
- if (summary == null) {
+ if (result == null) {
try {
ResourceBundle bundle = bundleLoader.getBundle(messageKey, locale);
- summary = bundle.getString(messageId);
- detail = bundle.getString(messageId + "_detail");
+ result = factory.create(bundle, messageKey, args);
} catch (MissingResourceException e) {
// do nothing
}
}
- if (summary == null) {
- return null;
- }
-
- String formattedSummary = MessageFormat.format(summary, args);
- String formattedDetail = null;
-
- if (detail != null) {
- formattedDetail = MessageFormat.format(detail, args);
- }
-
- return new FacesMessage(severity, formattedSummary, formattedDetail);
+ return result;
}
}
Modified: branches/RFPL-434/core/impl/src/test/java/org/richfaces/application/MessageFactoryImplTest.java
===================================================================
--- branches/RFPL-434/core/impl/src/test/java/org/richfaces/application/MessageFactoryImplTest.java 2010-08-31 11:26:53 UTC (rev 19033)
+++ branches/RFPL-434/core/impl/src/test/java/org/richfaces/application/MessageFactoryImplTest.java 2010-08-31 12:12:12 UTC (rev 19034)
@@ -92,6 +92,19 @@
}
@Test
+ public void testGetMessageTextFromFacesBundle() throws Exception {
+ expect(facesEnvironment.getFacesContext().getViewRoot()).andStubReturn(null);
+ expect(facesEnvironment.getApplication().getMessageBundle()).andStubReturn(null);
+ facesEnvironment.replay();
+
+ // {1}: Could not convert ''{0}'' to a string.
+ String message = messageFactory.getMessageText(facesEnvironment.getFacesContext(),
+ FacesMessages.CONVERTER_STRING, "something", "Message");
+
+ assertEquals("Message: Could not convert 'something' to a string.", message);
+ }
+
+ @Test
public void testCreateMessageFromApplicationBundle() throws Exception {
UIViewRoot mockViewRoot = facesEnvironment.createMock(UIViewRoot.class);
expect(mockViewRoot.getLocale()).andStubReturn(new Locale("ru", "RU"));
@@ -126,4 +139,24 @@
assertEquals(FacesMessage.SEVERITY_INFO, inputConversionMessage.getSeverity());
assertEquals("Failure message: Conversion error occurred.", inputConversionMessage.getSummary());
}
+
+ @Test
+ public void testGetMessageTextFromApplicationBundle() throws Exception {
+ UIViewRoot mockViewRoot = facesEnvironment.createMock(UIViewRoot.class);
+ expect(mockViewRoot.getLocale()).andStubReturn(new Locale("ru", "RU"));
+ expect(facesEnvironment.getFacesContext().getViewRoot()).andStubReturn(mockViewRoot);
+ expect(facesEnvironment.getApplication().getMessageBundle()).andStubReturn("org.richfaces.application.MessageFactoryImplTest");
+ facesEnvironment.replay();
+
+ // {1}: ''{0}'' ne konvertiruyetsia v stroku.
+ String message = messageFactory.getMessageText(facesEnvironment.getFacesContext(),
+ FacesMessages.CONVERTER_STRING, "something", "Message");
+
+ assertEquals("Message: 'something' ne konvertiruyetsia v stroku.", message);
+
+ // javax.faces.component.UIInput.CONVERSION={0}: Conversion error occurred.
+ String otherMessage = messageFactory.getMessageText(facesEnvironment.getFacesContext(),
+ FacesMessages.UIINPUT_CONVERSION, "Failure message");
+ assertEquals("Failure message: Conversion error occurred.", otherMessage);
+ }
}
14 years, 3 months