6 Replies Latest reply on Jan 18, 2007 5:32 AM by Pete Muir

    Combining EntityHome and session beans

    jk;l jkl; Expert

      If there's CRUD functionality for which I'd like to use EntityHome, but the user functionality has more complex validation than simply getting the #{person.firstName} and #{person.lastName} fields as entered in a form and doing a #{personHome.persist} (as in the the example given in ch. 14 of the Seam documentation), how would I do this?

      Would the complex validation and other things be included in EntityHome, or would it be a separate session bean? If the latter, how would you get the session bean and EntityHome to work together to accomplish this?

      An example is below:

      <div>First name: <h:inputText value="#{person.firstName}"/></div>
       <div>Last name: <h:inputText value="#{person.lastName}"/></div>
      
       <h:commandButton value="Create Person" action="#{myPersonBean.persistPerson}"/>
      
      


      (where "person" is a factory on the EntityHome)

      If the persistPerson() method has several validation and other things going on within the session bean, and you can't simply do a personHome.persist in its place, is EntityHome still useful? What's the best way to approach a situation like this? Should everything be done in the EntityHome, or should nothing be done? Or if both session beans and EntityHome are to be used, how would you divide up the responsibilities between the two?

      Thanks.

        • 1. Re: Combining EntityHome and session beans
          Pete Muir Master

          I normally extend the EntityHome and add the extra logic to this. I'll override persist, add in any custom (e.g. validation) logic, and then call super.persist() as needed.

          An exception to this is if I have a pageflow, in which I'll put the flow logic in a seperate bean (but still use a home bean for any crud, probably by injecting it into the flow-control bean).

          • 2. Re: Combining EntityHome and session beans
            Gavin King Master

            Right. EntityHome is meant to be extended.

            • 3. Re: Combining EntityHome and session beans
              jk;l jkl; Expert

              petemuir, is it correct to say that you would only put in EntityHome whatever validation or processing that would still need to be processed regardless of which pageflow the entity was being used by?

              Oh, I'm kinda confused...you can inject regular (non-bean) classes into beans? Why would you do this...wouldn't you only inject things that are managed by the container, like beans?

              • 4. Re: Combining EntityHome and session beans
                Pete Muir Master

                Well, I don't have a hard and fast rule about any of this (because that would be silly ;). So I would start by putting the validation on the home bean, then, if needed later on, move it onto the flow control bean. The only example of this I came of needing on the pageflow was:

                A wizard (backed by a pageflow) which the user could work on, then leave, then return to (e.g. the next day). I needed to make sure most of the fields were required BUT not on all submissions of the form, just when the user choose to "save and submit" (the final time). So for this I put the logic making fields required into the pageflow bean.

                Your second point is probably just a terminology problem - what I meant is that I have one seam component for pageflow logic (e.g. as discussed above) and the home component. I inject the home component into the pageflow component (using @In) - you can inject any Seam component into another one which supports bijection (i.e. not entity beans)

                • 5. Re: Combining EntityHome and session beans
                  jk;l jkl; Expert

                  If the user returned the next day (or after any long enough amount of time), wouldn't the SFSB on the server have timed out (with any normal timeout setting)?

                  When you implemented your wizard, were you able to use Hibernate Validators at all somehow in your validation/logic method in the pageflow bean, or was it some rather ugly coding? (I ask because don't Hibernate Validators run whenever their annotated property is populated rather than conditionally?)

                  • 6. Re: Combining EntityHome and session beans
                    Pete Muir Master

                    Yes, the SFSB (and conversation) has started - I just reload the necessary (already entered) and start a new conversation. No, I didn't use hibernate validators for the pageflow validation - as I was using it for standard validation. I did some coding to get around this - but I think there was a discussion about making it possible to use Seam/Hibernate validation for this.