How to reproduce :
1) Go to the profile of a party and then to the "Role" tab : https://localhost:8443/partymgr/control/viewroles?partyId=admin
2) Add any role
3) Wait for the page to reload
4) Try to add another role
5) Notice the error showing up and the redirection to the "profile" page
Problem : The problem comes from a bad request send. When you select a "main role" (without clicking on the add button), a request is send to get the form for the "secondary role". On the first time, there is no problem, the request is something such as :
On the second time, it becomes something like this :
When the controller receives this second request, it does both the "addrole" and the "addsecondaryroles" request. So when you chose a role in the first select, it actually sends a request to add the role before you even click on the "add" button.
Root of the problem :
First, the target of the forms (PartyForms#AddPartyRole, PartyForms#AddPartyMainRole and PartyForms#AddPartySecondaryRole) adding the "main" and "secondary" roles is "addrole/viewroles" (it seems to be the only place in the code where a target is done this way). To clear up the request, I tried to remove the "/viewroles" to match what is done in another case : when a task is added to a project.
It seems to work but I want to know what is your point of view on this.
Then, in the controller, there is a weird redirection to "viewprofile" instead of allowing the user to stay on "viewroles". All of this seems related to an update of the coding way in the project that didn't affect this part yet.
I'll provide a patch that seems to work.