4 Replies Latest reply: Oct 31, 2012 11:10 AM by Ravi Jegga RSS

    Dynamically show fields in the form.

    Sachin Gupta
      Hello All,

      We have a requirement where the fields needs to be dynamically determined and generated at runtime. To explain it better, in the process flow user will assign start date and finish date for the project. Based on the start/finish date specified, determine the number of months between them. It could be one month to several months like 20.

      Based on the above we have to dynamically show the fields in the form. So if the number of months are 20, UI should dynamically show 20 fields. Each field will correspond to one row in the database table. The header of the fields should also be dynamic to show the month-year for the field.

      We are using BPM with Feature Pack installed.

      My questions are
      1. How to implement this in the BPM Process flow?
      2. Do we have to use something like dynamic sql/ref cursor to determine the number of fields and their header?
      3. Based on the start/finish date entered how can we render the page to show the fields without saving/submitting the changes?

      Any suggestion/pointer on how this can be implemented in the BPM process flow and the ADF UI.

      Thanks in advance.

      Sachin Gupta
        • 1. Re: Dynamically show fields in the form.
          Daniel Atwood
          Hi Sachin,

          Others will be have different suggestions, but here is what I'd do.

          I'd suggest that you steer away from trying to store all of the information inside of each work item instance's payload. Instead, have the BPM process store the ID and then use that ID to retrieve the information from the database using ADFbc when the ADF form loads. It's not obvious how this is done and I struggled with it as well. Here's a blog post I wrote a few months ago that describes step-by-step how this is done- http://www.avioconsulting.com/blog/datwood/2012/06/19/using-bpm-process-variable-adf-form-retrieve-database-information-0.

          Sure you've already done this, but hit the Oracle ADF forum (JDeveloper and ADF This forum is incredibly active and if you decide to go the ADFbc database route, they'll be able to help you with your ADF form questions.

          • 2. Re: Dynamically show fields in the form.
            Ravi Jegga
            Hi Sachin
            1. Dan already put you in the right direction with his tips and pointers. We have a similar use-case but not for like "n" number of records but for a single record set. The below steps should give you an idea. You may find other approaches also. I used ADF BC stuff with minimal code possible.

            2. Create a DB Table (hopefully you already have), with columns like ID (Pk, uses Sequence Generator), BpmTaskNumber (this is the unique TaskId for each Process that you get from Payload), and your own custom columns like MY_DATE, MY_YEAR, MY_COL1, MY_COL2, MY_COL3 etc. If you familiar with JPA/Entities/ADF Framework, then just create a Java Entity for this Table. For PK variable add annotation to automatically generate the sequence using sequence generator for the PK value. Lets name this Entity as "MyEntity.java".

            3. Create a simple stateless Session EJB with couple of methods to create/read records from this table using Entities. Test them from a simple java client, to make sure all this works as expected.

            4. Now coming to integrating on the screen, for you TaskDetails jspx, create a simple ADF ManagedBean and link it to this page. Your task details page should already have lots of out of box managed beans linked in adf-config.xml file etc. On task details page, you may have dragged your 2 payload elements for startDate and endDate. Now add a Command Button (for now) and for this create a action method in your own managed bean like generateForm(). This managed bean, will have a instance variable of type List that corresponds to your entity like List<MyEntity> myEntities = new ArrayList<Entity>(); In generateForm() method, first using bindings get the startDate, endDate values. Do basic validation like they both are entered etc. If yes, get the difference between those dates (months). Create that many Empty MyEntity instances like MyEntity myEnt = new MyEntity() in a loop and add to the myEntities list.

            5. On the TaskDetails jsp file, create a af:table component, for this myEntities list. Then for columns add all your columns with input text fields, date fileds, etc etc. Do NOT add bpmTaskNumber, ID for now.

            6. For quick testing, add another button like "MySave" that calls another new method on your manage bean like saveData(). In this saveData(), get the fully populated myEntites list. Get taskId from the task payload and set it to each record to the variable bpmTaskNumber. This is very important. Because once the taskDetails page is saved and log out. Next day when you open that task details page, you should see all the "n" number of rows. This is where you will use your taskId from payload and do a query on your EJB with that bpmTaskNumber that pulls all records (MyEntity) and show on screen.

            7. Once all this works on click on 2 buttons like "GenerateForm" and 'MySave", now you to link them to actual Task Save, Submit actions etc. For generation form, go with custom button or do like onChange of second date fields etc. But for task actions, look at the code snippet, you can hook up your own new method in the actionListener. In this first save "n" records to database and then continue the task action. Basically you had to intercept the out of box actions. I have a code snippet in this below post.
            https://forums.oracle.com/forums/thread.jspa?threadID=2217874&start=0&tstart=0 (If you want to store "n" myEntities in Payload, this post can help).

            If you are familiar with bindings, then once you create EJB, simply create a DataControl for that EJB Local interface. This will create all methods you defined like save, get, update, delete etc etc. Drag and drop them on the taskDetails page and create ui components for them like Table etc. Edit the generated code with your column names etc. For any parameters to these methods, set them in managed bean invoke these data control actions by getting those bindings and using like execute methods.

            I hope the above should put you in some direction. Just note that, it needs a decent adf knowledge unless you want to write native sql code to talk to db tables.

            Ravi Jegga
            • 3. Re: Dynamically show fields in the form.
              Sachin Gupta
              Thanks Dan and Ravi for providing the pointers. I am not an expert of ADF and BPM. I will work in this direction and update the outcome soon.

              Sachin Gupta
              • 4. Re: Dynamically show fields in the form.
                Ravi Jegga
                Good luck Sachin. By the time we think we are Experts, a new version of product/framework is released and we end up learning that new stuff. Humbly speaking we can never be Experts :). Its always a Learning path :). Ping us for any information during your learning path.

                Ravi Jegga