Selecting a value in a Choices Dropdown calls "GetActionChoices" AJAX method

Nov 29, 2012 at 3:00 PM

Hi,

I am implementing a choices dropdown for an Action method and the list is populating as expected.

However, when I select a value from the Dropdown the GetActionChoices method is being called and the list is repopulated which means that the selection is lost.

Would you have any idea why this might be happening? It does not happen when the Dropdown is populated from a Bounded enum.

Many thanks,

John

Coordinator
Nov 29, 2012 at 3:23 PM

I tested out a simple action with a choices paramter and it worked as expected - so

1. Browser - I tried FF 17 and IE9 - are you using a different browser/version ?

2. Is it a simple dropdown or are there interdependencies between the parameters ?eg

    [MemberOrder(1)]
    public PurchaseOrderDetail AddNewDetail(Product prod, short qty) {
       ...
    }

     
    public List Choices0AddNewDetail(short qty) {
           ...
    }

3. Is there any custom javascript running ?

Nov 29, 2012 at 3:45 PM

Hi,

Thanks for your prompt reply.

The problem is occurring in both IE 9 and Chrome, the only browsers I have checked so far.

It is a simple dropdown, here is the code:

public void AddChild(ICustomer child)
{
    Child = child;
}
        
public IList<ICustomer> ChoicesAddChild(ICustomer child)
{
    return CustomerService.FindRelatedCustomers(this.AssociatedClaim.Claimant.Id).ToList();
 }

There is a bit of custom javascript but it should not conflict with this. Even so, I have removed it for now and the problem is still occurring.

I did a bit of debugging and it is the api.updateChoices method in NakedObjects-Ajax.js which is making the call. I haven't quite figured out the purpose of this method yet.

Thanks,

John

Nov 29, 2012 at 4:24 PM
Hi All. I have also experienced something like this on the client side where the dropdown selection gets reset / repopulated, but I have not looked into it.
I am also using a custom choices method.
Coordinator
Nov 30, 2012 at 7:52 AM

John

Can you just confirm whether you are getting the same behaviour with the alternate syntax for the same function?   i.e.:

 

public void AddChild(ICustomer child)
{
    Child = child;
}
        
public IList<ICustomer> Choices0AddChild()
{
    return CustomerService.FindRelatedCustomers(this.AssociatedClaim.Claimant.Id).ToList();
 }

Richard

Coordinator
Nov 30, 2012 at 8:36 AM
Edited Nov 30, 2012 at 8:38 AM

Thinking further, John, I think that this will solve the issue.  What I think is happening is this:

Your AddChild method has a single parameter of type ICustomer called 'child', but it also happens that the object has a property of type ICustomer called Child  (I can see that from the content of the AddChild method.  I'm guessing that Naked Objects is getting confused by this and interpreting the choices method as being somehow dependent on the Child property.  By switching to the other syntax (which, BTW, is the syntax you would get by default if you used the 'actcho' snippet for 'action choices') this ambiguity should be avoided. 

Please confirm back.  I will raise a (low priorty) ticket to look at this potential ambiguity.  N.B.  If you are using actions to update individual properties a lot then this is going to occur quite often.

Nov 30, 2012 at 10:45 AM
richardpawson wrote:

Thinking further, John, I think that this will solve the issue.  What I think is happening is this:

Your AddChild method has a single parameter of type ICustomer called 'child', but it also happens that the object has a property of type ICustomer called Child  (I can see that from the content of the AddChild method.  I'm guessing that Naked Objects is getting confused by this and interpreting the choices method as being somehow dependent on the Child property.  By switching to the other syntax (which, BTW, is the syntax you would get by default if you used the 'actcho' snippet for 'action choices') this ambiguity should be avoided. 

Please confirm back.  I will raise a (low priorty) ticket to look at this potential ambiguity.  N.B.  If you are using actions to update individual properties a lot then this is going to occur quite often.

Hi Richard,

I changed the syntax as you suggested and it is working correctly now.

Thank you!

John