1 Reply Latest reply on Mar 2, 2011 4:17 AM by antibrumm.mfrey0.bluewin.ch

    s:selectItems doesn't handle 'no selection' correctly after partial page rerender

    marcelkolsteren

      In my current Seam project, I experienced a problem related to <s:selectItems>. We have a page with a dropdown that looks like this in the xhtml:


      <h:selectOneMenu value="#{someBean.someValue}">
          <s:selectItems 
              value="#{someBean.someList}" var="#{foo}" label="#{foo.name}" 
              noSelectionLabel="" hideNoSelectionLabel="false" />
          <s:convertEntity />
      </h:selectOneMenu>
      



      In some situations, after parts of the page have been rerendered as a result of <a4j:support> for other fields, submitting of the form results in this exception, if the user didn't choose a value from the dropdown:


      java.lang.NumberFormatException with message: "For input string: "org.jboss.seam.ui.NoSelectionConverter.noSelectionValue""
      



      Further analysis with the debugger turned out that in this case the UISelectOne component only had an EntityConverter attached. Normally, the UISelectItems component would have constructed a converter chain for its parent, with the NoSelectionConverter in the first position, followed by the EntityConverter. Digging further, I found that the UISelectOne component and its children had been recreated by facelets during one of the rerenders of the page (this is probably a facelets bug; I will post the issue on a facelets/JSF forum). After the recreation of the UISelectItems component, it had not been rendered; which was correct, because it was not addressed by any reRender attribute. And because it had not been rerendered, the NoSelectionConverter was not added. That's because the addition of the NoSelectionConverter happens in the getValue() method of UISelectItems. Which is peculiar. I would expect that converters are added during view construction, not during view rendering. Who agrees? Who disagrees? It's in fact causing this problem (with a little bit help of the odd facelets view handler).


      I created a small project to show that the problem can be reproduced with a very small example page. I uploaded the project here (war file and sources):


      http://www.4shared.com/file/Tp-EWque/selectitemsproblem.html



      It makes use of Seam 2.2.0.GA, RichFaces 3.3.3.Final and Facelets 1.1.15.B1, and can be built with Maven 3.0. I deployed the war file in the JBoss 5.1.0.GA application server. After deployment, the sample is accessed on this link:


      http://localhost:8080/selectitemsproblem/Main.seam



      It shows a form with three fields:



      • gender radio button

      • name selection dropdown (rerendered when gender changes)

      • country selection dropdown



      The problem can be triggered by first selecting a gender (which causes a rerender of the name selection dropdown) and then pressing the process button. A conversion error will be shown to the user:


      j_id2:country: Validation Error: Value is not valid



      This is caused by the fact that the NoSelectionConverter is not available any more on the country selection field.


      Any remarks, opinions or solutions are welcome.