2 Replies Latest reply on Oct 16, 2007 11:33 AM by pmuir

    creating Edit forms for transaltable entities  - and keep ma

    marius.oancea

      If you edit simple objects like Users, you can have thinks like:
      <h:inputText value="#{user.username}" required="true"/>

      This is very simple because user.username is a simple string and binding to the input fields is evident.

      How one would approach the following problem:

      I have a entity named "Word". Word has a name that is different in every language. So I have the following structure:

      Word Translation
      ==== ==========
      name : Translation --------------> language: String
      text: String


      Binding input fields like below, is not possible:

      <h:inputText value="#{word.name(selectedLanguage)}" required="true"/>


      What is the most elegant way to solve that?

      Note:
      selectedLanguage is a statefull component.

      One posibility is to create a WordWrapper component in wich I inject selectedLanguage, and a word object. Then I provide methods for binding (set/get for name in selected language). This will work I think but I have very many Classes like Word and will be much work.

      Any better approach to write less code ?

        • 1. Re: creating Edit forms for transaltable entities  - and kee
          marius.oancea

          Ad schematics:

          Word Translation
          ==== ==========
          name : Translation --------------> language: String
          text: String
          


          I replace the ascii art with some code. I think is better:
          @Entity
          @Name("word")
          public class Word {
           Set<Translation> name = new HashSet<Translation>(); // maybe better use a Map because for each language we have one name.
          
           // setters and getters
          
          }
          
          @Entity
          public class Translation {
           String languageStr;
           String text;
          
           // setters and getters
          }
          


          Please ignore the missing identifiers but are not relevant.

          • 2. Re: creating Edit forms for transaltable entities  - and kee
            pmuir

            Make it a map and do #{word.name[language]} where language is a variable that is scoped to longer than the request and so available when restoring the view.