That is the expected behaviour. The line apex.item("P1_ERROR_FLAG").setValue("ERROR");
sets the value of the page item on the client side. Observe the network tab in the browser console - there will not be communication with the server when this happens. The value gets sent to the client in any of the following cases:
The post does not say when this code executes but I would create a dynamic action on change of P1_ERROR_FLAG that has an action of execute serverside code, items to submit set to P1_ERROR_FLAG and code NULL;
. This will submit that page item to the server.
There might be better solutions for your use case but then please provide more info (as much as possible ) about how the page is set up: at what point do you need the P1_ERROR_FLAG value and how is it used ?