Monday, October 5, 2009

passing variables in p4a between masks

i had a problem where i wanted to capture a value from a mask after going to another mask while creating a web application using p4a. i found the method on the p4a forum but it wouldnt work sometimes. i could not figure out what was the problem. it would pass the value the very first time the mask is called but it would not capture it once passed again to the same mask. the puzzled me. i then figured out that p4a is a state application and i would need to clear the previous state if i wanted to capture the new value. i had created a function to clear the state, which i posted on my forum some time ago, which i used but that didnt solved the problem. i checked other applications that i built and the method worked perfectly. i realised that the difference between the application that worked and the one that didnt work was the use of menus to open a mask. the menu function i used was one found from the p4a sample appliction. here is the code.

function menuClick(){
$this->openMask($this->active_object->getName());
}

here is how it is used:

$users = $control_panel->addItem('users')
->setLabel('Users')
->implement('onclick', $this, 'menuClick');

to change the state of the mask, i had to add a line to the menuClick function so that it clears it and displays the correct function.

function menuClick(){
$this->getPrevMask()->destroy();
$this->openMask($this->active_object->getName());
}

if a menu is not used to open a mask then when switching between mask you would only have to use one line in the function, $this->destroy();

hope it is understood and can help someone.

No comments: