Nested Repeats

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Nested Repeats

BitByter
Hi XForms experts,

I'm quite new to XForms and would like to implement a small quiz as an
exercise. Thus I've created a small XSD that defines the structure of my
quiz and an JSP page using XForms to implement the quiz itself (see
attachments).

The quiz should be in a table like layout, having two coloumns. The first
for the question and all available answers for each question, and the second
for the score of the question.

I've tried several variants to achieve the desired result, but without
fortune. Currently I'm having these problems:

* When referencing an element from a nodeset of a <xforms:repeat> element,
the browser always shows a red exclamation mark (!). Why and how do I stop
this?

* How do I place all available answers of a question beneath each other with
a <xforms:select1> element?

* How do I set the score/value of a selected answer to its associated
question <result> element?

* How do I correctly sum up the total score of all selected answers?

* Is an <xforms:help> element allowed within an <xforms:output> element?
Orbeon Forms doesn't complain about that, but I think the XForms reference
doesn't allow it.

I guess this all is straight forward for anybody working daily with XForms,
so grant grace to me. :)

- bitbyter



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

quiz.xsd (2K) Download Attachment
quiz.jsp (7K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Nested Repeats

Hank Ratzesberger
With me, this could be a case of the blind leading...
and I have not tried to integrate with jsp, but
here goes.
 
In general, I suggest you need a few data instances.  You
have the questions, but you need had another for the
answers, which is intially blank/empty or has all a
special value that means not answered yet. Your quiz-instance
helps you build the form, but there is no place for
the selections made.  And you may need a third instance to
control the display/activation of questions so the user
cannot answer out of order - just a guess..
 
When a selection is made, you can use xforms:insert
to add to your answers instance. The second column,
for example, is enclosed in a different xforms:group
that refers to the answers instance.  The xforms engine
will know that it has to redraw when the referenced
instance is updated.
 
 To do calculations, you want to use bindings. There is
a calculate binding that will be invoked when the instance
changes.
 
HTH,
Hank
 
----- Original Message -----
Sent: Friday, May 04, 2007 7:15 AM
Subject: [ops-users] Nested Repeats

Hi XForms experts,

I'm quite new to XForms and would like to implement a small quiz as an
exercise. Thus I've created a small XSD that defines the structure of my
quiz and an JSP page using XForms to implement the quiz itself (see
attachments).

The quiz should be in a table like layout, having two coloumns. The first
for the question and all available answers for each question, and the second
for the score of the question.

I've tried several variants to achieve the desired result, but without
fortune. Currently I'm having these problems:

* When referencing an element from a nodeset of a <xforms:repeat> element,
the browser always shows a red exclamation mark (!). Why and how do I stop
this?
-
 

* How do I place all available answers of a question beneath each other with
a <xforms:select1> element?

* How do I set the score/value of a selected answer to its associated
question <result> element?

* How do I correctly sum up the total score of all selected answers?

* Is an <xforms:help> element allowed within an <xforms:output> element?
Orbeon Forms doesn't complain about that, but I think the XForms reference
doesn't allow it.

I guess this all is straight forward for anybody working daily with XForms,
so grant grace to me. :)

- bitbyter



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re[2]: Nested Repeats

BitByter
Hi Hank,

Wednesday, May 9, 2007, 1:51:27 AM, you wrote:

> With me, this could be a case of the blind  leading...
> and I have not tried to integrate with jsp, but
> here goes.

Doesn't seem the problem is JSP, as I tried it directly within OPS as static
XHTML page. Unfortunately with the same result.  :(


> In general, I suggest you need a few data instances.  You
> have the questions, but you need had another for the
> answers, which is intially blank/empty or has all a
> special value that means not answered yet. Your  quiz-instance
> helps you build the form, but there is no place for
> the selections made.  And you  may need a third instance to
> control the display/activation of questions so the  user
> cannot answer out of order - just a guess..

Well, the quiz is/should be a multiple choice quiz, which means you get a
question and a few answers for each question, and just one answer is
correct. And the score/points of the selected answer should be stored in the
element "result" of the associated question. So is there really a need for a
second data instance to store the selections?

Thus I'm having just one data instance, which is the complete quiz itself,
which later on of course should be loaded dynamically and after finishing it
saved for later access.

And I intended to display the complete quiz at once and allow to answer the
questions mixed up.

So is there really (technically) a need for further data instances? The
question may sound dumb, but I'm not sure if I'm using XForms as it is
intended to be used.


> When a selection is made, you can use xforms:insert
> to add to your answers instance. The second column,
> for example, is enclosed in a different xforms:group
> that refers to the answers instance.  The xforms  engine
> will know that it has to redraw when the referenced
> instance is updated.

I'm not sure if I understood this suggestion.  :(


> To do calculations, you want to use  bindings. There is
> a calculate binding that will be invoked when the  instance
> changes.

Well, the calculation should not be stored in any data instance, rather only
displayed. So a binding seems to be inadequate as there is nothing to bind
against. :)    But Erik made a suggestion that I'll try out as soon as I get
the questions/answers displayed.


