Databases Reference
In-Depth Information
8.
Because there will be no False action, accept the defaults on this page, and click
Next
.
9.
Set
Selection Type
to
Triggering Element
, and click
Create Dynamic Action
.
Now, when page 2 is run, any text entered in the Created By field is made uppercase when the user exits the field.
Not
■
Dynamic actions that use sQL or pL/sQL for their conditions or body actually make a call back to the database
server to run the code in question. Depending on the weight and complexity of the code, this could potentially introduce
performance issues. save the use of sQL and pL/sQL for actions that require interaction with the database to retrieve
data that isn't available from directly within the page.
Dynamic Actions Using JavaScript
In addition to PL/SQL, you can use JavaScript in dynamic actions. In this exercise, you use JavaScript to determine the
onscreen status of a ticket that you're editing on page 210. If the user has set the status to CLOSED, the dynamic action
will automatically set the Closed On date to today's date:
1.
Edit
Page 210
of the application.
2.
Create a new dynamic action by right-clicking the
Dynamic Actions
node in the
Page
Rendering
tree and selecting
Create
from the context menu.
3.
Enter
AutoFill Closed_On Date
for
Name
, and click
Next
.
4.
Make sure
Event
is set to
Change
, set
Selection Type
to
Item(s)
, and enter
P210_STATUS_ID
for
Item(s).
5.
Set
Condition
to
JavaScript expression
.
6.
Locate and open the file
ch16_javascript.txt
. This file can be found where you unzipped
the files associated with this topic.
Examine the JavaScript string that is being used as the body of the condition. This may seem very cryptic at first,
but when it's broken down, it's quite straightforward. Let's look at it in pieces:
this.triggeringElement.options[this.triggeringElement.selectedIndex].text == 'CLOSED'
The keyword
this
references the JavaScript event that kicked off the chain of events to start with, and
triggeringElement
references the item on the page that was at the root of the event. So in this case,
this.triggeringElement
is talking about
P210_STATUS_ID
.
Here's where a little developer knowledge has to be introduced. Being the developer, you know that
P210_STATUS_ID
is a select list, and that a select list has from 1 to many values the user can select. In HTML, these
values are called
options
.
Because of the way you've declaratively defined the
P210_STATUS_ID
select list, only one option can be
selected at a time. You can access the option that is currently selected on the page by using the JavaScript
this.triggeringElement.selectedIndex
. The square brackets use that index to reference the selected option from
the
P210_STATUS_ID
select list.
Although you could reference the
value
of the selected option, that would only give you the ID of the selected
status. You'd then have to make a round trip to the database to find out the text status. Instead, you can use the
.text
JavaScript method to get the text that the select list is displaying to the end user and see what they selected.