我以前有这个工作,但后来我改变了一些东西,我不能让它再次工作。我正在尝试使用我的服务层来访问数据库并从我的转换器类中获取正确的对象,具体取决于用户单击的内容。我用弹簧将服务属性注入我的转换器。在调试期间,我可以看到该属性已正确设置。但是当我去调用 getService 时,它是空的。
@FacesConverter("PlaceConverter")
@SessionScoped 公共类 PlaceConverter 实现 Converter {
private SearchQueryService searchQueryService;
/**
* @return the searchQueryService
*/
public SearchQueryService getSearchQueryService() {
return searchQueryService;
}
/**
* @param searchQueryService the searchQueryService to set
*/
public void setSearchQueryService(SearchQueryService searchQueryService) {
this.searchQueryService = searchQueryService;
}
@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String submittedValue) {
try {
Criteria criteria = new Criteria();
criteria.setId(Integer.parseInt(submittedValue));
return getSearchQueryService().findPlaces(criteria).get(0);
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object value) {
((Place) value).setCategory(" (" + ((Place) value).getCategory() + ")");
return String.valueOf(((Place) value).getPlaceId());
}
}
<bean id="placeConverterBean" class="com.ghghg.converter.PlaceConverter">
<property name="searchQueryService" ref="searchQueryServiceBean" />
</bean>