6 Replies Latest reply on May 28, 2009 5:42 PM by jaand96

    looking for alternatives to covertEntity

      Hi!


      I don't have a persistence context in my SEAM webapp. All persistence is done in another application (remote ejb calls).


      Now, the s:selectItems together with s:convertEntity is great but from what I gather I can't use that without a persistence context.


      What do you suggest is the easiest way of achieving similar functionality?


      thanks

        • 1. Re: looking for alternatives to covertEntity
          kragoth

          The easiest and possibly the only way is to write your own converter.


          Look at how SEAM's converter is written and just make your own.


          The app that I'm working on also does not have a persistence context that SEAM is aware of.


          If you get really stuck I'll post my code, but.... my code is a little application specific and most likely would not really be what you want.

          • 2. Re: looking for alternatives to covertEntity

            Thanks, I took your advice and wrote my own. Using Seams EntityConverter and EntityConverterStore as inspiration.


            One thing worth noting (for beginners like me anyway) is that you can't have jsf converters in the hot source directory (using seam-gen). Got IllegalStateException without any further details. Moved it to the main source directory and it worked fine.

            • 3. Re: looking for alternatives to covertEntity
              kragoth

              Excelent! Glad that worked for you. :)

              • 4. Re: looking for alternatives to covertEntity

                Was to hasty here.
                The value I select in the selectOneMenu is assigned to the bound value ok. From the code below:
                #{ProductionPointController.stopTime.function} object is set to the selected #{ProductionPointController.functions}.


                However the inital value is not set when the selectOneMenu renders. Or in html speak, there is no selected in the option tag.


                Any suggestions as to what could cause this??


                
                <s:decorate id="functionDecorate" template="/layout/edit.xhtml">
                     <ui:define name="label">Function:</ui:define>
                          <h:selectOneMenu id="functionselect"
                                              value="#{ProductionPointController.stopTime.function}">
                                              <s:selectItems value="#{ProductionPointController.functions}"
                                                   var="function" label="#{function.name}">
                                              </s:selectItems>
                                              <f:converter converterId="DomainObjectConverter"/>
                          </h:selectOneMenu>                                             
                </s:decorate>          


                • 5. Re: looking for alternatives to covertEntity
                  kragoth

                  Ok, first the reason why this is happening.
                  This happens because your list of functions does not contain the actual instance of the function that is assigned to you stopTime.function. So the DomainObjectConverter doesn't find a match thus no 'selected' html element.


                  There are two ways of going about solving your problem. Well, maybe 3 but... anyways I'll give you them all.


                  1. (Not what I've done, so not 100% sure it will work but from what I've read probly would. Not really recommended due to larger implications.) Implement the equals method on your functions object so that your converter realises that they are infact the same. This is not really a good idea :P


                  2. Do a find and replace in your list of functions and replace the instance in the list with the instance of the one assigned to your stopTime.function. This will work and isn't toooo hard :P


                  3. Make your object store smarter. Don't let it rely on instances, instead look at your 'key' (assuming an actual domain entity with a unique key).



                  I'm not sure if #3 works... have to go back and look at my code that I wrote a while back now to see what I'm doing :P


                  I think the best thing you can do is look at the renderer and see how it is working out whether or not the 'selected' should be output. Once you understand how this happens fixing your converter should be cake.

                  • 6. Re: looking for alternatives to covertEntity

                    Thanks for a good answer. Strange, I thought it would use the converted value (the string) to find the selected row rather than working with the objects!


                    Option one would cause problems down the line for me.
                    I kind of got it working using option 2. But its quite clunky. In the example above, everytime I edit a stopTime I need to replace the instance in the list with the stopTime.function. And function is just an example out of several more...


                    Could you elaborate on #3? My entities have a unique key.


                    Downloaded the mojarra code, will try to find what happens behind the scenes.