You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Johnson <jo...@soho.club.tw> on 2004/06/18 08:33:04 UTC

the widget datatype question

Hi

 I try to caculate the widget value in repeter to another widget,the code is

     <fd:field id="test">
       <fd:label><i18n:text key="test">test:</i18n:text></fd:label>
       <fd:datatype base="decimal"/>
     </fd:field>

     <fd:repeater id="daily1List">
       <fd:field id="amt">
         <fd:label><i18n:text key="amt">amt:</i18n:text></fd:label>
         <fd:datatype base="decimal"/>
       </fd:field>
     </fd:repeater>

     <fd:repeater-action id="removeDaily1" action-command="delete-rows"
 repeater="daily1List" select="select">
           <fd:label><i18n:text
 key="removeDaily1">removeDaily1:</i18n:text></fd:label>
          <fd:on-activate>
          <javascript>
           var dList =  event.source.parent.lookupWidget("daily1List");
           var testv=0;

           for (var i = 0; i &lt; dList.size; i++) {
                 var row = dList.getRow(i);
                 num1 = row.lookupWidget("amt").value;
                 testv = testv + num1;
         }

         var test = event.source.parent.lookupWidget("test");
         test.setValue(testv);
        </javascript>
       </fd:on-activate>

     </fd:repeater-action>

 If I had two row,one amt is 1,one amt is 2,the test will be "12",why.

 Best Regards

 Johnson



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


Re: the widget datatype question

Posted by Joerg Heinicke <jo...@gmx.de>.
On 18.06.2004 09:42, Johnson wrote:

> But the system say can't convert Null to object,why

That simply means that one of your variables is null and you try to call
a method or property on it. It's just like a NullPointerException in
Java. So have a look into the line and find out what's null.

Joerg


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


Re: the widget datatype question

Posted by Johnson <jo...@soho.club.tw>.
another familiar question
If I want to do the same sumary in the amt field I wrote
      <fd:on-value-changed>
         <javascript>
          var dList =  event.source.parent.lookupWidget("daily1List");
          var testv=new Packages.java.math.BigDecimal("0");

          for (var i = 0; i &lt; dList.size; i++) {
                var row = dList.getRow(i);
 var num1 = new
Packages.java.math.BigDecimal(row.lookupWidget("amt").getValue());
 testv = testv.add(num1);
        }
        var test = event.source.parent.lookupWidget("test");
        test.setValue(testv);
       </javascript>
       </fd:on-value-changed>
But the system say can't convert Null to object,why

Best Regards

Johnson


----- Original Message ----- 
From: "Bruno Dumon" <br...@outerthought.org>
To: <us...@cocoon.apache.org>
Sent: Friday, June 18, 2004 2:46 PM
Subject: Re: the widget datatype question


> On Fri, 2004-06-18 at 08:33, Johnson wrote:
> > Hi
> >
> >  I try to caculate the widget value in repeter to another widget,the
code is
> >
> >      <fd:field id="test">
> >        <fd:label><i18n:text key="test">test:</i18n:text></fd:label>
> >        <fd:datatype base="decimal"/>
> >      </fd:field>
> >
> >      <fd:repeater id="daily1List">
> >        <fd:field id="amt">
> >          <fd:label><i18n:text key="amt">amt:</i18n:text></fd:label>
> >          <fd:datatype base="decimal"/>
> >        </fd:field>
> >      </fd:repeater>
> >
> >      <fd:repeater-action id="removeDaily1" action-command="delete-rows"
> >  repeater="daily1List" select="select">
> >            <fd:label><i18n:text
> >  key="removeDaily1">removeDaily1:</i18n:text></fd:label>
> >           <fd:on-activate>
> >           <javascript>
> >            var dList =  event.source.parent.lookupWidget("daily1List");
> >            var testv=0;
> >
> >            for (var i = 0; i &lt; dList.size; i++) {
> >                  var row = dList.getRow(i);
> >                  num1 = row.lookupWidget("amt").value;
> >                  testv = testv + num1;
> >          }
> >
> >          var test = event.source.parent.lookupWidget("test");
> >          test.setValue(testv);
> >         </javascript>
> >        </fd:on-activate>
> >
> >      </fd:repeater-action>
> >
> >  If I had two row,one amt is 1,one amt is 2,the test will be "12",why.
>
> Probably because Javascript doesn't know about bigdecimals. Depending on
> your needs, you could change the datatype of the widget to float, double
> or long.
>
> If you need the precission of bigdecimal numbers, you need to use the
> methods of the BigDecimal class to do your calculations. See the javadoc
> of that class.
>
> It would be something like
>
> var testv = new Packages.java.math.BigDecimal("0");
> testv = testv.add(num1);
>
> -- 
> Bruno Dumon                             http://outerthought.org/
> Outerthought - Open Source, Java & XML Competence Support Center
> bruno@outerthought.org                          bruno@apache.org
>
>
> ---------------------------------------------------------------------
> 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: the widget datatype question

