Re: FormUtil addendum
Christian Cryder <[email protected]> Fri, 16 Sep 2005 09:50:12 -0400
| Newsgroups | gmane.comp.java.enhydra.barracuda.general |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format...
------------=_1126878668-23388-86
Content-Type: multipart/alternative;
boundary="------------010300050901020002050102"
This is a multi-part message in MIME format.
--------------010300050901020002050102
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Hi Franck, yes it's a good idea. I'm not sure of what we'd need to do
specifically - if you look closely at the code, you will see that it is
also using the FormMap to get information about the data (eg. what type
of data it is does affect how the data is formatted for output - this is
only significant for date, time, and timestamp objects) - so an
alternate implementation would have to find some other way of working
around that - maybe just looking at the data type itself (I'm not sure
here).
Feel free to have a go at a map imlementation - I'd be happy to review
whatever you come up with.
Christian
Franck Routier wrote:
> Hi,
>
> what about adding a new method to FormUtil, similar to
> FormUtil.repopulate(FormMap fm, BComponent bc) but with a slightly
> different signature : FormUtil.repopulate(Map pm, BComponent bc)
>
> pm would be a plain map containing key / value instead of FormElement.
> This would allow to have a generic (re)population, either from
> previously typed in values (from a FormMap), but also initially from a
> plain map (say a value object coming from the business tier).
>
> The code could be as in the file attached.
>
> Any comments on that ? (maybe there is a much better approch ?)
>
> Regards,
>
> Franck
>
>
>
>
>
>
>------------------------------------------------------------------------
>
> /**
> * Given a BComponent and a reference to a FormMap, this method will automatically
> * repopulate the form value into the component. The way it works is fairly simply:
> * you create the appropriate component and name it - the component name will be used
> * to locate the appropriate form element and repopulate the component based on the
> * form element value.
> *
> * @param fm the backing form map
> * @param bcomp the component to be repopulated
> * @since csc_110304_1
> */
> public static void repopulate(Map aMap, BComponent bcomp) {
>
> String key = bcomp.getName();
> if (key==null) return;
> if (aMap == null) return;
>
> Object val = aMap.get(key);
>
> if (bcomp instanceof BToggleButton) {
> ((BToggleButton) bcomp).setSelected(Boolean.TRUE.equals(val));
>
> } else if ((val!=null) && (bcomp instanceof BInput) && (((BInput) bcomp).getValue()==null)) {
> ((BInput) bcomp).setValue(val);
> } else if ((val!=null) && (bcomp instanceof BSelect) && (((BSelect) bcomp).getSelectedIndex()==-1)) {
> ListModel lm = ((BSelect) bcomp).getModel();
> if (lm!=null) {
> for (int i=0, max=lm.getSize(); i<max; i++) {
> Object item = lm.getItemAt(i);
> boolean match = (item instanceof ItemMap && CollectionsUtil.checkEquals(val, ((ItemMap) item).getKey()));
> if (!match) match = (item instanceof ItemMap && CollectionsUtil.checkEquals(val, ((ItemMap) item).getValue()));
> if (!match) match = CollectionsUtil.checkEquals(val, item);
> if (match) {
> ((BSelect) bcomp).setSelectedIndex(i);
> break;
> }
> }
> }
> }
> }
>
>
>------------------------------------------------------------------------
>
>
>--
>Barracuda mailing list
>[email protected]
>http://www.objectweb.org/wws/lists/projects/barracuda
>
>
--
------------------------------------------------------------------------
Christian Cryder
Internet Architect, ATMReports.com <http://atmreports.com>
------------------------------------------------------------------------
/"Coffee? I could quit anytime, just not today"
http://seelifedifferently.blogspot.com/
--------------010300050901020002050102
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Franck, yes it's a good idea. I'm not sure of what we'd need to do
specifically - if you look closely at the code, you will see that it is
also using the FormMap to get information about the data (eg. what type
of data it is does affect how the data is formatted for output - this
is only significant for date, time, and timestamp objects) - so an
alternate implementation would have to find some other way of working
around that - maybe just looking at the data type itself (I'm not sure
here).<br>
<br>
Feel free to have a go at a map imlementation - I'd be happy to review
whatever you come up with.<br>
<br>
Christian<br>
<br>
Franck Routier wrote:
<blockquote cite="[email protected]" type="cite">Hi,
<br>
<br>
what about adding a new method to FormUtil, similar to
FormUtil.repopulate(FormMap fm, BComponent bc) but with a slightly
different signature : FormUtil.repopulate(Map pm, BComponent bc)
<br>
<br>
pm would be a plain map containing key / value instead of FormElement.
This would allow to have a generic (re)population, either from
previously typed in values (from a FormMap), but also initially from a
plain map (say a value object coming from the business tier).
<br>
<br>
The code could be as in the file attached.
<br>
<br>
Any comments on that ? (maybe there is a much better approch ?)
<br>
<br>
Regards,
<br>
<br>
Franck
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<pre wrap="">
<hr size="4" width="90%">
/**
* Given a BComponent and a reference to a FormMap, this method will automatically
* repopulate the form value into the component. The way it works is fairly simply:
* you create the appropriate component and name it - the component name will be used
* to locate the appropriate form element and repopulate the component based on the
* form element value.
*
* @param fm the backing form map
* @param bcomp the component to be repopulated
* @since csc_110304_1
*/
public static void repopulate(Map aMap, BComponent bcomp) {
String key = bcomp.getName();
if (key==null) return;
if (aMap == null) return;
Object val = aMap.get(key);
if (bcomp instanceof BToggleButton) {
((BToggleButton) bcomp).setSelected(Boolean.TRUE.equals(val));
} else if ((val!=null) && (bcomp instanceof BInput) && (((BInput) bcomp).getValue()==null)) {
((BInput) bcomp).setValue(val);
} else if ((val!=null) && (bcomp instanceof BSelect) && (((BSelect) bcomp).getSelectedIndex()==-1)) {
ListModel lm = ((BSelect) bcomp).getModel();
if (lm!=null) {
for (int i=0, max=lm.getSize(); i<max; i++) {
Object item = lm.getItemAt(i);
boolean match = (item instanceof ItemMap && CollectionsUtil.checkEquals(val, ((ItemMap) item).getKey()));
if (!match) match = (item instanceof ItemMap && CollectionsUtil.checkEquals(val, ((ItemMap) item).getValue()));
if (!match) match = CollectionsUtil.checkEquals(val, item);
if (match) {
((BSelect) bcomp).setSelectedIndex(i);
break;
}
}
}
}
}
</pre>
<pre wrap="">
<hr size="4" width="90%">
--
Barracuda mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="http://www.objectweb.org/wws/lists/projects/barracuda">http://www.objectweb.org/wws/lists/projects/barracuda</a>
</pre>
</blockquote>
<br>
<br>
<div class="moz-signature">-- <br>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; ">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Foo bar rama</title>
<table border="0">
<tbody>
<tr>
<td width="100%">
<hr align="left" size="1" width="350"> </td>
</tr>
<tr>
<td width="100%"><font face="Arial">Christian Cryder<br>
Internet Architect, <a href="http://atmreports.com">ATMReports.com</a></font></td>
</tr>
<tr>
<td width="100%">
<hr align="left" size="1" width="350"> </td>
</tr>
<tr>
<td width="100%">
<p align="center"><i>"Coffee? I could quit anytime, just not
today"<br>
<a href="http://seelifedifferently.blogspot.com"><font size="2">http://seelifedifferently.blogspot.com</font></a></i></p>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
--------------010300050901020002050102--
------------=_1126878668-23388-86
Content-Type: text/plain; name="message-footer.txt"
Content-Disposition: inline; filename="message-footer.txt"
Content-Transfer-Encoding: 8bit
--
Barracuda mailing list
[email protected]
http://www.objectweb.org/wws/lists/projects/barracuda
------------=_1126878668-23388-86--