Its configured to listen on page scope yes
Have you checked the logs for any errors?
The current page is used by default.
How do I get the pageId of a different page?
The page id is available in the page props. {page.props.pageId}
You would need to send it to the popup as a parameter to be used in the sendMessage()
function.
However, a popup shouldn't change the page, so the current page should be enough to receive the message.
Thats what Im thinking, is it because my message handler is on the button component?
So I have view 'EditProduct'. In that view I have a button with message handler 'deleteProductHandler' with code
def onMessageReceived(self, payload):
# Get the selected row or rows.
selRows = self.getSibling('Table').props.selection.data
# Check to see that a row is actually selected.
if len(selRows) > 0:
txID = system.db.beginTransaction(timeout = 10000)
# If the user gave confirmation, we need to loop through all of them.
for row in selRows:
# For each selected row, we need to get the value of the id column in that row.
id = row["ProductID"]
# Use the id of the row to delete it from the database table.
system.db.runNamedQuery("SampleTestV2","Configurations/DeleteProduct", {"ID":id},tx = txID)
# commit and close transaction
system.db.commitTransaction(txID)
system.db.closeTransaction(txID)
self.getSibling("Status").props.text = "Successfully deleted"
else:
self.getSibling("Status").props.text = "Error: No row(s) selected"
The button has onActionPerformed which opens popup view 'ConfirmationPopup'.
That view has button with code:
messageType = 'deleteProductHandler'
system.perspective.sendMessage(messageType,{})
How do you know it isn't running?
A few things:
- You're not doing anything to verify that the query was successful prior to calling commit on the transaction so do you even need a transaction?
- If you do need a transaction, then you should be using
system.db.beginNamedQueryTransaction()
for use with a Named Query.
I would place a system.perspective.print("message handled")
as the first line in the script, to verify that the message is being sent and received.
I have already tried inserting a print statement on the first line. Nothing prints. I use a transaction, so all the deletes go through before deleting.
I added this
self.get.Sibling('Status').props.text = "TEXT"
So this proves it does not make it to the message handler.
Are you testing this in a browser or in the designer? There are differences that come into play sometimes.
The browser of course.
I even put a button on the same view with code
messageType = 'deleteProductHandler'
system.perspective.sendMessage(messageType,{})
and nothing happened
I figured it out
One sec Ill tell you exactly what it is in a minute
The issue is somewhere in my if statement or condition
For what its worth, I would just use a filtered delete, and forgo the transaction, if you have no intention of rolling it back for any reason it isn't worth the overhead.
It is stopping at TEXT1.1 - It is not running the named query and leaving the loop
def onMessageReceived(self, payload):
self.getSibling('Status').props.text = "TEXT"
# Get the selected row or rows.
selRows = self.getSibling('Table').props.selection.data
# Check to see that a row is actually selected.
if len(selRows) > 0:
# If the user gave confirmation, we need to loop through all of them.
for row in selRows:
self.getSibling('Status').props.text = "TEXT1"
# For each selected row, we need to get the value of the id column in that row.
id = row["ProductID"]
self.getSibling('Status').props.text = "TEXT1.1"
# Use the id of the row to delete it from the database table.
system.db.runNamedQuery("SampleTestV2","Configurations/DeleteProduct", {"ID":id})
self.getSibling('Status').props.text = "TEXT2"
self.getSibling('Status').props.text = "TEXT3"
self.getSibling("Status").props.text = "Successfully deleted"
else:
self.getSibling("Status").props.text = "Error: No row(s) selected"
Named queries must be different in message handlers because if I copy that code on a button it works and successfully deletes???:?
I am assuming that "SampleTestV2" is your project name. Try removing that, in theory you shouldn't need it in this scope.