2 Replies Latest reply on May 8, 2009 12:33 AM by Cody Lerum

    combobox returning 'null'

    Pieter Bosman Newbie

      Hello everybody,

      Let me start of by thanking those that actually take the effort of reading it all! I know it's a very long post.

      TLDR Version:
      I'm going a bit crazy over my inability to get the Combobox provided by RichFaces working with a list of Entities in combination with the convertentity option.
      It keeps on returning a 'null' value somehow.

      I've been busting my brain on this for over a week and googled 12.000lbs of CO² into the air searching for a solution. So I turn to the forums.
      I would like to know if there is something I'm doing wrong. If there is another way of solving this. If it's a known bug.

      What I want to do:
      I've got an application that was generated using seam-gen, based on an existing database I've used in the past to supply a swing-application with data.
      The concept is that I wish to show a combobox (as described and exampled on the richfaces live demo site) with a list of my 'Speler' objects. Following a selection of one of the items in the combobox I wish to have the corresponding object behind it to be passed to a variable in my action bean behind it.
      I check this through the use of the logging tool supplied.

      The problem:
      I keep on getting a 'null' value that is returned to my action bean.

      What I have tried:
      1) created a custom entity converter and neither of the getAsString and getAsObject were being called

      2) used the convertentity and overridden the toString, hashCode and equals methods in my model bean

      3) used all different type of scopes: Session, Page, Conversation (just to check em all)

      Suffice to say, all to no avail.

      Development Environment:
      Eclipse Europa EE with JBossTools
      JBoss AS 4.2.3 GA
      Seam 2.1.1
      RichFaces 3.3.0 (previously tested with supplied RichFaces in Seam 2.1.1 with same results)

      The Code:

      Model / Entity Bean (remember this was created by seam-gen):

      // Generated 23-feb-2009 11:49:34 by Hibernate Tools 3.2.2.GA
      // package and import stuff left out
       * Speler generated by hbm2java
      @Table(name = "speler", catalog = "saga", uniqueConstraints = @UniqueConstraint(columnNames = "login"))
      @Roles( { @Role(name = "loggedIn", scope = ScopeType.SESSION),
                      @Role(name = "selectedSpeler", scope = ScopeType.SESSION) })
      public class Speler implements java.io.Serializable {
              private Long id;
              private String naam;
              private String paswoord;
              private String login;
              private String voornaam;
              private String role;
              public Speler() {
              public Speler(String role) {
                      this.role = role;
              public Speler(String naam, String paswoord, String login, String voornaam,
                              String role) {
                      this.naam = naam;
                      this.paswoord = paswoord;
                      this.login = login;
                      this.voornaam = voornaam;
                      this.role = role;
      //Getters & Setters left out

      Action Beans
      The Listingbean (created by seamGen)

      // package and import stuff left out
      public class SpelerList extends EntityQuery<Speler> {
              private static final String EJBQL = "select speler from Speler speler";
              private static final String[] RESTRICTIONS = {
                              "lower(speler.login) like concat(lower(#{spelerList.speler.login}),'%')",
                              "lower(speler.naam) like concat(lower(#{spelerList.speler.naam}),'%')",
                              "lower(speler.paswoord) like concat(lower(#{spelerList.speler.paswoord}),'%')",
                              "lower(speler.role) like concat(lower(#{spelerList.speler.role}),'%')",
                              "lower(speler.voornaam) like concat(lower(#{spelerList.speler.voornaam}),'%')",};
              private Speler speler = new Speler();
              public SpelerList() {
      //              setMaxResults(25);
              public Speler getSpeler() {
                      return speler;

      Action bean behind the page (I wrote this thing)

      // package and import stuff left out
      public class SpelerSelection
          @Logger private Log log;
          @In StatusMessages statusMessages;
          Speler selectedSpeler;
          public void spelerSelection()
              // implement your business logic here
              log.info("spelerSelection.spelerSelection() action called");
              log.info("SelectedSpeler = " + selectedSpeler);
          public void testSelection(Speler s) {
              log.info("Selection made in list: " + s);
              public Speler getSelectedSpeler() {
                      return selectedSpeler;
              public void setSelectedSpeler(Speler selectedSpeler) {
                      this.selectedSpeler = selectedSpeler;
          // add additional action methods

      The converter I wrote and use, for reference the log messages I put in are NEVER shown:

      // package and imports left out
      import sagacreator.model.Speler;
      public class SpelerConverter implements Converter {
              @Logger private Log log;
              @In List<Speler> spelerList;
              public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
                      log.debug("getAsObject Called with String = " + arg2);
                      return null;
              public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
                      log.debug("getAsObject Called with Object = " + arg2);
                      String s = "";
                      if (arg2 instanceof Speler) {
                              Speler speler = (Speler) arg2;
                              return speler.toString();
                      return null;

      the xhtml page (template used is the default one created by seamgen)

      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
              xmlns:a="http://richfaces.org/a4j" template="layout/template.xhtml">
              <ui:define name="body">
                              <f:facet name="header">spelerSelection</f:facet>
                              <h:form id="spelerSelectionForm">
                                      <rich:comboBox selectFirstOnUpdate="false"
                                              defaultLabel="Type the first few letters..."
                                              <s:selectItems var="_selectedSpeler" value="#{spelerList}" />
                                      <h:commandButton id="spelerSelection" value="spelerSelection!"
                                              action="#{spelerSelection.spelerSelection}" />

      Console output:
      On Page loading:

      15:40:21,406 INFO  [STDOUT] Hibernate: 
              speler0_.ID as ID14_,
              speler0_.ROLE as ROLE14_,
              speler0_.PASWOORD as PASWOORD14_,
              speler0_.NAAM as NAAM14_,
              speler0_.login as login14_,
              speler0_.VOORNAAM as VOORNAAM14_ 
              saga.speler speler0_

      On button click:

      15:41:38,000 INFO  [SpelerSelection] spelerSelection.spelerSelection() action called
      15:41:38,000 INFO  [SpelerSelection] SelectedSpeler = null

      I hope I was clear enough in my problem description! (and please excuse any mistakes I made in my english, I'm native dutch speaking :) )

      A duplicate of this post is made on the JBoss Forums.

      Thanks in advance for ANY help that is provided!


        • 1. Re: combobox returning 'null'
          Pieter Bosman Newbie

          So I switched the log.debug to log.info in my converter and got to see the messages.

          However, in that same converter my 'spelerList' object keeps on being a 'null' value.

          I was under the impression an @In annotation would ensure the object being injected and hence being 'not-null' ?

          I first thought it would be linked to my PAGE scoping of the SpelerList class, but I changed it to SESSION and still it turns out to be 'null' in my Converter class.

          Any help?

          Thanks in advance!

          • 2. Re: combobox returning 'null'
            Cody Lerum Apprentice


            Your converter has @BypassInterceptors which prevents the @In from triggering.

            Alternatively you could use Component.getInstance("spelerList") to inject.