I'm trying to make a palette using list of bean. And I can't find solution
how to do this. Especially with the encoder thing.
can anyone help me? sorry for posting this long source code, just to make
sure what is wrong with my code.
Error:
Render queue error in SetupRender[palette/UsingBean:palette]:
org.makeasoup.tapestryboard.beans.Student cannot be cast to java.util.List

*PaletteUsingBean.tml

*<div>
          <form t:type="form">
             <span t:type="palette" encoder="studentEncoder"
model="studentModel" selected="selectedStudentList"/>
             <input type="submit" value="Submit"/>
          </form>
</div>

*PaletteUsingBean.java*

public class PaletteUsingBean {
    @Persist(PersistenceConstants.FLASH)
    @Property
    private Student student;

    @Property
    @Persist(PersistenceConstants.FLASH)
    private List<Student> selectedStudentList;

    private List<Student> studentList;

    public List<Student> getStudentList() {
        if(studentList==null){
            studentList = new ArrayList<Student>();
            studentList.add(new Student("Dwi Ardi Irawan", (new
GregorianCalendar(8, Calendar.APRIL, 1984)).getTime(), "5106100506"));
            studentList.add(new Student("Tri Aditya Sasongko", (new
GregorianCalendar(11, Calendar.NOVEMBER, 1988)).getTime(), "5106100507"));
            studentList.add(new Student("No Name", (new GregorianCalendar(1,
Calendar.JANUARY, 2011)).getTime(), "5106100508"));
        }
        return studentList;
    }

    public SelectModel getStudentModel(){
        return new StudentSelectionModel(getStudentList());
    }

    public StudentValueEncoder getStudentEncoder(){
        return new StudentValueEncoder(getStudentList());
    }
}

*StudentSelectionModel.java*

public class StudentSelectionModel implements SelectModel {
    private List<Student> studentList;

    public StudentSelectionModel(List<Student> studentList) {
        this.studentList = studentList;
    }

    public List<OptionGroupModel> getOptionGroups() {
        return getSelectModel().getOptionGroups();
    }

    public List<OptionModel> getOptions() {
        return getSelectModel().getOptions();
    }

    public void visit(SelectModelVisitor visitor) {

        for (OptionGroupModel optionGroupModel :
getSelectModel().getOptionGroups()) {
            visitor.beginOptionGroup(optionGroupModel);
            for (OptionModel optionModel : optionGroupModel.getOptions()) {
                visitor.option(optionModel);
            }
            visitor.endOptionGroup(optionGroupModel);
        }

    }

    public SelectModel getSelectModel(){
        List<OptionModel> optionModelList = new ArrayList<OptionModel>();

        for (Student student : studentList) {
            optionModelList.add(new OptionModelImpl(student.getName(),
student));

        }
        return new SelectModelImpl(new OptionGroupModelImpl(null, false,
optionModelList));
    }

}

*StudentValueEncoder.java*

public class StudentValueEncoder implements ValueEncoder<List<Student>>{
    private List<Student> studentList;

    public StudentValueEncoder(List<Student> studentList) {
        this.studentList = studentList;
    }

    public String toClient(List<Student> studentList) {
        return null;
    }

    public List<Student> toValue(String value) {
        List<Student> selectedStudentList = new ArrayList<Student>();
        for(Student student : studentList) {
            if(student.getNrp().equals(value)) {
                selectedStudentList.add(student);
            }
        }
        return selectedStudentList;
    }

}

Reply via email to