This discussion is archived
8 Replies Latest reply: May 14, 2013 4:15 PM by Jeet_A RSS

How to show the primary key created by sequence before commit?

BAO.SZ Newbie
Currently Being Moderated
Hi,
In jdev 11.1.2.3,

I create a sequence and database trigger for the primary key of a table, then create a adf table in jsp page,
and with a button for create insert for the table.
By default, the primary key in the page will show blank(null) after I press the create insert button,
only after commit the page, will the primary key value created by the database trigger be shown.

Now my question is :
How to show the primary key created by sequence and database trigger after I press the create insert button and before commit the page?
(don't worry about the waste/discard of sequence number)
btw: to show -1 before commit is not the answer.

Thanks.
  • 1. Re: How to show the primary key created by sequence before commit?
    Timo Hahn Oracle ACE
    Currently Being Moderated
    The answer is to don't use thedb trigger but to use a groovy expression to set the PK whne you create the row. Check http://tompeez.wordpress.com/2011/09/02/using-groovy-expression-to-set-a-primary-key-with-a-sequence-number/

    Timo
  • 2. Re: How to show the primary key created by sequence before commit?
    BAO.SZ Newbie
    Currently Being Moderated
    Sorry, Timo,
    I just cannot access the link you provide.
    Is there any reference from Oracle doc?

    Thank you.
  • 3. Re: How to show the primary key created by sequence before commit?
    Jeet_A Journeyer
    Currently Being Moderated
    Hi,

    Timo's blog will explain you best declarative way to use Sequence.

    --From blog
    select the EmployeeId(or your Primary Key Id) in the attributes to get to the attributes properties.
    Here we can add a default value as literal, expression or as SQL. We select the ‘Expression’ radio button and click on hte pencel on the right side of the input field.
    Here we enter the Groovy expression to get the next sequence number
    (new oracle.jbo.server.SequenceImpl("<Your Seq>",adf.object.getDBTransaction())).getSequenceNumber() 
    eg.
    (new oracle.jbo.server.SequenceImpl("EMPLOYEES_SEQ",adf.object.getDBTransaction())).getSequenceNumber() 
    If you want to modify EOImpl class you can override create method.
    eg.
        protected void create(AttributeList attributeList) {
            super.create(attributeList);
              SequenceImpl seq = new SequenceImpl("EMPLOYEES_SEQ",getDBTransaction().getRootApplicationModule());
              BigDecimal EmpIdNumber = new BigDecimal(seq.getSequenceNumber().toString());
              setEmployeeId(EmpIdNumber);
           
        }
    Thnaks,
    Jit
  • 4. Re: How to show the primary key created by sequence before commit?
    BAO.SZ Newbie
    Currently Being Moderated
    Hi,Jit,
    It works for me!
    It's so great to have so many warm hearted people ready to help others here (OTN)!

    It's even special for me as I have self-pitied in another post "What degree of productivity can jdev/adf achieve compare to eclipse? "
    ( What degree of productivity can jdev/adf achieve compare to eclipse? )

    In my organization, I'm the only one who has interest in using jdev/adf, but I still think it maybe a right way to do.
    In order to convince and persuade my employees, now I'm doing an experimental project with jdev/adf by learning step by step.

    It's a process full of shit(frustrations) and discoveries,but it has a lot of fun.
    and I'm really moved and grateful when I can get help for almost each of my question within hours here!

    Thank you again Jit,
    Thank you Timo.

    BAO.

    **I cannot access Timo's blog, maby because it's blocked by our country's Great Fire Wall (GFW)

    Edited by: BAO.SZ on 2013-5-14 上午10:05
  • 5. Re: How to show the primary key created by sequence before commit?
    BAO.SZ Newbie
    Currently Being Moderated
    This solution also help me to clear one of my doubt which is described in thread:

    "Why sum field in master VO didnot change when a new row add in detail VO? "
    Why sum field in master VO didnot change when a new row add in detail VO?

    I think maybe an possible cause for the above issue is:
    Because there is another primary key VO2.id which is populated by a database trigger from sequence, when I commit data, the value of VO2.id has created but not showed in page. Then when I begin to edit this newly added row, jdev cannot find VO2.id-- then cannot calculated sum and cannot commit again?

    Now i have tested the above use case again:
    For each of newly inserted row, the PK column was created and showed in page after i press the creatwithpara button, so the calculated field in the master table will be changed accordingly.
  • 6. Re: How to show the primary key created by sequence before commit?
    Jeet_A Journeyer
    Currently Being Moderated
    Hi Bao,

    Good that worked for you. If you want to populate sequence immediately after hitting createInsert you can follow as mentioned in Timo's blog.

    If you want to defer sequence creation till you hit save you can add it in
        protected void doDML(int operation, TransactionEvent e) {
            if(operation == DML_INSERT){
              SequenceImpl seq = new SequenceImpl("EMPLOYEES_SEQ",getDBTransaction().getRootApplicationModule());
              BigDecimal EmpIdNumber = new BigDecimal(seq.getSequenceNumber().toString());
              setEmployeeId(EmpIdNumber);
                     
              }
            
            super.doDML(operation, e);
        }
    Here are few nice ADF Blogs if you face firewall issues.
    https://blogs.oracle.com/shay/entry/new_adf_blogs
    http://andrejusb-samples.blogspot.com/
    Donatas Valys - http://donatas.nicequestion.com
    Eugene Fedorenko - http://adfpractice-fedor.blogspot.com
    Deepak C S - http://deepakcs.blogspot.com
    Timo Hahn - http://tompeez.wordpress.com
    Amr Gawish - http://mdlwr.amr-gawish.com
    Mahmoud A. ElSayed - http://mahmoudoracle.blogspot.com
    Sameh Nassar - http://sameh-nassar.blogspot.com/
    Mohammad Jaber - http://mjabr.wordpress.com/
    Srinivas Jilla - http://learn-adf.blogspot.com/
    Dimitrios Stasinopoulos - http://dstas.blogspot.com/
    Chris Muir - https://blogs.oracle.com/onesizedoesntfitall/
    Eduardo Rodrigues/Fábio Souza - http://java2go.blogspot.com
    https://blogs.oracle.com/aramamoo/
    http://ramannanda.blogspot.com/

    And of course Frank Nimphius Code Corner
    http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html


    Thanks,
    Jit

    Edited by: appsjit on May 14, 2013 1:26 PM
  • 7. Re: How to show the primary key created by sequence before commit?
    BAO.SZ Newbie
    Currently Being Moderated
    Hi, Jit,
    Thank you very much for your recommendations!

    I take a try for these links you provide,
    These links CAN ACCESS:
    https://blogs.oracle.com/shay/entry/new_adf_blogs
    http://mdlwr.amr-gawish.com/
    https://blogs.oracle.com/onesizedoesntfitall/
    https://blogs.oracle.com/aramamoo/
    http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html

    But, these links Cannot access:
    http://andrejusb-samples.blogspot.com/
    http://donatas.nicequestion.com/
    http://adfpractice-fedor.blogspot.com/
    http://deepakcs.blogspot.com/
    http://tompeez.wordpress.com/
    http://mahmoudoracle.blogspot.com/
    http://sameh-nassar.blogspot.com/
    http://mjabr.wordpress.com/
    http://learn-adf.blogspot.com/
    http://dstas.blogspot.com/
    http://java2go.blogspot.com/
    http://ramannanda.blogspot.com/

    I donot know the cause for these links inaccessible, an important posibility is our country's GFW(Great Fire Wall).
    If that is the case, it'll be a really pity and shame for us here. They have spent enough of money, but the GFW not smart enough yet!!
    (http://www.quora.com/Great-Firewall-of-China-GFW/How-is-life-on-the-other-side-of-the-Great-Fire-Wall
    http://www.morningwhistle.com/html/2013/PoliticsSociety_0128/216902.html
    )

    I have another thread in OTN :
    " How to convert CreatewithParams button into a checkbox?"
    Re: How to convert CreatewithParams button into a checkbox?

    and Mr./Ms. Eon van Tonder had given a suggestion link which I cannot access:
    http://rohith-oracle.blogspot.com/search/label/How%20to%20post%20changes%20to%20a%20Database%20using%20ValueChangeListener

    Would you please help me to paste the above links content on this thread:
    Re: How to convert CreatewithParams button into a checkbox?

    Thank you again!
  • 8. Re: How to show the primary key created by sequence before commit?
    Jeet_A Journeyer
    Currently Being Moderated
    Hi,

    Content of
    http://rohith-oracle.blogspot.com/search/label/How%20to%20post%20changes%20to%20a%20Database%20using%20ValueChangeListener

    ADF - How to submit/post values changes to database immediately in ADF UI components

    When you want to persist changes to a database as soon as a user changes the value in any of the UI Components. you can use the below technique.

    1. Add a value change listener to your UI Component and also make Auto Submit to true.

    <af:selectOneChoice value="{row.bindings.reasonCode.inputValue}"
    label="#{row.bindings.reasonCode.label}" id="soc1" autoSubmit="true"
    valueChangeListener="#{failures.reasoncodeChange}">
    <f:selectItems value="#{row.bindings.reasonCode.items}" id="si1"/>
    </af:selectOneChoice>

    2. In the Backing bean value change listener method
    valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
    Calling the the above line will do all the model updates. refer the link
    public void reasoncodeChange(ValueChangeEvent valueChangeEvent) {
    valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());BindingContainer bindings = getBindings();
    OperationBinding operationBinding =bindings.getOperationBinding("Commit");
    operationBinding.execute();
    }



    Thanks

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points