4 Replies Latest reply on Jul 8, 2012 5:08 PM by lincolnthree

    How to use converters

    g00gle88

      I'm new to Forge (just started today).  I created a project based on the SAKILA database, i was able to generate entities and managedBeans with UI Scafolding for CRUD operations.  However, some enties are not converted to string properly. So I read about converters in the documentation https://docs.jboss.org/author/display/FORGE/UI+Scaffolding can someone give me a simple example how to use these converters?

       

      Thank you.

       

      Julius Sediolano

        • 1. Re: How to use converters
          g00gle88

          bump

          • 2. Re: How to use converters
            lincolnthree
            • 3. Re: How to use converters
              g00gle88

              Hi Lincoln,

               

              Thanks for the reply.  I have already read those articles in fact I'm using the custom converts discuessed @ mkyong's site.  What I'm asking is the converter found in the managed bean that Forge creates when you issue a "scaffold from-entities" command in Forge.

               

              Example:

               

              In the SAKILA database, there's a table called Actor.  So using Forge I created an entity, then scaffolded it.

               

              Here's a snippet of the converter

               

              public Converter getConverter()

                 {

               

               

                    return new Converter()

                    {

               

               

                       @Override

                       public Object getAsObject(FacesContext context, UIComponent component, String value)

                       {

               

               

                          return ActorBean.this.entityManager.find(Actor.class, Long.valueOf(value));

                       }

               

               

                       @Override

                       public String getAsString(FacesContext context, UIComponent component, Object value)

                       {

               

               

                          if (value == null)

                          {

                             return "";

                          }

               

               

                          return String.valueOf(((Actor) value).getActorId());

                       }

                    };

                 }

               

              I can I use this code in my JSF page to convert an Object to a String?

               

              Thanks for your patience.  I've also attached the managedBean that Forge generated.

              • 4. Re: How to use converters
                lincolnthree

                Try it see if it works. I don't see why it shouldn't.