0

I created PickList is my website and it works but is very slow. I have about 1000 items and every time I click submit it goes into Converter and does 1000 times it. Even if nothing selected.

Maybe I can skip converter or take only target items (not found example on internet) or give back only some text (for this can be only Code) or other solusion?

I am using primefaces 3.5

My Converter:

public Object getAsObject(FacesContext context, UIComponent component, String value) {

    if(value != null){
        int iii = Integer.parseInt(value);
        Jbtit s = new Jbtit();

        s = SR.findById(iii);

        return s;
    }

    return null;
}


public String getAsString(FacesContext context, UIComponent component, Object value) {

    if(value == null){
        return "";
    }

    if (!(value instanceof Jbtit)) return null;

    Integer i = ((Jbtit) value).getId();

    if(i != null){
        String s = Integer.toString(i);
        return s;
    }
    return "";
}

XHTML:

<p:pickList id="jbtit" styleClass="jbtitPickList" 
    value="#{panelCountMB.jobTitles}" var="jb" effect="none" 
    itemValue="#{jb}" itemLabel="#{jb.code} - #{jb.description_en}"
    converter="#{jbtitConverter}"  showCheckbox="true" showSourceFilter="true"
    showTargetFilter="true" filterMatchMode="contains" >  
    <f:facet name="sourceCaption">Available</f:facet>  
    <f:facet name="targetCaption">Selected</f:facet>  
        <p:column >  
            <h:outputLabel styleClass="testingas" style="width:100%"  value="#{jb.code} - #{jb.description_en}" />
        </p:column>  
</p:pickList>
4

2 回答 2

0

似乎总是使用数据库是我的错误。

我找到了另一个解决方案。

转换器可以这样重写:

@Component(value="primefacesPicklistConverter")
public class PrimefacesPicklistConverter implements Converter {

        public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
            Object ret = null;
            if (arg1 instanceof PickList) {
                Object dualList = ((PickList) arg1).getValue();
                DualListModel<?> dl = (DualListModel<?>) dualList;
                for (Object o : dl.getSource()) {
                    String id = "";
                    if (o instanceof Jbtit) {
                        id += ((Jbtit) o).getId();
                    }
                    if (arg2.equals(id)) {
                        ret = o;
                        break;
                    }
                }
                if (ret == null)
                    for (Object o : dl.getTarget()) {
                            String id = "";
                            if (o instanceof Jbtit) {
                                id += ((Jbtit) o).getId();
                            }
                        if (arg2.equals(id)) {
                            ret = o;
                            break;
                        }
                    }
            }
            return ret;
        }

        public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
            String str = "";
            if (arg2 instanceof Jbtit) {
                str = "" + ((Jbtit) arg2).getId();
            }
            return str;
        }

}

于 2013-10-18T07:12:26.560 回答
0

由于对 1000 个项目中的每一个都执行了“findById”,因此它似乎很慢。对于这种情况,可能使用数据库缓存或实施自定义缓存解决方案。

于 2013-10-17T12:20:51.697 回答