这是我的第一篇文章。我正在尝试为我的primefaces应用程序制作一个选项列表。我可以看到源代码部分中列出的值,也可以将源值传递给屏幕中的目标面板。但是在服务器端,关键列表ForDestination (绑定到选项列表中的目标面板)仍然是空的。但是在屏幕上一切正常。当我调试我的应用程序并在ontransfer方法中创建断点并将源对象传递给目标时,我看不到事件中的值.getItems(event TransferEvent)。
我将在下面发送相关的代码部分。
感谢您的回复。
DC
我的xhtml代码段:
<p:pickList id="pojoPickList" value="#{serviceCopyInsertBean.tariffList}" var="tariff" effect="bounce"
itemValue="#{tariff}" itemLabel="#{tariff.cpcmOfferName}" converter="tmp2TariffDescMappingConverter"
showSourceControls="true" showTargetControls="true" showCheckbox="true"
showSourceFilter="true" showTargetFilter="true" filterMatchMode="contains" >
<f:facet name="sourceCaption">Available</f:facet>
<f:facet name="targetCaption">Starting</f:facet>
<p:ajax event="transfer" listener="#{serviceCopyInsertBean.onTransfer}"/>
<p:column style="width:75%;">
#{tariff.cpcmOfferName}
</p:column>
</p:pickList>
我的转换器Tmp2TariffDescMappingConverter
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
import com.i2i.st.entity.Tmp2TariffDescMapping;
@FacesConverter("tmp2TariffDescMappingConverter")
public class Tmp2TariffDescMappingConverter implements Converter {
private static List<Tmp2TariffDescMapping> tmp2TariffDescMappingDB;
static {
tmp2TariffDescMappingDB = new ArrayList<Tmp2TariffDescMapping>();
}
public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue) {
if (submittedValue.trim().equals("")) {
return null;
} else {
try {
int number = Integer.parseInt(submittedValue);
for (Tmp2TariffDescMapping tmp :tmp2TariffDescMappingDB) {
if (tmp.getCpcmOfferId() == number) {
return tmp;
}
}
} catch(NumberFormatException exception) {
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Tmp2TariffDescMapping"));
}
}
return null;
}
public String getAsString(FacesContext facesContext, UIComponent component, Object value) {
if (value == null) {
return null;
} else {
return String.valueOf(((Tmp2TariffDescMapping) value).getCpcmOfferId());
}
}
}
我的JSF bean
private DualListModel<Tmp2TariffDescMapping> tariffList=new DualListModel<Tmp2TariffDescMapping>();
private List<Tmp2TariffDescMapping> tariffListForSource=new ArrayList<Tmp2TariffDescMapping>();
private List<Tmp2TariffDescMapping> tariffListForDestination=new ArrayList<Tmp2TariffDescMapping>();
tariffList=new DualListModel<Tmp2TariffDescMapping>(tariffListForSource, tariffListForDestination);
答案 0 :(得分:0)
我不明白你为什么要在getAsObject()中迭代tmp2TariffDescMappingDB。你是怎么填写这份名单的?
您应该搜索tariffList.getTarget()和tariffList.getSource()来查看pickList的两侧。类似于这个通用的东西:
public T getAsObject(FacesContext context, UIComponent component, String value) {
...
if (component instanceof PickList) {
DualListModel<T> dl = (DualListModel) ((PickList) component).getValue();
for (T t : dl.getTarget()) {
//search here
}
for (T t : dl.getSource()) {
//maybe here too
}
...