3 Replies Latest reply on Jul 3, 2008 3:29 PM by nimo stephan

    manuel convert from string to object

    nimo stephan Master

      How can I convert from a List of String-Objects into another (Entity-)Object?

      I have this in my Entity:

      private List<Role> roles = new HashSet<Role>();

      and this in my sessionBean:

      private List<SelectItem> roles;

      I retrieved values for Roles from a selectManyCheckbox:

      20:23:36,484 INFO  [STDOUT] Element in set: entity.Role@f86dd86c: java.lang.String
      20:23:36,484 INFO  [STDOUT] Element in set: entity.Role@a57fe861: java.lang.String

      So u see, the values retrieved from the GUI are String-Objects.

      Now I wanna cast them to Role-Objects:

      I have tried it with that:

      // go through the roles List which consists of java.lang.STRING-objects
      for (Iterator i = roles.iterator(); i.hasNext();) {
      Object m = (Object) i.next();
      // and cast the next STRING-Objects to my ROLE-Objects
      Role o = (Role) m.getClass().cast(role);

      ..but the cast does not work. So how can I cast (convert) it ?

      (s:convertEntity does not work, I got an exception with that)