[PJUG Javamail] problem creating list of data items from results of selectOne ListBox

Michael Phoenix michaelandrewphoenix at gmail.com
Sat Jan 10 02:14:15 UTC 2009


We are having problems with the following:

Here's the JSF
{code}                 <td valign="top">
                                 <h:selectOneListbox size="10"
value="#{LanguageGroupsPage.selectedLanguageGroup}"
                                                     onclick="submit();">
                                    <f:converter
converterId="lingonet.converters.LanguageGroupConverter"/>
                                    <f:selectItems
value="#{LanguageGroupsPage.languageGroups}"/>
                                 </h:selectOneListbox>
                              </td>
                              <td valign="top">
                                 <t:dataList var="languagePair"

value="#{LanguageGroupsPage.languagePairsOfSelectedGroup}"
                                             layout="unorderedList">
                                    <h:outputText
value="#{languagePair.fromToString}"/>
                                 </t:dataList>
                              </td>{code}

And here's the java code
{code}   public List getLanguageGroups () {
      ArrayList list = new ArrayList();
      for( int i = 0; i < m_languageGroups.length; i++ ) {
         list.add( new SelectItem( m_languageGroups[ i ],
m_languageGroups[ i ].getName() ) );
      }

      return list;
   }

   public LanguageGroupLocal getSelectedLanguageGroup ()
   {
      return m_selectedLanguageGroup;
   }

   public void setSelectedLanguageGroup ( LanguageGroupLocal
selectedLanguageGroup )
   {
      m_selectedLanguageGroup = selectedLanguageGroup;
   }

   public List getLanguagePairsOfSelectedGroup () {
      if( m_selectedLanguageGroup == null )
         return null;

      try {
         ArrayList languagePairs;
         UserTransaction ut = (UserTransaction)new
InitialContext().lookup( "java:comp/UserTransaction" );
         ut.begin();
         languagePairs = new ArrayList(
m_selectedLanguageGroup.getLanguagePairs() );
         ut.commit();
         return languagePairs;
      }
      catch( Exception e ) {
         m_logger.error( e, e );
         return null;
      }
   }{code}

The idea is that when you select from the languageGroup listbox that
group's languagePairs should be listed in the languagePairs datalist.
Unfortunately, the list is never rendered when a languageGroup is
selected. I tried to debug by putting a breakpoint in the first line
of the method getLanguagePairsOfSelectedGroup. What I found is that
when the item grom the languageGroup list is selected the framework
invokes this method 3 times. The second time it appears to work
properly, but the first and, more importantly, last time, the variable
m_selectedLanguageGroup is null and so the method returns null which
explains why the languagePairs datalist. However, I don't understand
why the framework is invoking that method 3 times. Xan anybody explain
what is going on and suggest how I might get the datalist to render?
Thanks.



More information about the Javamail mailing list