You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Dev at weitling <de...@weitling.net> on 2007/05/06 15:51:01 UTC

Further information needed on cform binding

Hi folks,

I want to reach the higher level of cform binding zen, but can't find
enough information.
The questions bothering me are at least:
- What does e.g. <fb:value id="id" path="@id"/> mean? Does it make any
sense in Java-binding?
- The path attribute always maps to a member or a get/set-style method
of a bean. What if I have a method name in other style e.g. list() or
iterator()? What if I have a method which needs an argument?
- Imagine I have an object containing three lists: The first holds
information which key items are displayed and in which order. The others
have data handled by two repeaters which should display according to the
order of their keys in the first list. I have a knot in my brain till now...
- How to do it when I have a HashMap (key -> data) and I want to display
the keys as well as their data?

Any help is greatly appreciated!
Florian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Further information needed on cform binding

Posted by Marc Portier <mp...@outerthought.org>.

Dev at weitling wrote:
> Hi folks,
> 
> I want to reach the higher level of cform binding zen, but can't find
> enough information.
> The questions bothering me are at least:
> - What does e.g. <fb:value id="id" path="@id"/> mean? Does it make any
> sense in Java-binding?

Java binding?

the cforms 'binding' actually is just an XML shorthand to express how
the widget-structure or form-model (see form-definition) maps onto the
actuall business-model (java objects or xml files)


> - The path attribute always maps to a member or a get/set-style method
> of a bean. What if I have a method name in other style e.g. list() or
> iterator()? What if I have a method which needs an argument?

in case of collections on the business side, then you probably will end
up with some kind of repeater inside your form, you could use the
fb:repeater to express the mapping between them

in more general terms, you can use the fb:java or fb:javascript to
express more freely how certain sub-contexts should be mapped

and if that is not enough: you can not use binding and just manually
transfer between form-widgets and back-end API calls

(note that the binding is intended as a _shorthand_ for such back-end
mapping: as soon as it stops being shorter, you _should_ switch to
something else!)

> - Imagine I have an object containing three lists: The first holds
> information which key items are displayed and in which order. The others
> have data handled by two repeaters which should display according to the
> order of their keys in the first list. I have a knot in my brain till now...
> - How to do it when I have a HashMap (key -> data) and I want to display
> the keys as well as their data?

dunno by heart, but from memory I would guess the fb:repeater's nested
fb:identity should be used to map the key

see
http://cocoon.zones.apache.org/daisy/cdocs/g1/g2/g7/forms/binding/488.html

have you checked the binding samples?  none of them have something on
hashmaps?

regards,
-marc=

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Further information needed on cform binding

Posted by Dev at weitling <de...@weitling.net>.
> I think that I understand your case but I don't know where is the
> problem. It's quite complicated situation for binding and runtime of a
> form but CForms are able to manage it, surely.

I'm sure about CForms being able to handle it, but not sure about me ;-)

> I guess that you will need to write your own binding or on-change
> handlers (or both) but they will not be much troublesome.

Yes, but I want to keep it as clean as possible.

> First, you must realize that you are dealing with
> semi-three-dimensional table. One dimension is number of languages,
> second is number of question-anwsers sets and third is number of
> answers. Since rendering three-dimensional tables is rather tricky you
> will need... five repeaters ;-)

Hah! I'm here with three repeaters. And it's not just a table but a tree
structure with connections between its nodes and leafs...

> QL must be simple repeater with on-change handler that updates
> questions and answers repeaters according to the changes performed on
> QL by user. Next, you will need question+answers repeater that holds
> as row pair of question and answers. Question is just simple repeater
> that have a row for each language (rendered as column, though).
> Answers is repeater that have a row for each answer. Answer, similarly
> to the question, is repeater that holds answer for each language.

My project is about multiple choice questions. For that there's a lot of
answers (which may be false) and localized text for the question and the
answers.
My code till now is as follows:

class Question {
  int id;
  Collection questionDatas, questionLocales, answers;
}
class QuestionData {
  int questionID, questionLocaleID;
  String data; // the text
}
class QuestionLocale {
  int id, questionID;
  String locale;
  Collection answerDatas;
}
class Answers {
  int id, questionID;
  Collection answerDatas;
}
class AnswerData {
  int answerID, questionLocaleID;
  String data; // the text
}

    <fb:repeater id="questionLocaleRepeater" parent-path="."
row-path="questionLocales">
        <fb:identity>
            <fb:value id="questionLocale" path="locale"/>
        </fb:identity>
       
        <fb:on-bind>
            <fb:value id="questionData" path="questionData/data"/>
        </fb:on-bind>
    </fb:repeater>
   
    <fb:repeater id="answerRepeater" parent-path="." row-path="answers">
        <fb:identity>
            <fb:value id="answerID" path="id"/>
        </fb:identity>
       
        <fb:on-bind>
            <fb:value id="answerCorrect" path="correct"/>               
               

            <!--
                now here's the point: I want to access and compare the
id of the answers/id with questionLocales/answerDatas/answerID
                but switching the path means cutting the branch I'm
