|
From: Jan H. <jh...@sc...> - 2008-01-29 07:46:40
|
That should be possible as well.
Most bindings have a specific required type, in this case a String. If
you bind a property to such a binding, then it requests a valueModel
with a specific type on the formModel. If the source valueModel (meaning
the first one wrapping the property) has a different type it will ask
the conversion service for a suitable converter to create a converting
valueModel from the source type to the required type and vice versa. So
creating converters in both directions and registering them should do
the trick. Take a look at the DefaultConversionServiceFactoryBean for
more information. There are a few converters registered there that you
can take as a reference.
Kind Regards,
Jan
On Mon, 2008-01-28 at 23:22 +0200, Rogan Dawes wrote:
> Arne Limburg wrote:
> > Hi Rogan,
> >
> > you need to extend AsYouTypeTextComponentAdapter and override
> > adaptedValueChanged with something like this:
> > protected void adaptedValueChanged(Object newValue) {
> > super.adaptedValueChanged(((String)newValue).getBytes());
> > }
> >
> > You also have to reimplement TextComponentBinding to use your Adapter
> > and to set the bytes, i.e. you have to change line 41 like this:
> > textComponent.setText(new
> > String((byte[])valueModel.getValue()));
> >
> > and implement an appropriate Binder (take a look at TextAreaBinder).
> > <http://dict.leo.org/ende?lp=ende&p=eL4jU.&search=appropriate>Of course,
> > if you need you have to handle encoding-specific conversions at the
> > places above.
> >
> > Regards,
> >
> > Arne
>
> I was looking at TextComponentBinding.java, and noted the Exception
> handling:
>
> protected JComponent doBindControl() {
> final ValueModel valueModel = getValueModel();
> try {
> textComponent.setText((String) valueModel.getValue());
> }
> catch (ClassCastException e) {
> IllegalArgumentException ex = new
> IllegalArgumentException("Class cast exception converting '"
> + getProperty() + "' property value to string - did you
> install a type converter?");
> ex.initCause(e);
> throw ex;
> }
> // TODO: implement ValueCommitPolicies
> new AsYouTypeTextComponentAdapter(textComponent, valueModel);
> return textComponent;
> }
>
> Would it not be sufficient to make an appropriate type converter?
>
> Rogan
>
> >
> > Rogan Dawes schrieb:
> >> Hi folks,
> >>
> >> I'd like to represent a byte[] field as a String in a JTextArea.
> >>
> >> Can anyone explain how to create such a Binder/Binding?
> >>
> >> Thanks
> >>
> >> Rogan
> >>
> >> -------------------------------------------------------------------------
> >> This SF.net email is sponsored by: Microsoft
> >> Defy all challenges. Microsoft(R) Visual Studio 2008.
> >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> >> _______________________________________________
> >> Springframework-rcp-dev mailing list
> >> Spr...@li...
> >> https://lists.sourceforge.net/lists/listinfo/springframework-rcp-dev
> >>
> >>
> >
> >
> > -------------------------------------------------------------------------
> > This SF.net email is sponsored by: Microsoft
> > Defy all challenges. Microsoft(R) Visual Studio 2008.
> > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> > _______________________________________________
> > Springframework-rcp-dev mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-rcp-dev
> >
> >
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Springframework-rcp-dev mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-rcp-dev
**** DISCLAIMER ****
http://www.schaubroeck.be/maildisclaimer.htm
|