Posted by Johnson <jo...@soho.club.tw>.
It work,tks very much

Johnson

----- Original Message ----- 
From: "Bruno Dumon" <br...@outerthought.org>
To: <us...@cocoon.apache.org>
Sent: Friday, June 18, 2004 2:46 PM
Subject: Re: the widget datatype question


> On Fri, 2004-06-18 at 08:33, Johnson wrote:
> > Hi
> >
> >  I try to caculate the widget value in repeter to another widget,the
code is
> >
> >      <fd:field id="test">
> >        <fd:label><i18n:text key="test">test:</i18n:text></fd:label>
> >        <fd:datatype base="decimal"/>
> >      </fd:field>
> >
> >      <fd:repeater id="daily1List">
> >        <fd:field id="amt">
> >          <fd:label><i18n:text key="amt">amt:</i18n:text></fd:label>
> >          <fd:datatype base="decimal"/>
> >        </fd:field>
> >      </fd:repeater>
> >
> >      <fd:repeater-action id="removeDaily1" action-command="delete-rows"
> >  repeater="daily1List" select="select">
> >            <fd:label><i18n:text
> >  key="removeDaily1">removeDaily1:</i18n:text></fd:label>
> >           <fd:on-activate>
> >           <javascript>
> >            var dList =  event.source.parent.lookupWidget("daily1List");
> >            var testv=0;
> >
> >            for (var i = 0; i &lt; dList.size; i++) {
> >                  var row = dList.getRow(i);
> >                  num1 = row.lookupWidget("amt").value;
> >                  testv = testv + num1;
> >          }
> >
> >          var test = event.source.parent.lookupWidget("test");
> >          test.setValue(testv);
> >         </javascript>
> >        </fd:on-activate>
> >
> >      </fd:repeater-action>
> >
> >  If I had two row,one amt is 1,one amt is 2,the test will be "12",why.
>
> Probably because Javascript doesn't know about bigdecimals. Depending on
> your needs, you could change the datatype of the widget to float, double
> or long.
>
> If you need the precission of bigdecimal numbers, you need to use the
> methods of the BigDecimal class to do your calculations. See the javadoc
> of that class.
>
> It would be something like
>
> var testv = new Packages.java.math.BigDecimal("0");
> testv = testv.add(num1);
>
> -- 
> Bruno Dumon                             http://outerthought.org/
> Outerthought - Open Source, Java & XML Competence Support Center
> bruno@outerthought.org                          bruno@apache.org
>
>
> ---------------------------------------------------------------------
> 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: the widget datatype question

Posted by Bruno Dumon <br...@outerthought.org>.
On Fri, 2004-06-18 at 08:33, Johnson wrote:
> Hi
> 
>  I try to caculate the widget value in repeter to another widget,the code is
> 
>      <fd:field id="test">
>        <fd:label><i18n:text key="test">test:</i18n:text></fd:label>
>        <fd:datatype base="decimal"/>
>      </fd:field>
> 
>      <fd:repeater id="daily1List">
>        <fd:field id="amt">
>          <fd:label><i18n:text key="amt">amt:</i18n:text></fd:label>
>          <fd:datatype base="decimal"/>
>        </fd:field>
>      </fd:repeater>
> 
>      <fd:repeater-action id="removeDaily1" action-command="delete-rows"
>  repeater="daily1List" select="select">
>            <fd:label><i18n:text
>  key="removeDaily1">removeDaily1:</i18n:text></fd:label>
>           <fd:on-activate>
>           <javascript>
>            var dList =  event.source.parent.lookupWidget("daily1List");
>            var testv=0;
> 
>            for (var i = 0; i &lt; dList.size; i++) {
>                  var row = dList.getRow(i);
>                  num1 = row.lookupWidget("amt").value;
>                  testv = testv + num1;
>          }
> 
>          var test = event.source.parent.lookupWidget("test");
>          test.setValue(testv);
>         </javascript>
>        </fd:on-activate>
> 
>      </fd:repeater-action>
> 
>  If I had two row,one amt is 1,one amt is 2,the test will be "12",why.

Probably because Javascript doesn't know about bigdecimals. Depending on
your needs, you could change the datatype of the widget to float, double
or long.

If you need the precission of bigdecimal numbers, you need to use the
methods of the BigDecimal class to do your calculations. See the javadoc
of that class.

It would be something like

var testv = new Packages.java.math.BigDecimal("0");
testv = testv.add(num1);

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


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