【问题标题】:p:autocomplete array null after last itemunselectp:autocomplete array null after last itemunselect
【发布时间】:2014-01-27 16:42:19
【问题描述】:

如果您从自动完成框中“删除”(事件“itemunselect”)最后一项,则 p:autocomplete 的有界数组会发生什么情况,其中 multi-selection = 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>

列表处理程序:

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,我不知道为什么.

这只是 itemunselect 事件调用的方法的一小部分:

@SuppressWarnings("null")
    public void startSearch(){

    ....

            if(this.entity.getTags().size() > 0){

                .....

                }
    }

【问题讨论】:

  • SLtrike 先生,您的 xhtml 和托管 bean 代码在哪里?
  • 它来了,但不知道这应该有什么帮助,这是一个普遍的问题,背景中的数组发生了什么。问候

标签: arrays primefaces autocomplete


【解决方案1】:

自己做了一个解决方案,但我还是不明白为什么数组为空。

@SuppressWarnings("null")
public void startSearch(){

....

    if(this.entity.getTags() == null){
       this.entity.setTags(new ArrayList<Tag>(0));
    }
        if(this.entity.getTags().size() > 0){

            .....

            }
}

【讨论】:

    猜你喜欢
    • 2022-12-17
    • 2011-07-23
    • 1970-01-01
    • 2011-01-22
    • 2013-09-12
    • 2019-01-03
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多