This is exactly where I'd use a custom component. Basically like you
said something with both a Label (that you can make pretty with CSS)
and a TextField (for when it's enabled) - yes, it adds a little
verbosity, but if you put that in custom reusable component (subclass
FormComponentPanel to do that), you have that only once and then can
cleanly use that everywhere else.

Carl-Eric

On Thu, 30 May 2013 16:29:56 +0300
Marios Skounakis <[email protected]> wrote:

> 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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to