如果你从自动完成框中“删除”(事件“itemunselect”)最后一项,那么p:autocomplete的多重选择= true会发生什么。 数组是设置为null还是仅为空?
XML:
<p:autoComplete id="mulitAutoTags"
value="#{entityHandler.entity.tags}"
completeMethod="#{entityListHandler.completeAreaWithCreation}"
var="_tag"
itemLabel="#{_tag.value}"
itemValue="#{_tag}"
multiple="true"
size="300"
converter="#{entityConverter}">
<p:ajax event="itemUnselect" listener="#{entityHandler.startSearch()}" update=":tags" />
</p:autoComplete>
ListHandler:
public List<Tag> completeAreaWithCreation(String query) {
List<Tag> returnList = this.entityManager.createNamedQuery(Tag.NAMED_QUERY_GET_TAGS_BY_LIKE, Tag.class).setParameter("tag", query.toLowerCase().trim() + "%").getResultList();
if(returnList.size() == 0){
if(query.endsWith(" ")){
entityHandler.create();
entityHandler.getEntity().value(query.trim());
entityHandler.save();
}
returnList = completeAreaWithCreation(query.trim());
}
return returnList;
}
这是(部分)我的实体:
@Table(name = "WF_TICKET")
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class WorkflowTicket extends Workflow{
....
private List<Tag> tags = new ArrayList<Tag>(0);
....
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name="WF_TICKET_TAG_L", joinColumns = {@JoinColumn(name = "ID_TICKET", nullable = false, updatable = false)} ,inverseJoinColumns = { @JoinColumn(name ="ID_TAG", nullable = false, updatable = false) })
public List<Tag> getTags() {
return schlagworts;
}
public void setTags(List<Tag> tagss) {
this.tags = tagss;
}
....
}
现在,我点击最后一项,选中,之后我在entityHandler中得到一个nullpointerexception(this.entity.getTags()。size()),因为arrayList为null而我不知道为什么
这只是teh itemunselect事件调用的方法的一小部分:
@SuppressWarnings("null")
public void startSearch(){
....
if(this.entity.getTags().size() > 0){
.....
}
}
答案 0 :(得分:0)
我自己做了一个解决方案,但我仍然不明白为什么数组为空。
@SuppressWarnings("null")
public void startSearch(){
....
if(this.entity.getTags() == null){
this.entity.setTags(new ArrayList<Tag>(0));
}
if(this.entity.getTags().size() > 0){
.....
}
}