5 Replies Latest reply on May 21, 2007 9:58 AM by anescu

    @Embeddable question

      Hi,

      We're trying to use an @Embeddable class in our project. It's a seam generated project, but we keep our entities and modify the views as needed.

      So, we have a ABC @Embeddable class which has one field

      private String name;

      And this class is embedded into another, XYZ.

      On the interface i have a field:
      <s:decorate id="ABCNameDecoration" template="layout/edit.xhtml">
       <ui:define name="label"><h:outputText value="#{messages['XYZ.ABCName.label']}" /></ui:define>
       <h:inputText id="ABCName"
       size="100"
       maxlength="100"
       value="#{xyzHome.instance.ABC.name}" title="#{messages['XYZ.ABCName.tooltip']}">
       <a:support event="onblur" reRender="ABCNameDecoration"/>
       </h:inputText>
      </s:decorate>


      The page renders ok, but when i try to edit/add an entity and put some value into this field I get a validation error:
      value could not be converted to the expected type

      No error shows up in the log, even on debug mode.

      I browsed the forum and found somewhere something about needing a converter for this entity. I also found some examples on how to build a custom JSF converter. So, my questions are:
      1) is there a doc on how to do custom converters on seam (what needs to be configured and so on)
      2) If my ABC class has 5 fields, all rendered on the page of the owing entity (XYZ) as separate fields, do I need 5 converters, one for each field????
      Tnx, I wait for your reply...

        • 1. Re: @Embeddable question
          fernando_jmt

          Have you declared the ABC as follows?:

          public class XYZ {
          ...
          private ABC abc = new ABC();
          
          ...
          getters/setters
          }
          
          


          In this case "abc" should be referenced in the view, not ABC.

          HTH.

          • 2. Re: @Embeddable question

            Yes, I just tried and the same problem.
            i also tried this one: I manually inserted the value into the DB (in xyz_abc_name field), so this one works like this, after that i deleted the value from the field and updated, all works ok.

            Is possible I need to set not null value on the field in the constructor???

            • 3. Re: @Embeddable question

              Correction:

              It works to insert a new entity XYZ. But i have a script which inserts some rows into xyz tables without the xyz_abc_name field. If i select one of these entities and want to update the abc.name field to something then i get a validation error.

              Anybody any idea how to solve this one?

              • 4. Re: @Embeddable question
                fernando_jmt

                I make a mistake in my last post, the code shoul be:

                public class XYZ {
                ...
                @Embedded
                private ABC abc = new ABC();
                
                ...
                getters/setters
                }
                
                


                And your ABC must have @Embeddable at type level.

                do you have it in this way?

                • 5. Re: @Embeddable question

                  Yes, i have them both. Earlier i had only the @Embeddable on class ABC, but i saw the @Embedded annotation in another post and used it.

                  So the insert works, but the update of some already inserted entities does not.