1 2 Previous Next 20 Replies Latest reply on Jun 10, 2007 3:14 PM by beligum Go to original post
      • 15. Re: My list of questions: Seam validation, transactions and
        gavin.king

         

        "hstang" wrote:
        I played around with JSF validation for a few days, and I just couldn't get it play nicely with Seam. I ran into some bizarre problems with transaction management and I just said forget it--I resorted to just action-validation instead.

        "beligum" wrote:

        Gavin, I don't actually use Seam validation (yet), but JSF validation instead. Can this introduce any problems? It seemed to work fine in my simple app, so I don't think that's my cause of error. But then, I'm wrong about many things, apparently ;-)



        I don't know why you had problems by "don't use JSF validation" is definitely not great advice for new users....

        • 16. Re: My list of questions: Seam validation, transactions and
          beligum

          Hi Gavin, here's my code without the templates:

          <h:form>
          <table>
           <tr>
           <td><h:outputLabel for="newSpaceName">name</h:outputLabel></td>
           <td>
           <h:inputText
           id="newSpaceName"
           value="#{selectedSpaceInstance.entityData.name}"
           required="true"
           validator="#{spaceManager.validateSpaceName}" />
           </td>
           </tr>
           <tr>
           <td><h:outputLabel for="newSpaceCompany">company</h:outputLabel></td>
           <td>
           <h:selectOneMenu id="newSpaceCompany" value="#{selectedSpaceInstance.entityData.company}" required="true">
           <s:selectItems value="#{companyManager.possibleSpaceCompanies}" var="company" label="#{company.name}" />
           <s:convertEntity />
           </h:selectOneMenu>
           </td>
           </tr>
           <tr>
           <td></td>
           <td>
           <h:commandButton action="#{spaceManager.updateInstance}" value="update" type="submit" />
           </td>
           </tr>
          
          </table>
          </h:form>
          


          The action-method #{spaceManager.validateSpaceName} is doing some basic unicity-checking on the space-name, that's all. I really like JSF-validation (I hope this _is_ JSF-validation) over annotations in the entity beans, because of the freedom it gives me to do what I want with the data. (or perhaps I'm just too ignorant regarding annotations, that's possible, too)
          Do I still need <s:validateAll/> in this case?

          btw, yes, indeed, I check the DB to see if my changes are persisted or not.


          • 17. Re: My list of questions: Seam validation, transactions and
            pmuir

            Ok, lets see the backing bean as well :)

            You are using a form of JSF validation (#{spaceManager.validateSpaceName}), but you aren't using what Gavin is calling JSF (I would perhaps call it Seam/Hibernate/JSF validation ;) ) - Seam/JSF/Hibernate validation is using a combination of @Min, @Max etc. and s:validate/s:validateAll. This is the simplest and most powerful validation available in Seam IMO.

            Do I still need <s:validateAll/> in this case?


            No.

            Doing validation in action methods (in your case #{spaceManager.updateInstance}) is fine, but, it certainly isn't done in the JSF validation phase, so, your model *will* have been updated with invalid data. It's your responsibility as the developer to deal with this (using @Rollback is, IIRC, one way of doing this, another is to be in flushmode=MANUAL and reload the data manually). This is CERTAINLY NOT the recommended way of doing simple validation (but is required for more complicated situations, like when you need to compare values).

            • 18. Re: My list of questions: Seam validation, transactions and

               

              "gavin.king@jboss.com" wrote:
              "hstang" wrote:
              I played around with JSF validation for a few days, and I just couldn't get it play nicely with Seam. I ran into some bizarre problems with transaction management and I just said forget it--I resorted to just action-validation instead.
              I don't know why you had problems by "don't use JSF validation" is definitely not great advice for new users....

              That was certainly not my intention but after re-reading what I wrote, I could see how it can be interpreted that way.

              My problems *could* be related to what beligum is experiencing as it had to do with transactional errors using JSF validators. I raised JIRA-1408, but I still haven't found a solution yet. I wanted to upload a plain-vanilla test case but can't find an option to upload any more. Instead spending any more time on it, fortunately Seam provides other ways at doing validation so I am not stuck with one particular way of doing things.


              • 19. Re: My list of questions: Seam validation, transactions and
                beligum

                omg, I think I found the problem...

                For clarity, I omitted this section in the second form-entry:

                <s:div rendered="#{empty companyManager.possibleSpaceCompanies}">
                 #{messages['noMembersPresent']}
                </s:div>
                


                so the second entry actually is:
                <tr>
                 <td>
                 <h:outputLabel for="newSpaceCompany">company</h:outputLabel>
                 </td>
                 <td>
                 <h:selectOneMenu id="newSpaceCompany" value="#{selectedSpaceInstance.entityData.company}" required="true">
                 <s:selectItems value="#{companyManager.possibleSpaceCompanies}" var="company" label="#{company.name}" />
                 <s:convertEntity />
                 </h:selectOneMenu>
                
                 <s:div rendered="#{empty companyManager.possibleSpaceCompanies}">
                 #{messages['noMembersPresent']}
                 </s:div>
                 </td>
                </tr>
                


                Now, it seems, when I remove this, everything works as expected.
                How is it possible this is the cause of my problems?

                • 20. Re: My list of questions: Seam validation, transactions and
                  beligum

                  While I'm at it, there's another thing that confuses me.

                  If I login, I select a space (that I'm member of), and a LR conversation is started that keeps track of my do's and don'ts in that space. However, if I'm an admin of that space, I can click the "edit" button that takes me to the page where I can edit the space name and a nested conversation is started (that edits the same bean I selected before).

                  Is this wrong? The docs say I should have read-only access to the beans of the parent conversation, but I want to edit the space I selected before (and I'm allowed to, too, apparently).

                  Is this bad design? If yes, how can I demarcate the "edit-session" so this piece alone can be rolled back?

                  1 2 Previous Next