使用:春季3.2門戶與Liferay的5.2.3和Tomcat 6.0.18屬性編輯器問題與設置型
我試圖創建一個屬性編輯器來Set<Type>
和String
,並再次之間進行轉換MVC。我已成功將Set<Type>
改爲String
,以便毫無問題地工作。但是我不能讓財產編輯人員在相反的方向上得到認可。我已經成功地完成這件事與Type
- >String
- >Type
,但這樣做轉換爲Set
是躲避我。
我已經確定SetAsText方法不會被調用,我也得到一個運行時錯誤表明這些轉換卻沒有這樣做。關於財產編輯的信息非常稀少,除了一兩個例外,我能找到的僅有的模糊相關問題已經有4年或更長時間了。
要麼我失去了這麼根本的是我看不到它,或者它是在框架中更深層次的東西,但我會任何幫助或建議表示感謝。
下面是從我控制器@InitBinder片段:
@InitBinder("formBacking")
public void initBinder(WebDataBinder binder){
binder.registerCustomEditor(Set.class, "field", new SetEditor(listService, Set.class));
logger.info("FormBacking Binder initialization");
}
這裏是我的屬性編輯:
public class SetEditor extends PropertyEditorSupport {
protected static Logger logger = Logger.getLogger("PropertyEditor");
private ListService listService;
public SetEditor(ListService listService, Class clazz) {
super(clazz);
this.listService = listService;
}
@Override
public String getAsText() {
Stack<String> returnString = new Stack<String>();
Set<Type> types = new HashSet<Type>();
try {
types = (Set<Type>)this.getValue();
for (Type type:types) {
returnString.push(type.getTypeId().toString());
}
} catch (NullPointerException e) {
logger.info("getAsText is \"\"");
return "";
} catch (Exception e) {
logger.info("getAsText Other Exception: " + e.getMessage());
return "";
}
return "[" + StringUtils.collectionToDelimitedString(returnString,",") + "]"; // a very useful Spring Util
}
@Override
public void setAsText(String text) throws IllegalArgumentException {
Type type = new Type();
Set<Type> result = new HashSet<Type>();
try {
String[] typeArray = text.split("[,]"); //this may not be correct, but I can't get here to debug it!!
for(String type:typeArray) {
if(!type.isEmpty()) {
type = listService.getType(Long.valueOf(text));
result.add(type);
}
}
}catch(NullPointerException e) {
logger.info("SetAsText is \"\" ");
setValue(null);
}
catch(Exception e) {
logger.info("setAsText Other Exception: " + e.getMessage());
}
setValue(result);
}
}
Type類片段是:
@Entity(name="Type")
@Table(name="type")
public class Type {
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "playListImages",
joinColumns={@JoinColumn(name="superTypeId")},
inverseJoinColumns={@JoinColumn(name="typeId")})
private Set<Type> types = new HashSet<Type>();
getters and setters...