I have some weird behaviour in Apex 5.1.
I have created a 3 page items and a button on a page. If I hit the button I want to execute some PL/SQL code passing the page items as parameters. First I want to check if the page items are not empty and otherwise warn the user to enter the values.
In javascript most of this is quite easy. Below I check on two of the page items. If one is missing I show an error, otherwise I display the values in a success message.
apex.message.clearErrors();
if ( $v("P7_SELECTED_MB") == "" ) {
apex.message.showErrors ([
{
type: apex.message.TYPE.ERROR,
location: ["page", "inline"],
pageItem: "P7_SELECTED_MB",
message: "Choose a group first",
unsafe: false
}]
)
} else
{
if ( $v("P7_SELECTED_IO") == "" ) {
apex.message.showErrors ([
{
type: apex.message.TYPE.ERROR,
location: ["page"],
message: "Choose some contracts first.",
unsafe: false
}]
)
}
else
{
apex.message.showPageSuccess( "Page items: MB="+$v("P7_SELECTED_MB")+" PC="+$v("P7_SELECTED_PC")+" IO="+$v("P7_SELECTED_IO") );
}
}


So far so good. In PL/SQL I could do something like this
BEGIN
IF :P7_SELECTED_MB IS NULL
THEN
Raise_Application_Error (-20000,'Pass a group first' );
END IF;
XXGR_OPA_ERRORS_PKG.Log (null,'DEBUG APEX','CreateGroup processing from page ' || :P7_SELECTED_MB || ' - ' || :P7_SELECTED_PC || ' - ' || :P7_SELECTED_IO);
END;
But now I get this

Which is not very useful. I log the variables to the database using my log call and I can see only the first variable has a value. The other 2 are Always empty, even if I select a value. There seems to be something odd referring to the page items in PL/SQL.
I have tested a few combinations to understand what is happening.
1. I make P7_SELECTED_MB empty and hit the button. I have this in PL/SQL
IF :P7_SELECTED_MB IS NULL
THEN
Raise_Application_Error (-20000,'Pass a group first' );
END IF;
But no error is displayed and it stores in the database
CreateGroups processing from page 5-014-16 - -
So it still thinks the page item has a value which is weird right, here you see the three page items. And if I use the javascript with the error message it does see the page item is empty. So why is it not empty for PL/SQL??

The first is a select list. The second as well, the third is entered dynamically from an interactive grid on selection.
2. I enter values for all and hit create.

But only the first value is shown in the database
CreateGroups processing from page 5-014-16 - -
3. Change the condition to
IF :P7_SELECTED_IO IS NULL
THEN
Raise_Application_Error (-20000,'Pass a group first');
END IF;
Now the error message is shown (but inreadable for a user).
So I am sort of desperate and looking for two possible workarounds
1. Call PL/SQL from javascript so my messages are nice and the page items have correct values.
2. Fix whatever I am doing wrong so I can pass the parameters correctly to my PL/SQL dynamic action and display proper error messages.
Can anyone help me with either of these solutions?