在Ajax传输侦听器上,Primefaces PickList目标为空

时间:2013-02-03 15:27:24

标签: jsf jsf-2 primefaces

我有以下p:pickList

<p:pickList id="activityUser" value="#{activityEntryController.activityUserDualListModel}" var="model" itemLabel="#{model.fullName}"
    itemValue="#{model}" converter="activityUserListConverter" styleClass="activityUser" required="true" showSourceFilter="true"
    showTargetFilter="true" filterMatchMode="contains">

    <f:facet name="sourceCaption">Available</f:facet>
    <f:facet name="targetCaption">Selected</f:facet>

    <p:column style="width: 400px">
        <h:outputText value="#{model.fullName}" />
    </p:column>

    <p:ajax event="transfer" listener="#{activityEntryController.sortUsersOnTransfer}" update="activityUser" />
</p:pickList>

value的{​​{1}}是一个扩展p:pickList的类:

DualListModel<T>

我从public class ActivityUserDualListModel extends DualListModel<ActivityUserDTO> { private static final long serialVersionUID = -5369543532197736480L; public ActivityUserDualListModel() { super(); initModel(); } public ActivityUserDualListModel(List<ActivityUserDTO> source, List<ActivityUserDTO> target) { super(source, target); initModel(); } private void initModel() { IServiceProvider serviceProvider = (IServiceProvider) ContextLoader.getCurrentWebApplicationContext().getBean(Beans.SERVICE_PROVIDER.getName()); IUserService userService = serviceProvider.getUserService(); List<ActivityUserDTO> activityUserDTOs = new ArrayList<ActivityUserDTO>(); for(User user : userService.getAllUser()) { if(user.isActive()) { activityUserDTOs.add(constructActivityUserDTO(user)); } } Collections.sort(activityUserDTOs, ComparatorUtils.getActivityUserFullNameComparator()); setSource(activityUserDTOs); setTarget(new ArrayList<ActivityUserDTO>()); } private ActivityUserDTO constructActivityUserDTO(User user) { ActivityUserDTO activityUserDTO = new ActivityUserDTO(); activityUserDTO.setId(user.getId()); activityUserDTO.setUsername(user.getUsername()); activityUserDTO.setFullName(user.getFullName()); return activityUserDTO; } } 托管bean的ActivityUserDualListModel方法实例化PostConstruct

事件ActivityEntryController时发生的listener p:ajax为:

transfer

奇怪的是上面方法中的public void sortUsersOnTransfer(TransferEvent event) { List<ActivityUserDTO> source = activityUserDualListModel.getSource(); List<ActivityUserDTO> target = activityUserDualListModel.getTarget(); System.out.println("============================================="); for(ActivityUserDTO dto : source) { System.out.println(dto.getFullName()); } System.out.println("============================================="); System.out.println("============================================="); for(ActivityUserDTO dto : target) { System.out.println(dto.getFullName()); } System.out.println("============================================="); if(source != null) { Collections.sort(source, ComparatorUtils.getActivityUserFullNameComparator()); } if(target != null) { Collections.sort(target, ComparatorUtils.getActivityUserFullNameComparator()); } } 列表是空的。我无法找到我所缺少的东西。任何指针都对我很有帮助。

编辑:

以下类是转换器:

target

我还有以下@FacesConverter("activityUserListConverter") public class ActivityUserListConverter implements Converter { @Override public Object getAsObject(FacesContext context, UIComponent component, String submittedValue) { if (!(component instanceof PickList)) { return null; } if (StringUtils.isBlank(submittedValue)) { return null; } @SuppressWarnings("unchecked") DualListModel<ActivityUserDTO> pickListModel = (DualListModel<ActivityUserDTO>) ((PickList) component).getValue(); ActivityUserDTO ret = null; for (ActivityUserDTO activityUserDTO : pickListModel.getSource()) { if (activityUserDTO.getId().equals(Long.parseLong(submittedValue))) { ret = activityUserDTO; break; } } if (ret == null) { for (ActivityUserDTO activityUserDTO : pickListModel.getTarget()) { if (activityUserDTO.getId().equals(Long.parseLong(submittedValue))) { ret = activityUserDTO; break; } } } return ret; } @Override public String getAsString(FacesContext context, UIComponent component, Object value) { if (value == null || value.equals("")) { return ""; } if (value instanceof ActivityUserDTO) { return String.valueOf(((ActivityUserDTO) value).getId()); } return ""; } } 用于提交表单。现在p:commandButton没有触发,但如果我从xhtml中移除actionListener形式,它就会触发。

0 个答案:

没有答案