Hi Keith,
i try your workaround for 2.0.3 but my converter was not called. Modified your configuration by changing the id of expressionparser as following:
Code:
<webflow:flow-builder-services id="flowBuilderServices" conversion-service="conversionService" expression-parser="expressionParser" .../>
<bean id="expressionParser" class="org.springframework.webflow.expression.el.WebFlowELExpressionParser">
<constructor-arg>
<bean class="org.jboss.el.ExpressionFactoryImpl"/>
</constructor-arg>
<property name="conversionService" ref="conversionService"/>
</bean>
I have downloaded the last nigthly build and my converter was not called too.
Whats wrong?
See my own Thread please:
http://forum.springframework.org/showthread.php?t=59007
I believe the converters are a very nice feature and the community will use it. Please check the following code and give me a suggestion:
Environment: SWF 2.0.4.CI-573 with facelets
webflow-config.xml
Code:
<!-- Configures the Spring Web Flow JSF integration -->
<faces:flow-builder-services id="facesFlowBuilderServices"
conversion-service="conversionService"/>
<bean id="conversionService" class="de.myApp.web.springframework.MyConversationService" />
conversationService:
Add my own converter and the shortDate from examples to test it too.
Code:
package de.myApp.web.springframework;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.binding.convert.converters.StringToDate;
import org.springframework.binding.convert.service.DefaultConversionService;
import de.myApp.web.springframework.converter.StringToUnterkunftTyp;
public class MyConversationService extends DefaultConversionService {
private final static Log LOGGER = LogFactory
.getLog(MyConversationService.class);
public MyConversationService() {
super();
}
protected void addDefaultConverters() {
super.addDefaultConverters();
addConverter("unterkunftTyp",new StringToUnterkunftTyp());
// try the demo Converter from examples.
addConverter("shortDate", new StringToDate());
}
}
my Flow
Code:
<view-state id="add" model="backingBean">
<binder>
<binding property="unterkunftTyp" converter="unterkunftTyp" />
<binding property="jetzt" converter="shortDate" />
</binder>
<transition on="save" to="commitAndEnd">
<evaluate expression="backingBean.save(flowRequestContext)" />
</transition>
<transition on="chooseregion" to="regionchooser">
</transition>
<transition on="reload" to="fewoadd">
</transition>
</view-state>
backingBean:
Code:
// with getter and setter
private UnterkunftTyp unterkunftTyp;
private Date jetzt = new Date();
my own converter:
Code:
package de.myApp.web.springframework.converter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.binding.convert.converters.InvalidFormatException;
import org.springframework.binding.convert.converters.StringToObject;
import org.springframework.util.StringUtils;
import de.myApp.bean.UnterkunftTyp;
import de.myApp.bean.impl.UnterkunftTypImpl;
import de.myApp.service.UnterkunftTypService;
public class StringToUnterkunftTyp extends StringToObject {
@Autowired
private transient UnterkunftTypService unterkunftTypService;
public StringToUnterkunftTyp() {
super(UnterkunftTypImpl.class);
}
/* (non-Javadoc)
* @see org.springframework.binding.convert.converters.StringToObject#toObject(java.lang.String, java.lang.Class)
*/
@Override
public Object toObject(String string, Class targetClass) throws Exception {
if (!StringUtils.hasText(string)) {
return null;
}
try {
return unterkunftTypService.getUnterkunftTypById(new Integer(string));
} catch (Exception e) {
throw new InvalidFormatException(string, "unterkunftTyp", e);
}
}
public String toString(Object target) throws Exception {
UnterkunftTyp unterkunftTyp = (UnterkunftTyp) target;
if (unterkunftTyp == null) {
return "";
}
return unterkunftTyp.getOid().toString();
}
/**
* @param unterkunftTypService the unterkunftTypService to set
*/
public void setUnterkunftTypService(UnterkunftTypService unterkunftTypService) {
this.unterkunftTypService = unterkunftTypService;
}
}
my facelet
No converter was called and i saw the jetzt.toString() and unterkunftTyp.toString() implementation.
Code:
<td><h:inputText id="jetzt" value="#{feWoController.jetzt}"/><br/>
<h:inputText id="unterunftTyp" value="#{feWoController.unterkunftTyp}"/><br/>
Thanks,
alex