- bitbyter





--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re[2]: Nested Repeats

Hank Ratzesberger
bitbyter,

OK, I see now you do have a <result></result>
to put the selection -- no need for another instance.
I was thinking that you may not want the form changed
when submitted, because the xforms engine will update
all the <group> areas that reference the instance.

Well, this is a case when the xforms inspector may help you
http://www.orbeon.com/blog/2007/02/02/orbeon-forms-instance-inspector/

I did some editing so I could run in the xforms sandbox. I am
having a couple problems, mostly getting the right answers to
list -- I get only the first.  

Let's see if we can get something to work in the sandbox.  I'll
have to try again later.

--Hank

----- Original Message -----
From: "BitByter" <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, May 09, 2007 12:10 AM
Subject: Re[2]: [ops-users] Nested Repeats


Hi Hank,

Wednesday, May 9, 2007, 1:51:27 AM, you wrote:

> With me, this could be a case of the blind  leading...
> and I have not tried to integrate with jsp, but
> here goes.

Doesn't seem the problem is JSP, as I tried it directly within OPS as static
XHTML page. Unfortunately with the same result.  :(


> In general, I suggest you need a few data instances. You
> have the questions, but you need had another for the
> answers, which is intially blank/empty or has all a
> special value that means not answered yet. Your  quiz-instance
> helps you build the form, but there is no place for
> the selections made. And you  may need a third instance to
> control the display/activation of questions so the  user
> cannot answer out of order - just a guess..

Well, the quiz is/should be a multiple choice quiz, which means you get a
question and a few answers for each question, and just one answer is
correct. And the score/points of the selected answer should be stored in the
element "result" of the associated question. So is there really a need for a
second data instance to store the selections?

Thus I'm having just one data instance, which is the complete quiz itself,
which later on of course should be loaded dynamically and after finishing it
saved for later access.

And I intended to display the complete quiz at once and allow to answer the
questions mixed up.

So is there really (technically) a need for further data instances? The
question may sound dumb, but I'm not sure if I'm using XForms as it is
intended to be used.


> When a selection is made, you can use xforms:insert
> to add to your answers instance. The second column,
> for example, is enclosed in a different xforms:group
> that refers to the answers instance. The xforms  engine
> will know that it has to redraw when the referenced
> instance is updated.

I'm not sure if I understood this suggestion.  :(


> To do calculations, you want to use  bindings. There is
> a calculate binding that will be invoked when the  instance
> changes.

Well, the calculation should not be stored in any data instance, rather only
displayed. So a binding seems to be inadequate as there is nothing to bind
against. :)    But Erik made a suggestion that I'll try out as soon as I get
the questions/answers displayed.


- bitbyter







>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
>

--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

