Primefaces数据转换器带滤波

时间:2015-02-19 16:50:23

标签: jsf primefaces datatable filtering converter

我内有datatableselectonemenu 我想在选择的一个菜单项中显示图像。所以我们有一个评级等级和转换器ratingConverter用于评级等级 我在这里遇到了下一个问题:通过此列过滤仅运行一次!当我尝试从method load(..)来电更改项目LazyComicsDataModel时。但是之后 过滤一次没什么用!方法加载不再调用。 server.log中没有任何例外情况。当我不使用转换器和类评级(仅使用String类)时,它可以正常工作。 我想知道为什么会发生这种情况 代码:
xhtml页面的一部分:
    

            <p:ajax 
                event="rowSelect" 

                update=":form:comicsDetail" 
                oncomplete="PF('comicsDialog').show()"/>

                <p:column width="20%" 
                      headerText="#{comicsCatalogueView.columnComicsRating}" 
                      sortBy="#{comics.rating}" 
                      filterBy="#{comics.rating}" 
                      filterMatchMode="exact" >
                <f:facet name="filter" >
                    <p:selectOneMenu

                        value="#{comicsCatalogueView.rating}"
                        var="r"
                        onchange="PF('comicsTable').filter()"
                        converter="ratingConverter"
                        >

                        <f:selectItem 
                            value="#{null}"
                            itemValue="#{null}" /> 
                        <f:selectItems 
                            value="#{comicsFinderManagedBean.ratings}"
                            var="rating"
                            itemLabel="#{rating.value} - #{rating.value+1}"
                            itemValue="#{rating}" 

                                       />   

                        <p:column>
                            <p:graphicImage value="#{r.image}"/>
                        </p:column>

                    </p:selectOneMenu>
                </f:facet>

            <h:panelGroup>
                <pf:rating  disabled="true"
                            totalStars="5"
                            step="0.1"
                            value="#{comics.rating}"
                            >
                </pf:rating>
            </h:panelGroup>

            </p:column>

评级:

public class Rating {

public Rating(Integer value, String image) {
    this.value = value;
    this.image = image;
}

private Integer value;
private String image;

public Integer getValue() {
    return value;
}

public void setValue(Integer value) {
    this.value = value;
}

public String getImage() {
    return image;
}

public void setImage(String image) {
    this.image = image;
}

@Override
public int hashCode() {
    int hash = 5;
    hash = 71 * hash + (this.value != null ? this.value.hashCode() : 0);
    hash = 71 * hash + (this.image != null ? this.image.hashCode() : 0);
    return hash;
}

@Override
public boolean equals(Object obj) {
    if (obj == null) {
        return false;
    }
    if (getClass() != obj.getClass()) {
        return false;
    }
    final Rating other = (Rating) obj;
    if (this.value != other.value && (this.value == null || !this.value.equals(other.value))) {
        return false;
    }
    if ((this.image == null) ? (other.image != null) : !this.image.equals(other.image)) {
        return false;
    }
    return true;
}

@Override
public String toString() {
    return "Rating{" + "value=" + value + ", image=" + image + '}';
}

评级转换器:

@FacesConverter("ratingConverter")  
public class RatingConverter implements Converter {

@Override
public Object getAsObject(FacesContext fc, UIComponent uic, String value) {
    if(value != null && value.trim().length() > 0) {

            ComicsFinderManagedBean ratingFinderManagedBean = (ComicsFinderManagedBean) 
                    fc.getExternalContext().getApplicationMap().get("comicsFinderManagedBean");
            return ratingFinderManagedBean.getRating(Integer.parseInt(value));

    }
    else {
        return null;
    }
}

@Override
public String getAsString(FacesContext fc, UIComponent uic, Object object) {
    if(object != null) {
        return String.valueOf(((Rating) object).getValue());

    }
    else {
        return null;
    }
}  

}

0 个答案:

没有答案