Java Primefaces选择列表转换器

Java Primefaces选择列表转换器,java,primefaces,converter,picklist,Java,Primefaces,Converter,Picklist,我使用的是PrimeFaces4.0和JSF2.2。我使用了一个带转换器的选择列表。问题是我没有在转换器中获得正确的arg2。它总是说0。我的期望是,这是元素的id,我可以从源/目标列表中解析它。有什么想法吗 我的转换器的灵感来自 我的选择列表声明如下: <p:pickList value="#{loadingPlaceGroups.pickList}" style="margin:0" var="loadingPlace" converter="primeFacesPic

我使用的是PrimeFaces4.0和JSF2.2。我使用了一个带转换器的选择列表。问题是我没有在转换器中获得正确的
arg2
。它总是说
0
。我的期望是,这是元素的id,我可以从源/目标列表中解析它。有什么想法吗

我的
转换器的灵感来自

我的选择列表声明如下:

<p:pickList value="#{loadingPlaceGroups.pickList}"
    style="margin:0" var="loadingPlace"
    converter="primeFacesPickListConverter"
    itemValue="#{loadingPlace}"
    itemLabel="#{loadingPlace.name}#{loadingPlace.location.address.street}#{loadingPlace.location.address.houseNr}#{loadingPlace.location.address.zipCode}#{loadingPlace.location.address.city}"
    showSourceFilter="true" showTargetFilter="true"
    filterMatchMode="contains"
    styleClass="picklist500x350source picklist500x350target">

    <f:facet name="sourceCaption">Alle Ladestellen</f:facet>
    <f:facet name="targetCaption">Gewählte Ladestellen</f:facet>
    <p:column style="border-bottom:1px solid lightgray">
        <p:panelGrid>
            <p:row>
                <p:column style="padding-left:0;font-size:12pt">
                    <h:outputLabel value="#{loadingPlace.name}"
                        style="font-weight:bold" />
                </p:column>
            </p:row>
            <p:row>
                <p:column style="padding:0">
                    <h:outputLabel
                        value="#{loadingPlace.location.address.street} #{loadingPlace.location.address.houseNr}" />
                </p:column>
            </p:row>
            <p:row>
                <p:column style="padding:0">
                    <h:outputLabel
                        value="#{loadingPlace.location.address.zipCode} #{loadingPlace.location.address.city}" />
                </p:column>
            </p:row>
        </p:panelGrid>
    </p:column>
</p:pickList>

阿勒·拉德斯特伦
Gewählte Ladestellen

对于选取列表,请使用此
通用转换器

import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.WeakHashMap;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter(value = "entityConverter")
public class EntityConverter implements Converter {

    private static Map<Object, String> entities = new WeakHashMap<Object, String>();

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object entity) {
        synchronized (entities) {
            if (!entities.containsKey(entity)) {
                String uuid = UUID.randomUUID().toString();
                entities.put(entity, uuid);
                return uuid;
            } else {
                return entities.get(entity);
            }
        }
    }

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String uuid) {
        for (Entry<Object, String> entry : entities.entrySet()) {
            if (entry.getValue().equals(uuid)) {
                return entry.getKey();
            }
        }
        return null;
    }

}
import java.util.Map;
导入java.util.Map.Entry;
导入java.util.UUID;
导入java.util.WeakHashMap;
导入javax.faces.component.UIComponent;
导入javax.faces.context.FacesContext;
导入javax.faces.convert.Converter;
导入javax.faces.convert.FacesConverter;
@FacesConverter(value=“entityConverter”)
公共类EntityConverter实现转换器{
私有静态映射实体=new WeakHashMap();
@凌驾
公共字符串getAsString(FacesContext上下文、UIComponent组件、对象实体){
已同步(实体){
如果(!entities.containsKey(实体)){
字符串uuid=uuid.randomUUID().toString();
实体。put(实体,uuid);
返回uuid;
}否则{
返回实体。获取(实体);
}
}
}
@凌驾
公共对象getAsObject(FacesContext上下文、UIComponent组件、字符串uuid){
for(条目:entities.entrySet()){
if(entry.getValue().equals(uuid)){
return entry.getKey();
}
}
返回null;
}
}