0

For example the delete-link was clicked twice or from different users. While the first click will correctly remove my object the second one will fail (as it is outdated) before my deleteAction is Called. How can I prevent this?

/**
 * action delete
 *
 * @param $upload
 * @dontvalidate $upload
 * @return void
 */
public function deleteAction(Tx_MyExt_Domain_Model_Upload $upload) {
    $this->uploadRepository->remove($upload);
    $this->flashMessageContainer->add('Your Upload was removed.');
    $this->redirect('list');
}

I get an Exception:

The value must be of type "Tx_MyExt_Domain_Model_Download", but was of type "NULL".

Doing something inside the action doesn't help, because it fails before…

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
AdON
  • 33
  • 1
  • 7

1 Answers1

0

I'm assuming you have some fluid markup that looks like:

<f:link.action action="delete" arguments="{upload:uploadObjectToDelete}" > ... 

Which says: pass the uploadObjectToDelete object to the delete action when the user clicks on this link. And when the user clicks on that link the ExtBase PropertyMapper uses the arguments sent with the link to locate the uploadObjectToDelete in the database to hand it off to your controller and the delete action.

After the first click, that delete action successfully deletes the object from the database and the page is reloaded when you redirect to the list action. However, this time the uploadObjectToDelete object is null. So, for the second click, when the PropertyMapper tries to locate an upload argument for the delete action there is no object to look for. And since the upload argument is required (i.e. can't be null), you get an exception.

Option 1

Change your list action so that it doesn't show these links when the uploadObjectToDelete object is null. This is probably the best option.

<f:if condition="uploadObjectToDelete">
    <f:link.action action="delete" arguments="{upload:uploadObjectToDelete}" > ... 
</f:if>

Option 2

Change your delete action to accept null arguments:

public function deleteAction(Tx_MyExt_Domain_Model_Upload $upload = null) { ...

But this option doesn't make sense. Why would you allow your user to try and delete an object that is already null?

These are just suggestions.

peter
  • 6,067
  • 2
  • 33
  • 44
  • Ahh, great, option 2 did the trick for me. The problem could occur, when a user had an outdated page open, for example a different tab. The user destroyed the object successfully in one tab, but the other tab still had the delete-link. And I just didn't want to get an exception in the frontend at this point. Thanks a lot! – AdON Aug 31 '12 at 21:17