Hi all,

I have what seems a rather common requirement: to be able to switch form
components to read-only mode on and off in ajax updates.

The simple and clear solutions is to use the enabled property, but this
results in ugly disabled controls in the browser. And you can't really
handle this via css consistently last I ckecked.

I would much prefer a solution where disabled controls are rendered as read
only textboxes (let's disregard checkboxes and radiobuttons for a moment).
Again the obvious solution is to add an extra TextField for each component
and toggle the paired components' visibility on and off. But this results
in a lot of unnecessary/boilerplate code in both the code and the markup
files.

Or you can use Panels that wrap FormComponents like ViewOrEdit does, but
again this adds verbosity to the form code.

So is there any beautiful solution to this problem? What do people do?

I have considered using a BorderBehavior or an AbstractTransformerBehavior
to add the html markup to render a read only input control for disabled
components and also hide the original component by wrapping it in a span
with visibility:hidden style. BorderBehavior needs some modifications to
work with ajax (implement IAjaxRegionMarkupIdProvider) and to use
dynamically generated markup (to conditionally do nothing or add the extra
markup to show the description of the component's value) but it seems it
can be done. This seems like a rather pretty solution as it requires no
extra markup, and does not mess with the java code (you simply need to add
the behavior to the components).

Any feedback would be greatly appreciated.
Marios

Reply via email to