You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ca...@apache.org on 2007/03/14 12:46:20 UTC

svn commit: r518104 - in /myfaces/core/branches/jsf12/api/src: main/java-templates/javax/faces/component/UIInputTemplate.java test/java/javax/faces/component/UIInputTest.java

Author: cagatay
Date: Wed Mar 14 04:46:19 2007
New Revision: 518104

URL: http://svn.apache.org/viewvc?view=rev&rev=518104
Log:
Added converterMessage feature related to MYFACES-1237. See jsf 1.2 spec section 4.1.6.2
Also added tests with mocks

Added:
    myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIInputTest.java   (with props)
Modified:
    myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIInputTemplate.java

Modified: myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIInputTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIInputTemplate.java?view=diff&rev=518104&r1=518103&r2=518104
==============================================================================
--- myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIInputTemplate.java (original)
+++ myfaces/core/branches/jsf12/api/src/main/java-templates/javax/faces/component/UIInputTemplate.java Wed Mar 14 04:46:19 2007
@@ -334,16 +334,21 @@
         }
         catch (ConverterException e)
         {
-            FacesMessage facesMessage = e.getFacesMessage();
-            if (facesMessage != null)
-            {
-                context.addMessage(getClientId(context), facesMessage);
-            }
-            else
-            {
-                _MessageUtils.addErrorMessage(context, this, CONVERSION_MESSAGE_ID,new Object[]{getId()});
-            }
-            setValid(false);
+        	String converterMessage = getConverterMessage();
+        	if(converterMessage != null) {
+        		context.addMessage(getClientId(context),new FacesMessage(FacesMessage.SEVERITY_ERROR,converterMessage,converterMessage));
+        	} else {
+        		 FacesMessage facesMessage = e.getFacesMessage();
+                 if (facesMessage != null)
+                 {
+                     context.addMessage(getClientId(context), facesMessage);
+                 }
+                 else
+                 {
+                     _MessageUtils.addErrorMessage(context, this, CONVERSION_MESSAGE_ID,new Object[]{_MessageUtils.getLabel(context,this)});
+                 }
+        	}
+        	setValid(false);
         }
         return submittedValue;
     }

Added: myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIInputTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIInputTest.java?view=auto&rev=518104
==============================================================================
--- myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIInputTest.java (added)
+++ myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIInputTest.java Wed Mar 14 04:46:19 2007
@@ -0,0 +1,72 @@
+/*
+ * 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 javax.faces.component;
+
+import static org.easymock.EasyMock.*;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+
+import junit.framework.Test;
+
+import org.apache.shale.test.base.AbstractJsfTestCase;
+
+public class UIInputTest extends AbstractJsfTestCase{
+	
+	private Converter mockConverter;
+
+	public UIInputTest(String name) {
+		super(name);
+	}
+
+	protected void setUp() throws Exception {
+		super.setUp();
+		mockConverter = createMock(Converter.class);
+	}
+	
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        mockConverter = null;
+    }
+
+	public static Test suite() {
+		return null;
+	}
+	
+	public void testWhenSpecifiedConverterMessageIsUsedInCaseConverterExceptionOccurs() {
+		UIInput input = new UIInput();
+		input.setId("testId");
+		input.setConverterMessage("Cannot convert");
+		
+		input.setConverter(mockConverter);
+		expect(mockConverter.getAsObject(facesContext, input, "xxx")).andThrow(new ConverterException());
+		replay(mockConverter);
+		
+		input.getConvertedValue(facesContext, "xxx");
+		verify(mockConverter);
+		
+		assertFalse(input.isValid());
+		assertNotNull(facesContext.getMessages("testId"));
+		
+		FacesMessage message = (FacesMessage) facesContext.getMessages("testId").next();
+		assertEquals(message.getDetail(), "Cannot convert");
+		assertEquals(message.getSummary(), "Cannot convert");
+	}
+}

Propchange: myfaces/core/branches/jsf12/api/src/test/java/javax/faces/component/UIInputTest.java
------------------------------------------------------------------------------
    svn:eol-style = native