我使用的是Primefaces 4.0和JSF 2.2.我使用了带转换器的选项列表.问题是arg2我的转换器中没有正确的.它总是说0.我的期望是这是元素的id,我可以从源/目标列表中解析它.有任何想法吗?
我Converter的灵感来自于如何为<p:pickList>编写自定义转换器.
我的领料单声明如下:
<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>
Run Code Online (Sandbox Code Playgroud) 我的primefaces pickList源和目标值不会改变,我已经在primefaces showcase中跟踪了示例, 并且在这里查看了几个帖子,但仍然无法解决问题.我正在使用数据库中的列表来填充源代码,如下所示:
private DualListModel<Course> courseModel;
public CourseBean() {
List<Course> target = new ArrayList<Course>();
List<Course> source = new ArrayList<Course>();
courseModel = new DualListModel<Course>(source, target);
}
...
//this DualListModel getter also populates the source with values from db
public DualListModel<Course> getCourseModel() {
courseModel.setSource(getCourseList());
return courseModel;
}
Run Code Online (Sandbox Code Playgroud)
我的转换器是
import org.omnifaces.converter.SelectItemsConverter;
@FacesConverter("courseConverter")
public class CourseConverter extends SelectItemsConverter {
@Override
public String getAsString(FacesContext context, UIComponent component,
Object value) {
Integer id = (value instanceof Course) ? ((Course) value).getId()
: null;
return …Run Code Online (Sandbox Code Playgroud) 您好如何使用JSF h:selectOneMenu或Primefaces 的POJO列表p:selectOneMenu?
我知道有很多相关的问题建议使用Converter但没有明确的构建从头开始的例子.
我想要一个通用的转换器代码用于上述目的.
如果重复,请建议任何替代方案/指出正确的问题.