Forum Stats

  • 3,838,112 Users
  • 2,262,333 Discussions
  • 7,900,511 Comments

Discussions

APEX doesn't check item value until you submit the page???

Alter Boy
Alter Boy Member Posts: 65
edited Aug 22, 2018 12:44PM in APEX Discussions

I've been getting really annoyed with the way APEX checks its item's value only after you've submitted the page. I've been doing workarounds that have taken way too much work and now I can't even do a workaround in this situation. Is there a way to get a page item's value without submitting the page first? What I mean is like if I have a page with just a text field and a Submit button, I want to put "Hello" in that field and click Submit. I then have a dynamic action on Submit that onClick performs a PLSQL insert into expression that inserts the value of that field into a table I want. However, the value is ALWAYS null no matter what I do. How do I fix this or is APEX just that barebone?

Tagged:
Scott WesleyTurntableZ

Best Answer

  • ApexMeister
    ApexMeister Member Posts: 766 Bronze Badge
    edited Aug 14, 2018 3:38PM Answer ✓

    1. Create a DA when change item

    2. Create pl/sql code action, you can just call the pl/sql code directly and add the item names on items to submit and if you change an item value just put it on items to return.

    pastedImage_0.png

    I think its better if you start this way and afterwards learn how to create javascript code.

    JS takes a little bit more time but faster.

    Scott WesleyTurntableZ

Answers

  • ApexMeister
    ApexMeister Member Posts: 766 Bronze Badge
    edited Aug 14, 2018 2:45PM

    apex is stateless framework so you have to aware of page and session state.

    If you want to get the value of an item without submitting you have to use javascript or pl/sql DAs.

    In JS $v('item_name') would give you the value or $s() if you want to set the value.

    Also from JS you can easily call pl/sql and pass that value or you can submit specific page items so pl/sql can see it.

    In pl/sql you can use v('item_name') once you submitted in JS (not page submit).

    You can also submit an item by creating pl/sql DA with null; code and under page items to submit just list all the items you want though the JS is faster.

  • Alter Boy
    Alter Boy Member Posts: 65
    edited Aug 14, 2018 2:56PM

    "In pl/sql you can use v('item_name') once you submitted in JS (not page submit)."

    What do you mean submit in JS? How would I do that? (item name is P101_ITEM)

  • ApexMeister
    ApexMeister Member Posts: 766 Bronze Badge
    edited Aug 14, 2018 3:38PM Answer ✓

    1. Create a DA when change item

    2. Create pl/sql code action, you can just call the pl/sql code directly and add the item names on items to submit and if you change an item value just put it on items to return.

    pastedImage_0.png

    I think its better if you start this way and afterwards learn how to create javascript code.

    JS takes a little bit more time but faster.

    Scott WesleyTurntableZ
  • Pavel_p
    Pavel_p Member Posts: 2,314 Gold Trophy
    edited Aug 15, 2018 5:37AM

    Hi,

    I'm not sure if "getting really annoyed" is the right way how to get familiar with the basics of some tool/framework you're not familiar with (no matter if APEX or anything else). No offense but probably you're doing workarounds on workarounds just because you don't know how to do things right and the tool you're working with is not to blame.

    So the basics in a nutshell (and I'm sorry if these are already obvious).

    There is a server-side (Oracle DB with SQL and PL/SQL) and the client-side (browser with html, css, JavaScript...). You can often read that APEX is stateless which actually means that there is no connection between the server and the client when the page is loaded and the server knows absolutely nothing about the client and vice versa. So if you change your item's value in the browser client-side, the server has no idea about this change and similarly if some server-side process changes the session state/value of some item, the client does not know anything about this change. In order to let server know about some client-side change it's necessary to submit either the entire page (all items on page are submitted at once) or in case of Dynamic Action (DA) that is supposed to be executed server-side (Execute PL/SQL Code) you can specify Item(s) to submit and item(s) to return.

    Let's say you have 2 page items P1_X (value entered by user) and P1_Y and you want to perform a simple calculation on the server like add 1 to value that is in P1_X and show the result in P1_Y. Such PL/SQL DA would be

    :p1_y := :p1_x + 1;

    Since P1_X has changed on the client and it's used in the calculation (and the server knows absolutely nothing about this change), we need to specify this item as Item(s) to submit (send its current client-side value to the server). Then we change value of P1_Y item server-side and the client would know absolutely nothing about this change, so it's necessary to specify it as Item(s) to return (send current sever-side value back to the browser).

    How do I fix this or is APEX just that barebone?

    My bet is that to specify the item name (field) you fill Hello into as Item(s) to submit should do the trick, however your description is not that clear and I may be wrong.

    APEX is a full-featured RAD framework with its pros and cons (like anything else) and if it's missing some specific feature you desperately need, it's possible to extend it with (either community or your own) plugins. It natively offers most (if not all) the tools and mechanisms needed for development of database-driven applications, so it's quite courageous to proclaim that it's barebone.

    Regards,

    Pavel

    Scott Wesley
This discussion has been closed.