sitting on. If I only could use a kind of variable holding the current id
                the answerRepeater...
             -->
            <fb:repeater id="localeAnswerRepeater" parent-path="."
row-path="/questionLocales/answerDatas[./answerID=/answers/id]">
                <fb:on-bind>
                    <fb:value id="answerData" path="data"/>
                </fb:on-bind>
            </fb:repeater>
        </fb:on-bind>
           
    </fb:repeater>

> Yeah, rendering five repeaters in HTML nicely will demand some of your
> own rendering by is doable. Hope that this helps a little. If not,
> explain what is exact problem, please.

Sorry, if I complicate it too much. Tomorrow is a new day!

Bye and thanks,
Florian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Further information needed on cform binding

Posted by Grzegorz Kossakowski <gk...@apache.org>.
Dev at weitling napisaƂ(a):
> 
> No, sorry, it's a bit difficult to explain. The web site shall contain a
> table like structure. From left to right the columns represent different
> languages. From top to bottom there's first a row containing a question
> followed by one or more answers. If the user removes/adds/reorders the
> languages this should be done for the questions as well as for the
> answers, meaning the language order of the question list has to be the
> same as that of the answers (which are - to make it worse - put it a
> nested list, too).
> The simplified structure:
> question object (Q) containing
> - a list of question languages (QL)
> - a list of localized question texts (QD)
> - a list of answer objects (A) containing each
>     - a list of localized answer texts (AD)

I think that I understand your case but I don't know where is the problem. It's quite complicated situation for binding 
and runtime of a form but CForms are able to manage it, surely.

I guess that you will need to write your own binding or on-change handlers (or both) but they will not be much troublesome.

First, you must realize that you are dealing with semi-three-dimensional table. One dimension is number of languages, 
second is number of question-anwsers sets and third is number of answers. Since rendering three-dimensional tables is 
rather tricky you will need... five repeaters ;-)
QL must be simple repeater with on-change handler that updates questions and answers repeaters according to the changes 
performed on QL by user. Next, you will need question+answers repeater that holds as row pair of question and answers. 
Question is just simple repeater that have a row for each language (rendered as column, though). Answers is repeater 
that have a row for each answer. Answer, similarly to the question, is repeater that holds answer for each language.

Yeah, rendering five repeaters in HTML nicely will demand some of your own rendering by is doable. Hope that this helps 
a little. If not, explain what is exact problem, please.

>>> - How to do it when I have a HashMap (key -> data) and I want to display
>>> the keys as well as their data?
>> Can you give more details... doesn't the binding already have to know
>> the key to get at the value?
> 
> Besides Cocoon & Co. I can let me show the list of keys and after look
> up with ech key its value.

You should use @name (or child:name) path for accessing key and "." for accessing value as explained here:
http://jakarta.apache.org/commons/jxpath/users-guide.html#Map_Element_Access


-- 
Grzegorz Kossakowski

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Further information needed on cform binding

Posted by Dev at weitling <de...@weitling.net>.
Hi Jason,

working sundays, too ;-)

>> I want to reach the higher level of cform binding zen, but can't find
>> enough information.
>> The questions bothering me are at least:
>> - What does e.g. <fb:value id="id" path="@id"/> mean? Does it make any
>> sense in Java-binding?
>
> I believe that in Java binding, path="id" and path="@id" are equivalent.
>
> You can find a lot of information about the details of how the binding
> works from the documentation on the JXPath site:
> http://jakarta.apache.org/commons/jxpath/ -- JXPath is what interprets
> the path attribute to traverse whatever object you're binding to/from,
> so understanding how JXPath works will help you understand the binding
> framework.

Thanks, I will have a look at it after this posting.

>> - Imagine I have an object containing three lists: The first holds
>> information which key items are displayed and in which order. The others
>> have data handled by two repeaters which should display according to the
>> order of their keys in the first list. I have a knot in my brain till
>> now...
>
> It sounds to me like you actually want to have your form definition
> and binding XML be dynamically generated using the first list; then
> when the binding is executed it doesn't have to do anything special
> since the repeater widgets already line up with the keys.

No, sorry, it's a bit difficult to explain. The web site shall contain a
table like structure. From left to right the columns represent different
languages. From top to bottom there's first a row containing a question
followed by one or more answers. If the user removes/adds/reorders the
languages this should be done for the questions as well as for the
answers, meaning the language order of the question list has to be the
same as that of the answers (which are - to make it worse - put it a
nested list, too).
The simplified structure:
question object (Q) containing
- a list of question languages (QL)
- a list of localized question texts (QD)
- a list of answer objects (A) containing each
    - a list of localized answer texts (AD)

>> - How to do it when I have a HashMap (key -> data) and I want to display
>> the keys as well as their data?
> Can you give more details... doesn't the binding already have to know
> the key to get at the value?

Besides Cocoon & Co. I can let me show the list of keys and after look
up with ech key its value.

Let me know if I should be more precise.

Thanks and greetings,
Florian



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Further information needed on cform binding

Posted by Marc Portier <mp...@outerthought.org>.

