get Client side Control's value on the Server side

Hi,

I have a client side control Drop Down menu. It’s value is set by a variable in the beforeRenderResponse() service.

My requirement is that

  • When user selects any value from that drop down, I want to get the value of that control in the server side function executed by Async command.

I have added client side selection change listener for the Drop down and that executes my async command.

I have tried many ways to get the value of the control on the server side, but I have failed.

I like to know the syntex to get value of client control on server side.

Thanks,
Jaimin Patel

There are two very easy ways of doing this, neither of which require any javascript or client side coding.

Method one: Member variable
This is the most straight forward technique where you add a member variable to the PageBean and in your Command Handler access the variable directly.

To use this technique:

  1. Add a member variable to your Page Bean and a public getter/setter
  2. Bind the Value property of the Drop Down control to the member variable.

Method two: Control Accessor
This method removes the need for creating a member variable, but you need to cast the result of a method call to your data type.

To use this technique:

  1. In the CAF Page Editor, right click on the Drop Down Control and choose Source → Create Control Accessor. This will create a new java method.
  2. In your Command Handler function, call the getter that was created in step one and call getValue()

Please see the attached project for a demonstration of both techniques.
Regards,
–mark
DropDownValue.zip (11.8 KB)

1 Like

Hi Mark,

Which approach would you follow? Could you please explain why?

Thanks,
Bruno