Wednesday, February 2, 2011

Client side vs. server side on Visualforce

What I needed to do was to disable a drop down box based on the selection in another drop down. Fairly common requirement. The controller drop down starts as disabled, so I set disabled property in , and used JavaScript from onchange to toggle disabled in HTML DOM from the controlling drop down. All sounded fine and dandy and the UI worked as it should, until I realized that the form never returned anything from the controlled drop down no matter what its status was.

It looks like the client side JavaScript did nothing to enable the controlled element. As far as the server was concerned, it's a field it can discard. I didn't do any HTML/JS debugging to confirm that, but it certainly felt that way. Once I switched the controlling mechanism to server-side processing/AJAX, it started to work as intended.

The only drawback with the AJAX way was that it's a bit slower. Action from the client-side Javascript was instant. With AJAX and its server round trip, it took about one second for the controlled drop down to change status.

No comments:

Post a Comment