quiz2.jsp (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re[4]: Nested Repeats

BitByter
Hi Hank,

Wednesday, May 9, 2007, 7:01:13 PM, you wrote:

> Well, this is a case when the xforms inspector may help you
> http://www.orbeon.com/blog/2007/02/02/orbeon-forms-instance-inspector/

Doesn't/didn't really help in this case, because I know how the instance
looks like. There is nothing added or delete from the instance, except that
the result for the selected answers is stored.

> I did some editing so I could run in the xforms sandbox. I am
> having a couple problems, mostly getting the right answers to
> list -- I get only the first.

Many  thanks  for  your  effort. The following code snippet does the desired
job:

<table border="1">
   <thead>
      <th>QUESTION</th>
      <th>SCORE</th>
   </thead>
   <xforms:repeat nodeset="instance('quiz-instance')/question" id="quiz-repeat">
      <tr>
         <td>
            <xforms:select1 ref="./result" appearance="full">
               <xforms:label ref="../text" />
               <xforms:help ref="../description" />
               <xforms:itemset model="quiz-model" nodeset="xxforms:repeat-current()/answers/answer">
                 <xforms:label ref="./text" />
                 <xforms:value ref="./value" />
               </xforms:itemset>
            </xforms:select1>
         </td>
         <td>
            <xforms:output ref="result" />
         </td>
      </tr>
   </xforms:repeat>
   <tfoot>
      <td>Total Score</td>
      <td><xforms:output value="sum(for $value in /quiz/question/result return number($value))"/></td>
   </tfoot>
</table>


What makes me stunning is the fact that I can use e.g. "../text" to
reference the question text for the itemset of answers. Seems as if the
context of the repeat control changes when having an itemset control inside.
But I'm not sure if the context should or is allowed to change in such a
case?

But I'm still looking for a solution that does not use any Orbeon specific
<xxforms:*> controls...

And by the way: the <xforms:help> control generates an '?' image after last
available answers for each question. Is it possible to place that behind the
output of the <xforms:label> control, which is the question itself in this
case?


- bitbyter




--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re[4]: Nested Repeats

Hank Ratzesberger

bitbyter,

The context of xpath expressions does change for
repeats and itemsets.  As I understand, itemsets require
their own model, even if in your case it is the same
model as the instance data -- but this changes the context
for its nodeset attribute.  And repeat expressions change
the the context to that of the current repeat iteration.

Well, the xforms inspector is a lot of help to me because
I can evaluate xpath expressions, although I don't know
yet how to filter out the NaN's from the sum.

I too would ideally avoid Orbeon extensions, but every time
they solve a problem.

The changing context of repeats and itemsets can, as the
saying goes, paint oneself into a corner.

Cheers,
Hank


----- Original Message -----
From: "BitByter" <[hidden email]>
To: <[hidden email]>
Sent: Thursday, May 10, 2007 4:32 AM
Subject: Re[4]: [ops-users] Nested Repeats


> Hi Hank,
>
> Wednesday, May 9, 2007, 7:01:13 PM, you wrote:
>
>> Well, this is a case when the xforms inspector may help you
>> http://www.orbeon.com/blog/2007/02/02/orbeon-forms-instance-inspector/
>
> Doesn't/didn't really help in this case, because I know how the instance
> looks like. There is nothing added or delete from the instance, except that
> the result for the selected answers is stored.
>
>> I did some editing so I could run in the xforms sandbox. I am
>> having a couple problems, mostly getting the right answers to
>> list -- I get only the first.
>
> Many  thanks  for  your  effort. The following code snippet does the desired
> job:
>
> <table border="1">
>   <thead>
>      <th>QUESTION</th>
>      <th>SCORE</th>
>   </thead>
>   <xforms:repeat nodeset="instance('quiz-instance')/question" id="quiz-repeat">
>      <tr>
>         <td>
>            <xforms:select1 ref="./result" appearance="full">
>               <xforms:label ref="../text" />
>               <xforms:help ref="../description" />
>               <xforms:itemset model="quiz-model" nodeset="xxforms:repeat-current()/answers/answer">
>                 <xforms:label ref="./text" />
>                 <xforms:value ref="./value" />
>               </xforms:itemset>
>            </xforms:select1>
>         </td>
>         <td>
>            <xforms:output ref="result" />
>         </td>
>      </tr>
>   </xforms:repeat>
>   <tfoot>
>      <td>Total Score</td>
>      <td><xforms:output value="sum(for $value in /quiz/question/result return number($value))"/></td>
>   </tfoot>
> </table>
>
>
> What makes me stunning is the fact that I can use e.g. "../text" to
> reference the question text for the itemset of answers. Seems as if the
> context of the repeat control changes when having an itemset control inside.
> But I'm not sure if the context should or is allowed to change in such a
> case?
>
> But I'm still looking for a solution that does not use any Orbeon specific
> <xxforms:*> controls...
>
> And by the way: the <xforms:help> control generates an '?' image after last
> available answers for each question. Is it possible to place that behind the
> output of the <xforms:label> control, which is the question itself in this
> case?
>
>
> - bitbyter
>
>
>

--------------------------------------------------------------------------------


>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
>



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re[4]: Nested Repeats

Alessandro Vernet
Administrator
In reply to this post by BitByter
On 5/10/07, BitByter <[hidden email]> wrote:
> But I'm still looking for a solution that does not use any Orbeon specific
> <xxforms:*> controls...

BitByter,

Instead of xxforms:repeat-current()/answers/answer, you should be able
to write instance('quiz-instance')/question[index('quiz-repeat')]/answers/answer.
The expression gets a little longer as you duplicate the code that you
already have in the <xforms:repeat nodeset="..."> expression, but as a
benefit you are not using xxforms:repeat-current().

Alex
--
Orbeon Forms - Web 2.0 Forms for the Enterprise
http://www.orbeon.com/



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws