Carl-Eric, A subtle problem with this approach is that you don't have direct access to the embedded control's properties or to its markup.
So for instance you need an extra non-standard way for adding behaviors to the embedded component (e.g. implement an addBehaviorToComponent method to the panel so it's add() remains unchanged in case you need it), or you need to do something like panel.getEmbeddedComponent().add(behavior). Also you cannot subclass the embedded component. Alternatively you can go the ViewOrEdit approach which takes the component as a constructor argument so you have direct access to it and you can also subclass it. However in both cases you don't have access to the component's markup since it's embedded in the FormComponentPanel's markup and you need to rely on AttributeModifiers. Overall this approach is ok but it does make the actual component less reachable. This is why I am considering doing this via a behavior as it changes nothing with respect to the way you treat the component. Marios On Thu, May 30, 2013 at 5:12 PM, Carl-Eric Menzel <[email protected]>wrote: > 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] > >
