Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 48568 invoked from network); 23 Jun 2005 20:46:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 23 Jun 2005 20:46:42 -0000 Received: (qmail 38821 invoked by uid 500); 23 Jun 2005 20:46:40 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 38620 invoked by uid 500); 23 Jun 2005 20:46:39 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@cocoon.apache.org List-Id: Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 38606 invoked by uid 99); 23 Jun 2005 20:46:39 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Jun 2005 13:46:39 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [207.162.210.50] (HELO wrinkledog.com) (207.162.210.50) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 23 Jun 2005 13:46:39 -0700 Received: (qmail 24000 invoked by uid 0); 23 Jun 2005 20:46:35 -0000 Received: from unknown (HELO ?192.168.0.3?) (ml@67.171.172.83) by wrinkledog.com with SMTP; 23 Jun 2005 20:46:35 -0000 Mime-Version: 1.0 (Apple Message framework v622) In-Reply-To: <42B92C96.4080309@apache.org> References: <42B7B6CF.8040701@apache.org> <21a822398d88ce3b949150b1084c1b93@wrinkledog.com> <42B92C96.4080309@apache.org> Content-Type: multipart/mixed; boundary=Apple-Mail-9--481528772 Message-Id: From: Mark Lundquist Subject: Re: [CForms binding] access to model data from repeater row widget Date: Thu, 23 Jun 2005 13:46:31 -0700 To: dev@cocoon.apache.org X-Mailer: Apple Mail (2.622) X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --Apple-Mail-9--481528772 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=WINDOWS-1252; format=flowed Hi Sylvain, thx for your reply... > .... >> However... >> >>>> I realized that I have a nomenclature clash with my choice=20= >>>> of >>>> the name "model". I've been using the v2 API for a long=20 >>>> time, >>>> so I forgot in v1, there is a Form.model property that=20 >>>> denotes >>>> the widget value tree. >>> >>> The "model" property is only available on the toplevel form JS >>> object, so there may not be a clash. >> >> It's not a hard "name clash", but it is a nomenclature clash in that=20= >> it's a different sense of the term "model". My new row "model"=20 >> property is truly the "model", as in "MVC" or as in=20 >> "loadFormFromModel()". The v1 "model" is "model" in terms of=20 >> "formmodel", I guess. I just think it's too confusing to have both=20 >> senses. I actually sort of wish the v1 "model" were called something=20= >> else, because it isn't the model /a la/ MVC. > > You're right. The "form.model" is actually the value tree. Maybe form.model should be renamed to "form.value"! Then you would=20 have these two expressions that mean the same thing (just as they look=20= like they should! :-): form.value.foobar and form.lookupWidget('foobar').value , right? :-) But for now in my working version of the code I settled on "rowModel"=20 to expose the row model object in Flowscript and JXT. Now then, the following exchange has me totally confused: >>> It doesn't seem good to me to provide at the API level a way to >>> link the form to the data model, >> >> No, no, it /is/ good... :-) >> [ ...my rambling snipped...] >> >>> However, there are some uses cases where this makes sense. You=20= >>> can >>> then use widget attributes (see get/setAttribute) to attach some >>> application data of your liking to any widget, including = repeater >>> rows. >> >> See, that's the problem, this is what I have to deal with currently=20= >> :-)... I have two parallel structures: a Collection, and a Repeater.=20= >> If the Repeater does not give me a "view" to its collection, then I=20= >> have to do some kind of iteration to create associations somewhere=20 >> between the repeater rows and the collection elements, and this just=20= >> feels silly and wasteful. I've done it this way, decorating the=20 >> repeater rows with handles to the model data, and I just think that=20= >> since the binding layer is already iterating across the collection,=20= >> it should do this decoration for me! :-). > > Yes. That's the idea behind the "bound repeater binding" idea Reinhard=20= > pointed to. Right. Which was your idea, and which I think I have gone and=20 implemented before I knew that somebody else had thought of it :-)... =20= Or have I not? Maybe I am misunderstanding Reinhard's reference and it=20= isn't really the same thing... or maybe you are misunderstanding me,=20 and thinking it's not the same thing, but it really _is_? :-) Are you saying, "Ah yes, you're right... I thought of this before, and=20= now I remember why it _is_ a good idea (+1! :-)" ? Or =97 are you saying "Ah, it looks like I did think of this too once,=20= but now on second thought I'm not so sure it was a good idea" ? >> I could live with there being a "callback" facility in the repeater=20= >> binding language, e.g. within ... know=20 >> what I mean? But that's sort of beyond my ability to implement, and I=20= >> was looking for something that I could actually do :-) > > Extending the repeater binding to keep the connection to the data=20 > model may be easier, no? Well, it certainly was awfully easy :-) Tell you what, the change is=20 so ridiculously small, I'll just attach the diffs (they are against=20 src/blocks/forms/java/org/apache/cocoon/forms) and you can see if we're=20= talking about the same thing. At first this amounted to about 6 lines=20= of code added, before I added the convenience flowscript function (that=20= I had mentioned in the original post that I wanted to add... this=20 doubled :-) the size of the mod). BTW, this function =97 = 'getRowModel()'=20 =97 I only added it in v2 ('cuz that's what I'm using! :-). When I=20 looked at v1's ScriptableWidget, I hesitated when I saw that there are=20= so few javascript functions defined there, and I wasn't sure if this is=20= really the right idiom for v1... Care to comment? Cheers, =97ml=97 --Apple-Mail-9--481528772 Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0644; name="rowModel.diff" Content-Disposition: attachment; filename=rowModel.diff Index: formmodel/Repeater.java =================================================================== --- formmodel/Repeater.java (revision 594) +++ formmodel/Repeater.java (working copy) @@ -311,6 +311,11 @@ public class RepeaterRow extends AbstractContainerWidget { + private Object model; + + public Object getModel() { return model; } + public void setModel (Object model) { this.model = model; }; + public RepeaterRow(RepeaterDefinition definition) { super(definition); setParent(Repeater.this); Index: generation/template.jx =================================================================== --- generation/template.jx (revision 594) +++ generation/template.jx (working copy) @@ -63,6 +63,7 @@ + Index: flow/javascript/v2/ScriptableWidget.java =================================================================== --- flow/javascript/v2/ScriptableWidget.java (revision 594) +++ flow/javascript/v2/ScriptableWidget.java (working copy) @@ -682,6 +682,18 @@ } } + public Object jsFunction_getRowModel() + throws JavaScriptException + { + if (delegate instanceof Repeater.RepeaterRow) { + return ((Repeater.RepeaterRow) delegate).getModel(); + } else { + throw new JavaScriptException ( + "expected a Repeater.RepeaterRow instead of " + delegate + ); + } + } + static final Object[] WIDGET_CLASS_MAP = { Form.class, "Form", Field.class, "Field", Index: binding/RepeaterJXPathBinding.java =================================================================== --- binding/RepeaterJXPathBinding.java (revision 594) +++ binding/RepeaterJXPathBinding.java (working copy) @@ -121,6 +121,7 @@ // make a jxpath ObjectModelSubcontext on the iterated element Pointer jxp = (Pointer)rowPointers.next(); JXPathContext rowContext = repeaterContext.getRelativeContext(jxp); + thisRow.setModel (rowContext.getValue (".")); // hand it over to children this.identityBinding.loadFormFromModel(thisRow, rowContext); this.rowBinding.loadFormFromModel(thisRow, rowContext); --Apple-Mail-9--481528772--