Target values ​​of the target list and initial values ​​do not change

My sources and the target values ​​of the pickList of my lines do not change, I followed the example in showface and also looked at some messages here, but still am not able to solve the problem. I use the list from the database to populate the source as follows:

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; } 

My converter

 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 (id != null) ? String.valueOf(id) : null; } @Override public Object getAsObject(FacesContext arg0, UIComponent arg1, String value) { Course course = new Course(); course.setId(Integer.parseInt(value)); return course; } } 

and finally my xhtml page:

 <h:form> <p:pickList id="coursesOffered" value="#{courseView.courseModel}" var="course" itemValue="#{course}" itemLabel="#{course.courseTitle}" converter="courseConverter" showSourceFilter="true" showTargetFilter="true" filterMatchMode="contains"> <f:facet name="targetCaption">Selected</f:facet> <f:facet name="sourceCaption">All Courses</f:facet> <p:ajax event="transfer" listener="#{courseView.onTransfer}" /> <p:column style="width:10%"> #{course.courseCode}: </p:column> <p:column style="width:90%"> #{course.courseTitle} </p:column> </p:pickList> <p:commandButton id="pojoSubmit" value="Submit" update="displayPlayers" oncomplete="playerDialog.show()" style="margin-top:5px" /> <p:dialog showEffect="fade" hideEffect="fade" widgetVar="playerDialog"> <h:panelGrid id="displayPlayers" columns="2"> <h:outputText value="Source: " style="font-weight:bold" /> <ui:repeat value="#{courseView.courseModel.source}" var="course"> <h:outputText value="#{course.courseTitle}" style="margin-right:5px" /> </ui:repeat> <h:outputText value="Target: " style="font-weight:bold" /> <ui:repeat value="#{courseView.courseModel.target}" var="course"> <h:outputText value="#{course.courseTitle}" style="margin-right:5px" /> </ui:repeat> </h:panelGrid> </p:dialog> </h:form> 

PickList is displayed correctly with a source filled with values ​​from the database, however, when you click a button, only the initial values ​​of the source list and the empty target list are displayed in the dialog box even after transferring the interface elements. What am I missing?

+4
source share
2 answers

I see some problems with your code. In getter, you restore DualList from the database, republishing all the changes you have made so far.

try to do something like this:

 public DualListModel<Course> getCourseModel() { return this.courseModel; } 

Create and load your list from the database in the annotated @PostConstruct method, and not in the + getter constructor.

 public CourseBean() {} @PostConstruct public void init() { List<Course> target = new ArrayList<Course>(); courseModel.setSource(getCourseList()); courseModel = new DualListModel<Course>(source, target); } 

Also comment on your bean @ViewScoped, so you do not create a new bean with an empty target list for each request

 @ManagedBean(name="courseView") @ViewScoped public class CourseBean { } 

Finally, you also need a setter:

 public void setCourseModel(DualListModel<Course> courseModel) { this.courseModel = courseModel; } 

I really didn’t look into the converter when I did the picker the last time I took the converter included in the barcode display window (I never tried anything). Here is the link to the source: http://code.google.com/p/ind/source/browse/indicadorCensoJSF/src/ve/gob/ine/censo/beans/convert/PrimeFacesPickListConverter.java?spec=svn154&r=154

+5
source

A converter is required to work with objects. This is the best answer how to implement it: fooobar.com/questions/268646 / ...

0
source

All Articles