diff --git a/spring-binding/src/main/java/org/springframework/binding/format/formatters/DateFormatter.java b/spring-binding/src/main/java/org/springframework/binding/format/formatters/DateFormatter.java index 2e6d5493..ea10c30e 100644 --- a/spring-binding/src/main/java/org/springframework/binding/format/formatters/DateFormatter.java +++ b/spring-binding/src/main/java/org/springframework/binding/format/formatters/DateFormatter.java @@ -23,6 +23,7 @@ import java.util.Locale; import org.springframework.binding.format.Formatter; import org.springframework.binding.format.InvalidFormatException; +import org.springframework.util.StringUtils; public class DateFormatter implements Formatter { @@ -47,10 +48,16 @@ public class DateFormatter implements Formatter { } public String format(Object date) { + if (date == null) { + return ""; + } return getDateFormat().format((Date) date); } public Object parse(String formattedString) throws InvalidFormatException { + if (!StringUtils.hasText(formattedString)) { + return null; + } DateFormat dateFormat = getDateFormat(); try { return dateFormat.parse(formattedString); diff --git a/spring-binding/src/main/java/org/springframework/binding/format/formatters/NumberFormatter.java b/spring-binding/src/main/java/org/springframework/binding/format/formatters/NumberFormatter.java index 9f7c0504..b0f75b48 100644 --- a/spring-binding/src/main/java/org/springframework/binding/format/formatters/NumberFormatter.java +++ b/spring-binding/src/main/java/org/springframework/binding/format/formatters/NumberFormatter.java @@ -22,6 +22,7 @@ import org.springframework.binding.format.Formatter; import org.springframework.binding.format.InvalidFormatException; import org.springframework.util.Assert; import org.springframework.util.NumberUtils; +import org.springframework.util.StringUtils; public class NumberFormatter implements Formatter { @@ -39,6 +40,9 @@ public class NumberFormatter implements Formatter { } public String format(Object number) { + if (number == null) { + return ""; + } if (pattern != null) { return getNumberFormat().format(number); } else { @@ -46,11 +50,14 @@ public class NumberFormatter implements Formatter { } } - public Object parse(String text) throws InvalidFormatException { + public Object parse(String formattedString) throws InvalidFormatException { + if (!StringUtils.hasText(formattedString)) { + return null; + } if (pattern != null) { - return NumberUtils.parseNumber(text, numberClass, getNumberFormat()); + return NumberUtils.parseNumber(formattedString, numberClass, getNumberFormat()); } else { - return NumberUtils.parseNumber(text, numberClass); + return NumberUtils.parseNumber(formattedString, numberClass); } } diff --git a/spring-webflow/src/main/java/org/springframework/webflow/persistence/HibernateFlowExecutionListener.java b/spring-webflow/src/main/java/org/springframework/webflow/persistence/HibernateFlowExecutionListener.java index e28191ac..65bb01a2 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/persistence/HibernateFlowExecutionListener.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/persistence/HibernateFlowExecutionListener.java @@ -145,8 +145,10 @@ public class HibernateFlowExecutionListener extends FlowExecutionListenerAdapter } public void exceptionThrown(RequestContext context, FlowExecutionException exception) { - if (isPersistenceContext(context.getActiveFlow())) { - unbind(getHibernateSession(context)); + if (context.getFlowExecutionContext().isActive()) { + if (isPersistenceContext(context.getActiveFlow())) { + unbind(getHibernateSession(context)); + } } } diff --git a/spring-webflow/src/main/java/org/springframework/webflow/persistence/JpaFlowExecutionListener.java b/spring-webflow/src/main/java/org/springframework/webflow/persistence/JpaFlowExecutionListener.java index d387128c..280ceb32 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/persistence/JpaFlowExecutionListener.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/persistence/JpaFlowExecutionListener.java @@ -121,12 +121,7 @@ public class JpaFlowExecutionListener extends FlowExecutionListenerAdapter { // this is a commit end state - start a new transaction that quickly commits transactionTemplate.execute(new TransactionCallbackWithoutResult() { protected void doInTransactionWithoutResult(TransactionStatus status) { - // necessary for JTA to enlist the entity manager in the transaction - try { - em.joinTransaction(); - } catch (IllegalStateException e) { - // won't be necessary once Spring 2.0.7 is released - } + em.joinTransaction(); } }); } @@ -136,8 +131,10 @@ public class JpaFlowExecutionListener extends FlowExecutionListenerAdapter { } public void exceptionThrown(RequestContext context, FlowExecutionException exception) { - if (isPersistenceContext(context.getActiveFlow())) { - unbind(getEntityManager(context)); + if (context.getFlowExecutionContext().isActive()) { + if (isPersistenceContext(context.getActiveFlow())) { + unbind(getEntityManager(context)); + } } }