Jason Johnston wrote:
> Marc Portier wrote:
>>
>> Jason Johnston wrote:
>>> Dev at weitling wrote:
>>>> Hi folks,
>>>>
>>>> I want to reach the higher level of cform binding zen, but can't find
>>>> enough information.
>>>> The questions bothering me are at least:
>>>> - What does e.g. <fb:value id="id" path="@id"/> mean? Does it make any
>>>> sense in Java-binding?
>>>
>>> I believe that in Java binding, path="id" and path="@id" are equivalent.
>>>
>>
>> they are not
>>
>> the id attribute points to the id of the widget in the form_model
>> the path attribute points to the structure of the business_model (bean
>> or XML)
> 
> I think you misread me, I did not mention the id="" attribute anywhere.
> 

I did indeed,
sorry for that.

-marc=



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Further information needed on cform binding

Posted by Jason Johnston <co...@lojjic.net>.
Marc Portier wrote:
> 
> Jason Johnston wrote:
>> Dev at weitling wrote:
>>> Hi folks,
>>>
>>> I want to reach the higher level of cform binding zen, but can't find
>>> enough information.
>>> The questions bothering me are at least:
>>> - What does e.g. <fb:value id="id" path="@id"/> mean? Does it make any
>>> sense in Java-binding?
 >>
>> I believe that in Java binding, path="id" and path="@id" are equivalent.
>>
> 
> they are not
> 
> the id attribute points to the id of the widget in the form_model
> the path attribute points to the structure of the business_model (bean
> or XML)

I think you misread me, I did not mention the id="" attribute anywhere.

> 
> 
> <fb:value id="id" path="@id" /> will thus be executed
> 
> 
> 1/ during LOAD as (expressed in something js-like)
> 
> widget      = currentContextWidget.lookupWidget('id');
> beanContext = currentJXPathContext.getContext('@id');
> widget.setValue(beanContext.getValue());
> 
> 
> 2/ during SAVE as
> 
> widget      = currentContextWidget.lookupWidget('id');
> beanContext = currentJXPathContext.getContext('@id');
> beanContext.setValue(widget.getValue());
> 
> 
> (above just gives the idea, actual api might be slightly different)
> 
> 
> regards,
> -marc=
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Further information needed on cform binding

Posted by Marc Portier <mp...@outerthought.org>.

Jason Johnston wrote:
> Dev at weitling wrote:
>> Hi folks,
>>
>> I want to reach the higher level of cform binding zen, but can't find
>> enough information.
>> The questions bothering me are at least:
>> - What does e.g. <fb:value id="id" path="@id"/> mean? Does it make any
>> sense in Java-binding?
> 
> I believe that in Java binding, path="id" and path="@id" are equivalent.
> 

they are not

the id attribute points to the id of the widget in the form_model
the path attribute points to the structure of the business_model (bean
or XML)


<fb:value id="id" path="@id" /> will thus be executed


1/ during LOAD as (expressed in something js-like)

widget      = currentContextWidget.lookupWidget('id');
beanContext = currentJXPathContext.getContext('@id');
widget.setValue(beanContext.getValue());


2/ during SAVE as

widget      = currentContextWidget.lookupWidget('id');
beanContext = currentJXPathContext.getContext('@id');
beanContext.setValue(widget.getValue());


(above just gives the idea, actual api might be slightly different)


regards,
-marc=

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Further information needed on cform binding

Posted by Jason Johnston <co...@lojjic.net>.
Dev at weitling wrote:
> Hi folks,
> 
> I want to reach the higher level of cform binding zen, but can't find
> enough information.
> The questions bothering me are at least:
> - What does e.g. <fb:value id="id" path="@id"/> mean? Does it make any
> sense in Java-binding?

I believe that in Java binding, path="id" and path="@id" are equivalent.

You can find a lot of information about the details of how the binding 
works from the documentation on the JXPath site: 
http://jakarta.apache.org/commons/jxpath/ -- JXPath is what interprets 
the path attribute to traverse whatever object you're binding to/from, 
so understanding how JXPath works will help you understand the binding 
framework.

> - The path attribute always maps to a member or a get/set-style method
> of a bean. What if I have a method name in other style e.g. list() or
> iterator()? What if I have a method which needs an argument?

Out of the box JXPath only supports certain object structures: JavaBean 
getters/setters, collections, arrays, DOMs... maybe a few others but 
they're all commonly-used standard patterns.  It does appear to have 
some support for custom xpath functions: 
http://jakarta.apache.org/commons/jxpath/users-guide.html#Extension_Functions 
so you may be able to use that to call your custom methods.

> - Imagine I have an object containing three lists: The first holds
> information which key items are displayed and in which order. The others
> have data handled by two repeaters which should display according to the
> order of their keys in the first list. I have a knot in my brain till now...

It sounds to me like you actually want to have your form definition and 
binding XML be dynamically generated using the first list; then when the 
binding is executed it doesn't have to do anything special since the 
repeater widgets already line up with the keys.

> - How to do it when I have a HashMap (key -> data) and I want to display
> the keys as well as their data?

Can you give more details... doesn't the binding already have to know 
the key to get at the value?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org