tapestry-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Wells <dan_we...@byu.edu>
Subject MultiplePropertySelection component from Contrib library
Date Tue, 19 Aug 2003 19:37:17 GMT
Hi all,

I am having a problem with getting the MultiplePropertySelection to work
as I expect.  I think I just am not able to see what I'm missing, and I
would appreciate another pair of eyes taking a look, if anyone has a
moment.

I have a wizard (multipage form) with a step that allows users to select
from a checkbox list.  If a user has already selected these, and have
come back to this page, I want the values they already checked to appear
checked.

I've made sure my equals method is set up right.  I've even hardcoded
the value I wanted to be checked in the getSectionList() method.

I have a PropertySelection component working for another page, but I
can't see why this one isn't working.  Thanks in advance if anyone helps
out.

Here are the simplified, relevant parts of my code if anyone has a few
minutes to take a look:

.html
-------------------------------------------------------
<span 
 jwcid="sectionCheckList@contrib:MultiplePropertySelection"
 selectedList="ognl:sectionList"
 model="ognl:sectionsModel">

<input type="checkbox">Section 1</input>
<input type="checkbox">Section 2</input>

</span>


.java (of component - the wizard step)
-------------------------------------------------------
public class BbSections extends CmuComponent implements
PageRenderListener
{
  private IPropertySelectionModel sectionsModel;

  private List sectionList = new ArrayList();

  public List getSectionList()
  {
    return this.sectionList;
  }

  public void setSectionList(List sections)
  {
    BbWebSite currentSite = getCmuVisit().getCurrentSite();

    currentSite.setSectionList(sections);

    getCmuVisit().setCurrentSite(currentSite);
    
    this.sectionList = sections;

  } //setSectionList

...

  public IPropertySelectionModel getSectionsModel()
  {
    String yearTerm = getCmuVisit().getCurrentSite().getYearTerm();

    List classSections = new ArrayList();

    try
    {
      Person user = getCmuVisit().getEffectiveUser();
      
      classSections = getController().getClassSections(user, yearTerm);
    }
    catch (Exception e)
    {
      getCmuPage().handleError(e);
    }

    IPropertySelectionModel model = new 
               ClassSectionSelectionModel(classSections);

    return model;

  }
  
  public void pageBeginRender(PageEvent event)
  {
    List sections = getCmuVisit().getCurrentSite().getSectionList();
    
    if (sections == null)
      return;
  
    setSectionList(sections);
    
  }

} //class


ClassSection.equals() method
-------------------------------------------------------
public boolean equals(ClassSection section)
  {
    if
(section.getCreditInstitution().equals(this.getCreditInstitution())
      && section.getYearTerm().equals(this.getYearTerm())
      && section.getCurriculumId().equals(this.getCurriculumId())
      && section.getTitleCode().equals(this.getTitleCode())
      && section.getSectionNumber().equals(this.getSectionNumber()))
    {
      return true;
    }

    return false;

  } //equals



ClassSectionSelectionModel.java
-------------------------------------------------------
public class ClassSectionSelectionModel implements
IPropertySelectionModel
{
  private List sections;

  public ClassSectionSelectionModel(List sections)
  {
    this.sections = sections;
  }

  public int getOptionCount()
  {
    return sections.size();
  }

  public Object getOption(int idx)
  {
    return sections.get(idx);
  }

  public String getLabel(int idx)
  {
    ClassSection section = (ClassSection) sections.get(idx);

    String label =
      section.getDeptName() + " " + 
      section.getCatalogNumber() + 
      section.getCatalogSuffix() + " Section " + 
      section.getSectionNumber();
        
    return label;
  }

  public String getValue(int idx)
  {
    ClassSection section = (ClassSection) sections.get(idx);

    String value =
      section.getCreditInstitution() + ":" + 
      section.getYearTerm() + ":" + 
      section.getCurriculumId() + ":" +
      section.getTitleCode() + ":" + 
      section.getSectionNumber();
        
    return value;
  }//getValue

  public Object translateValue(String val)
  {
    String[] fields = val.split(":");

    ClassSection section = new ClassSection();

    section.setCreditInstitution(fields[0]);

    section.setYearTerm(fields[1]);

    section.setCurriculumId(fields[2]);

    section.setTitleCode(fields[3]);

    section.setSectionNumber(fields[4]);

    return section;

  }//translateValue

} //class


-- 
Dan Wells <dan_wells@byu.edu>


Mime
View raw message