Topic
11 replies Latest Post - ‏2013-01-10T14:32:21Z by mburati
Codeoline
Codeoline
141 Posts
ACCEPTED ANSWER

Pinned topic Required

‏2012-12-20T18:34:20Z |
How do I go about making some fields required based on entries in other fields? Is there an example i could look at?
Updated on 2013-01-10T14:32:21Z at 2013-01-10T14:32:21Z by mburati
  • mburati
    mburati
    2543 Posts
    ACCEPTED ANSWER

    Re: Required

    ‏2012-12-21T15:10:41Z  in response to Codeoline
    If you want this done in the browser (for speed/convenience) then you would typically write that cross field validation in Javascript.

    If you want/need this done on the server (typically the case for data consistency and security reasons), then this is considered "cross field validation".

    I would've suggested just searching this forum and the wiki for "cross field validation" but the forum search is hard to weed through with multiple non-unique tokens returning a lot of non-related hits, and the wiki search appears to be down at the moment, so I did some digging for you.

    The WEF Page Automation overview document (PDF) describes how to do cross field validation (check field B if field A is ...) with a page automation (eg, Data Page or related builder) post submit action:

    http://www.lotus.com/ldd/pfwiki.nsf/xsp/.ibmmodres/domino/OpenAttachment/ldd/pfwiki.nsf/6B8CD87CE91D4A5D8525748A0070820A/attach/PageAutomation.pdf&ei=6nrUULizAora0QG9-oHYBg&usg=AFQjCNE_nOCfkgqigIM6INnbRTx72xSd_g&sig2=1eJSapzoEtwwMv3a-B9Xcg&bvm=bv.1355534169,d.dmQ

    I hope that info helps,
    ..Mike Burati
    http://www-10.lotus.com/ldd/pfwiki.nsf/
    The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.
    • Codeoline
      Codeoline
      141 Posts
      ACCEPTED ANSWER

      Re: Required

      ‏2013-01-02T17:50:01Z  in response to mburati
      Will this work if i am using DSUI?
      • mburati
        mburati
        2543 Posts
        ACCEPTED ANSWER

        Re: Required

        ‏2013-01-02T18:28:01Z  in response to Codeoline
        I haven't tried that with DSUI myself, but I would think it should be possible to make it work.
        DSUI is a high level builder built on top of page automation (Data Page etc), so what applies to page automation typically should also apply to artifacts generated by DSUI's use of page automation.

        I hope that info helps,
        ..Mike Burati
        http://www-10.lotus.com/ldd/pfwiki.nsf/
        The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.
        • Codeoline
          Codeoline
          141 Posts
          ACCEPTED ANSWER

          Re: Required

          ‏2013-01-02T19:49:12Z  in response to mburati
          I am validating to and from dates using a method along with post save. I should be able to add this to the method, save correct?

          {
          String res = inputs.getText("reservation");
          String pref = inputs.getText("preferance");
          if (("Yes".equals(res)) {
          if ((pref == null) || (pref.length() == 0)) {
          errors.addMessage("res", "This field is required when a reservation is needed" + pref + ".");
          }
          }
          }
          • mburati
            mburati
            2543 Posts
            ACCEPTED ANSWER

            Re: Required

            ‏2013-01-02T20:22:58Z  in response to Codeoline
            It's hard to say just from that snippet what's happening in your particular application. You may want to stick in printlns of what you're getting for those input values to be sure you're getting what you believe you should be receiving there. Also, you appear to be retrieving an input from "reservation" but setting the error on a field named "res", so please be sure that the field names you're using there match the names that page automation is expecting for that input form (eg, double check the field names in the Design View in the designer).

            If you post a sample (with no confidential info or intellectual property) showing what you're having trouble with, it might make it easier for someone to quickly spot what's wrong with it.

            I hope that info helps,..Mike Burati http://www-10.lotus.com/ldd/pfwiki.nsf/The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.
            • Codeoline
              Codeoline
              141 Posts
              ACCEPTED ANSWER

              Re: Required

              ‏2013-01-02T21:01:50Z  in response to mburati
              Thank You.
              I will try and do a small DSUI that i can post.
              I appreciate your help.
              • mburati
                mburati
                2543 Posts
                ACCEPTED ANSWER

                Re: Required

                ‏2013-01-02T22:45:54Z  in response to Codeoline
                Since I hadn't tried this with DSUI myself I wanted to make sure I wasn't missing some difference from the above referenced article.

                I took the code from the above referenced page automation article (on cross page validation) almost verbatim and changed the name of the update page to the one used by DSUI in the out of the box Orders Service Consumer sample that comes with WEF 7.0.1.x and 8.0.0.x.

                With the following code, if I update/edit an order that has status "Shipped" and clear the "Date Shipped" field, I get and see the error set by this post save method that I set in the DSUI builder. Again, the following code is almost identical to the above article - I just changed the page name where it gets the Errors LJO (from updatePageError to uiUpdateError, so that it would work with the current WEF Orders Service Consumer sample, since DSUI names the pages differently than View and Form) and changed the text of the error message slightly. The logic is the same (copied from) the above mentioned article.

                
                
                { PageAutomationMessages errors = (PageAutomationMessages)webAppAccess.getVariables().getObject(
                "uiUpdateError"); System.out.println(
                "Debug: Got errors LJO: " + errors); IXml inputs = webAppAccess.getVariables().getXml(
                "ordersUpdateOrderInputs"); System.out.println(
                "Debug:  got update inputs: " + inputs); String status = inputs.getText(
                "STATUS"); System.out.println(
                "Debug: got STATUS input: " + status); String dateShipped = inputs.getText(
                "DATE_SHIPPED"); 
                
                if ((
                "Shipped".equals(status))||(
                "Returned".equals(status))) 
                { 
                
                if ((dateShipped == 
                
                null) || (dateShipped.length() == 0)) 
                { errors.addMessage(
                "DATE_SHIPPED", 
                "Date Shipped is required when the status is: " + status + 
                "."); 
                } 
                } 
                }
                


                Note, you may want to make sure some other validation on the page fails first (eg, set another field to required and leave that field blank when you submit) to be sure that default (non-cross-field) validation is working in general on your input page.

                I hope that info helps,
                ..Mike Burati
                http://www-10.lotus.com/ldd/pfwiki.nsf/
                The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.
                • Codeoline
                  Codeoline
                  141 Posts
                  ACCEPTED ANSWER

                  Re: Required

                  ‏2013-01-09T15:33:40Z  in response to mburati
                  In the end what I would like to accomplish with this post is cross at the same time validating from and through dates. I have both working separately but would like them to work together for both create and update.

                  Before I can do that I would like to know how to create a table or something that I can incorporate into my model so the forum can execute this app. Obviously you are not able to tap into my DB.

                  Much Thanks

                  Attachments

                  • mburati
                    mburati
                    2543 Posts
                    ACCEPTED ANSWER

                    Re: Required

                    ‏2013-01-09T18:51:36Z  in response to Codeoline
                    I'm sorry I don't understand which part you still don't have working? Can you just add both sets of checks to your postSaveAction method?

                    If you want and need to, you should be able to generate a "stub" provider model that can be run without your DB. In the Service Provider model's Service Definition builder, in the testing section, there's a button to Generate Stub (and an input to name the model for that stub) which will generate a dummy service provider that can return static data with the same service operations/interface as your actual provider. I'm not sure you need to do that though, if you just need to get both sets of validation working and can combine that logic in your post save action method.

                    I'm also not sure why you appear to be hand coding JDBC code and leveraging that via LJO rather than using the WEF SQL builders.
                    Was there something you were trying to do with the WEF SQL builders but having trouble understanding how to do or is this just pre-existing code that you had to leverage in this app?

                    I hope that info helps,
                    ..Mike Burati
                    http://www-10.lotus.com/ldd/pfwiki.nsf/
                    The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.
                    • Codeoline
                      Codeoline
                      141 Posts
                      ACCEPTED ANSWER

                      Re: Required

                      ‏2013-01-10T14:19:37Z  in response to mburati
                      The calendar validate has a return type of String and the cross validation has a return type of void. I did not think they would both work in one method.

                      I would love to learn how to use the SQL builders. I just have not had time. Most of what i am working with i inherited and yes there is plenty in WEF that i do not understand but, am looking forward to learning more.

                      Almost everything i have learned and accomplished in WEF has been with help from the forum and i am grateful for that.

                      Thank You
                      • mburati
                        mburati
                        2543 Posts
                        ACCEPTED ANSWER

                        Re: Required

                        ‏2013-01-10T14:32:21Z  in response to Codeoline
                        You appear to be returning null in your date validation method (since it wants a per field validation error message), so while I haven't had time to look at your code in depth to be sure what it's doing, it seems like you should be able to take the date field validation code from your disabled date validation method and copy it into your cross field validation method that is enabled and do both sets of field validation in that same method. I suggest trying that.

                        If you're new to WEF, the Learning Roadmap on the WEF Wiki (URL below) is a great place to get started and will help you understand data integration builders in general, plus the SQL builders. Even before you have time for that, there are intro WEF Videos available off that page, including a pair that show building a DB based provider and then consumer using the SQL builder functionality.

                        I hope that info helps,
                        ..Mike Burati
                        http://www-10.lotus.com/ldd/pfwiki.nsf/
                        The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.