Recommended entity retrieval method

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Recommended entity retrieval method

DarkStar1
Bought the book (Apache Ofbiz Development) and going through chapter 8.
When attempting to retrieve the data via the beanshell script: "data = delegator.findAll(<entity_name>)"
The ftl generates an error: " Expecting a string, date or number here, Expression record[key]!"" is instead a freemarker.ext.beans.SimpleMethodModel The problematic instruction: ---------- ==> ${record[key]!""} "

The following is the macro from the book:
<#macro displayData data>
  <#if data?is_sequence>
    <#assign keys = data?first?keys/>
  <#else>
    <#assign keys = data?keys/>
</#if>
  <#-- Header -->
  <tr>
    <#list keys as key>
      <td class="dark-grid"><b>${key}</b></td>
    </#list>
  </tr>
  <#-- Data -->
  <#if data?is_sequence>
    <#list data as record>
        <tr>
            <#list keys as key>
            <td class="light-grid">${record[key]!""}</td>
            </#list>
        </tr>
    </#list>
  <#else>
        <tr>
          <#list keys as key>
          <td class="light-grid">${data[key]!""}</td>
          </#list>
         <h1>Processed script: "${parameters.scriptName}"</h1>
          <#if data?has_content && (data?is_sequence || data?is_hash)>
        </tr> </#if>
  </#if>
</#macro>

On the off chance that there might be a problem elsewhere, I removed the section for displaying data and I noticed that the header were composed of the sql statements the delegator
uses to retrieve the entities. I am very new to ofbiz and aware there's a lot of ground to cover, however this book is several years old and I'd like to know if there's an easier/alternate way to
retrieve the data. I should mention that I use groovy wherever possible in my tests as the book suggests that this is the new scripting method to replace bsh (learning groovy at the same
time also).
I am working with opentaps 1.5 which I believe ships with ofbiz 10.x
Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Recommended entity retrieval method

    <#list keys as key>
          </#list>
    <#-- Data -->
  <#if data?is_sequence>
    <#list data as record>
                    <#list keys as key>
                        </#list>
            </#list>
  <#else>
                  <#list keys as key>
                    </#list>
        

Processed script: "${parameters.scriptName}"

          <#if data?has_content && (data?is_sequence || data?is_hash)>
         </#if>
  </#if>
</#macro>

On the off chance that there might be a problem elsewhere, I removed the section for displaying data and I noticed that the header were composed of the sql statements the delegator
uses to retrieve the entities. I am very new to ofbiz and aware there's a lot of ground to cover, however this book is several years old and I'd like to know if there's an easier/alternate way to
retrieve the data. I should mention that I use groovy wherever possible in my tests as the book suggests that this is the new scripting method to replace bsh (learning groovy at the same
time also).
I am working with opentaps 1.5 which I believe ships with ofbiz 10.x
Thanks
--
Coherent Software Australia Pty Ltd
http://www.coherentsoftware.com.au/

Bonsai ERP, the all-inclusive ERP system
http://www.bonsaierp.com.au/
Paul Foxworthy
Hi DarkStar,

Just in case you weren't aware, where you see <entity_name> you should substitute the name of the entity you want, such as "Party".
 
If you do a view source on the page in the browser, you might find that the td with a class of dark-grid was rendered before the error occurred. This would give you the value of the key variable.

The basic approach of using groovy to retrieve some data and populate a collection for use by freemarker is common. See for example

https://fisheye6.atlassian.com/browse/ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/ViewProfile.groovy?hb=true

which is called from

https://fisheye6.atlassian.com/browse/ofbiz/trunk/applications/party/widget/partymgr/PartyScreens.xml?hb=true#to67

Yes, Groovy is replacing beanshell and should be used for anything new.

Cheers

Paul Foxworthy

DarkStar1 wrote
Bought the book (Apache Ofbiz Development) and going through chapter 8.
When attempting to retrieve the data via the beanshell script: "data = delegator.findAll(<entity_name>)"
The ftl generates an error: " Expecting a string, date or number here, Expression record[key]!"" is instead a freemarker.ext.beans.SimpleMethodModel The problematic instruction: ---------- ==> ${record[key]!""} "

The following is the macro from the book:
<#macro displayData data>
  <#if data?is_sequence>
    <#assign keys = data?first?keys/>
  <#else>
    <#assign keys = data?keys/>
</#if>
  <#-- Header -->
 
${key}
${record[key]!""}
${data[key]!""}
Reply | Threaded
Open this post in threaded view
|

Re: Recommended entity retrieval method

DarkStar1
Merci pour votre résponse.
Yes I know that I am supposed to put the entity name there I was just being generic.
I solved the problem and posted the issue on stack: http://stackoverflow.com/questions/14650949/whats-the-meaning-of-within-a-variable-expression-in-freemarker


On 10 mars 2013, at 11:47, Paul Foxworthy wrote:

> Hi DarkStar,
>
> Just in case you weren't aware, where you see <entity_name> you should
> substitute the name of the entity you want, such as "Party".
>
> If you do a view source on the page in the browser, you might find that the
> td with a class of dark-grid was rendered before the error occurred. This
> would give you the value of the key variable.
>
> The basic approach of using groovy to retrieve some data and populate a
> collection for use by freemarker is common. See for example
>
> https://fisheye6.atlassian.com/browse/ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/ViewProfile.groovy?hb=true
>
> which is called from
>
> https://fisheye6.atlassian.com/browse/ofbiz/trunk/applications/party/widget/partymgr/PartyScreens.xml?hb=true#to67
>
> Yes, Groovy is replacing beanshell and should be used for anything new.
>
> Cheers
>
> Paul Foxworthy
>
>
> DarkStar1 wrote
>> Bought the book (Apache Ofbiz Development) and going through chapter 8.
>> When attempting to retrieve the data via the beanshell script: "data =
>> delegator.findAll(
>> <entity_name>
>> )"
>> The ftl generates an error: " Expecting a string, date or number here,
>> Expression record[key]!"" is instead a
>> freemarker.ext.beans.SimpleMethodModel The problematic instruction:
>> ---------- ==> ${record[key]!""} "
>>
>> The following is the macro from the book:
>> <#macro displayData data>
>>  <#if data?is_sequence>
>>    <#assign keys = data?first?keys/>
>>  <#else>
>>    <#assign keys = data?keys/>
>> &lt;/#if&gt;
>>  <#-- Header -->
>>
>
>>    <#list keys as key>
>>
> *
>> ${key}
> *
>>    &lt;/#list&gt;
>>
>
>>  <#-- Data -->
>>  <#if data?is_sequence>
>>    <#list data as record>
>>
>
>>            <#list keys as key>
>>
>
>> ${record[key]!""}
>
>>            &lt;/#list&gt;
>>
>
>>    &lt;/#list&gt;
>>  <#else>
>>
>
>>          <#list keys as key>
>>
>
>> ${data[key]!""}
>
>>          &lt;/#list&gt;
>>        
>
>> Processed script: "${parameters.scriptName}"
>
>>          <#if data?has_content && (data?is_sequence || data?is_hash)>
>>
>
>> &lt;/#if&gt;
>>  &lt;/#if&gt;
>> &lt;/#macro&gt;
>>
>> On the off chance that there might be a problem elsewhere, I removed the
>> section for displaying data and I noticed that the header were composed of
>> the sql statements the delegator
>> uses to retrieve the entities. I am very new to ofbiz and aware there's a
>> lot of ground to cover, however this book is several years old and I'd
>> like to know if there's an easier/alternate way to
>> retrieve the data. I should mention that I use groovy wherever possible in
>> my tests as the book suggests that this is the new scripting method to
>> replace bsh (learning groovy at the same
>> time also).
>> I am working with opentaps 1.5 which I believe ships with ofbiz 10.x
>> Thanks
>
>
>
>
>
> -----
> --
> Coherent Software Australia Pty Ltd
> http://www.coherentsoftware.com.au/
>
> Bonsai ERP, the all-inclusive ERP system
> http://www.bonsaierp.com.au/
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/Recommended-entity-retrieval-method-tp4639244p4639774.html
> Sent from the OFBiz - Dev mailing list archive at Nabble.com.
>

Reply | Threaded
Open this post in threaded view
|

Re: Recommended entity retrieval method

Paul Foxworthy
Hi Darkstar,

I'm glad you were able to fix the problem. Just to clarify, did changing record[key]!"" to plain record[key] fix it?

Cheers

Paul Foxworthy

DarkStar1 wrote
Merci pour votre résponse.
Yes I know that I am supposed to put the entity name there I was just being generic.
I solved the problem and posted the issue on stack: http://stackoverflow.com/questions/14650949/whats-the-meaning-of-within-a-variable-expression-in-freemarker


On 10 mars 2013, at 11:47, Paul Foxworthy wrote:

> Hi DarkStar,
>
> Just in case you weren't aware, where you see <entity_name> you should
> substitute the name of the entity you want, such as "Party".
>
> If you do a view source on the page in the browser, you might find that the
> td with a class of dark-grid was rendered before the error occurred. This
> would give you the value of the key variable.
>
> The basic approach of using groovy to retrieve some data and populate a
> collection for use by freemarker is common. See for example
>
> https://fisheye6.atlassian.com/browse/ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/ViewProfile.groovy?hb=true
>
> which is called from
>
> https://fisheye6.atlassian.com/browse/ofbiz/trunk/applications/party/widget/partymgr/PartyScreens.xml?hb=true#to67
>
> Yes, Groovy is replacing beanshell and should be used for anything new.
>
> Cheers
>
> Paul Foxworthy
>
>
> DarkStar1 wrote
>> Bought the book (Apache Ofbiz Development) and going through chapter 8.
>> When attempting to retrieve the data via the beanshell script: "data =
>> delegator.findAll(
>> <entity_name>
>> )"
>> The ftl generates an error: " Expecting a string, date or number here,
>> Expression record[key]!"" is instead a
>> freemarker.ext.beans.SimpleMethodModel The problematic instruction:
>> ---------- ==> ${record[key]!""} "
>>
>> The following is the macro from the book:
>> <#macro displayData data>
>>  <#if data?is_sequence>
>>    <#assign keys = data?first?keys/>
>>  <#else>
>>    <#assign keys = data?keys/>
>> </#if>
>>  <#-- Header -->
>>
>
>>    <#list keys as key>
>>
> *
>> ${key}
> *
>>    </#list>
>>
>
>>  <#-- Data -->
>>  <#if data?is_sequence>
>>    <#list data as record>
>>
>
>>            <#list keys as key>
>>
>
>> ${record[key]!""}
>
>>            </#list>
>>
>
>>    </#list>
>>  <#else>
>>
>
>>          <#list keys as key>
>>
>
>> ${data[key]!""}
>
>>          </#list>
>>        
>
>> Processed script: "${parameters.scriptName}"
>
>>          <#if data?has_content && (data?is_sequence || data?is_hash)>
>>
>
>> </#if>
>>  </#if>
>> </#macro>
>>
>> On the off chance that there might be a problem elsewhere, I removed the
>> section for displaying data and I noticed that the header were composed of
>> the sql statements the delegator
>> uses to retrieve the entities. I am very new to ofbiz and aware there's a
>> lot of ground to cover, however this book is several years old and I'd
>> like to know if there's an easier/alternate way to
>> retrieve the data. I should mention that I use groovy wherever possible in
>> my tests as the book suggests that this is the new scripting method to
>> replace bsh (learning groovy at the same
>> time also).
>> I am working with opentaps 1.5 which I believe ships with ofbiz 10.x
>> Thanks
>
>
>
>
>
> -----
> --
> Coherent Software Australia Pty Ltd
> http://www.coherentsoftware.com.au/
>
> Bonsai ERP, the all-inclusive ERP system
> http://www.bonsaierp.com.au/
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/Recommended-entity-retrieval-method-tp4639244p4639774.html
> Sent from the OFBiz - Dev mailing list archive at Nabble.com.
>
--
Coherent Software Australia Pty Ltd
http://www.coherentsoftware.com.au/

Bonsai ERP, the all-inclusive ERP system
http://www.bonsaierp.com.au/
Reply | Threaded
Open this post in threaded view
|

Re: Recommended entity retrieval method

DarkStar1
Hi
That didn't do it either,a s that was the first thing I tried.
Also I got the solution post wrong. This: http://stackoverflow.com/questions/14687035/how-can-i-retrieve-object-keys-from-a-sequence-in-freemarker
was what gave me the clue to solve it. I simply replaced the brackets for the normal ones as it appears that the indexes weren't strings.

Thanks for the responses.

On 12 mars 2013, at 01:57, Paul Foxworthy wrote:

> Hi Darkstar,
>
> I'm glad you were able to fix the problem. Just to clarify, did changing
> record[key]!"" to plain record[key] fix it?
>
> Cheers
>
> Paul Foxworthy
>
>
> DarkStar1 wrote
>> Merci pour votre résponse.
>> Yes I know that I am supposed to put the entity name there I was just
>> being generic.
>> I solved the problem and posted the issue on stack:
>> http://stackoverflow.com/questions/14650949/whats-the-meaning-of-within-a-variable-expression-in-freemarker
>>
>>
>> On 10 mars 2013, at 11:47, Paul Foxworthy wrote:
>>
>>> Hi DarkStar,
>>>
>>> Just in case you weren't aware, where you see
>> <entity_name>
>> you should
>>> substitute the name of the entity you want, such as "Party".
>>>
>>> If you do a view source on the page in the browser, you might find that
>>> the
>>> td with a class of dark-grid was rendered before the error occurred. This
>>> would give you the value of the key variable.
>>>
>>> The basic approach of using groovy to retrieve some data and populate a
>>> collection for use by freemarker is common. See for example
>>>
>>> https://fisheye6.atlassian.com/browse/ofbiz/trunk/applications/party/webapp/partymgr/WEB-INF/actions/party/ViewProfile.groovy?hb=true
>>>
>>> which is called from
>>>
>>> https://fisheye6.atlassian.com/browse/ofbiz/trunk/applications/party/widget/partymgr/PartyScreens.xml?hb=true#to67
>>>
>>> Yes, Groovy is replacing beanshell and should be used for anything new.
>>>
>>> Cheers
>>>
>>> Paul Foxworthy
>>>
>>>
>>> DarkStar1 wrote
>>>> Bought the book (Apache Ofbiz Development) and going through chapter 8.
>>>> When attempting to retrieve the data via the beanshell script: "data =
>>>> delegator.findAll(
>>>>
>> <entity_name>
>>>> )"
>>>> The ftl generates an error: " Expecting a string, date or number here,
>>>> Expression record[key]!"" is instead a
>>>> freemarker.ext.beans.SimpleMethodModel The problematic instruction:
>>>> ---------- ==> ${record[key]!""} "
>>>>
>>>> The following is the macro from the book:
>>>> <#macro displayData data>
>>>> <#if data?is_sequence>
>>>>   <#assign keys = data?first?keys/>
>>>> <#else>
>>>>   <#assign keys = data?keys/>
>>>> &lt;/#if&gt;
>>>> <#-- Header -->
>>>>
>>>
>>>>   <#list keys as key>
>>>>
>>> *
>>>> ${key}
>>> *
>>>>   &lt;/#list&gt;
>>>>
>>>
>>>> <#-- Data -->
>>>> <#if data?is_sequence>
>>>>   <#list data as record>
>>>>
>>>
>>>>           <#list keys as key>
>>>>
>>>
>>>> ${record[key]!""}
>>>
>>>>           &lt;/#list&gt;
>>>>
>>>
>>>>   &lt;/#list&gt;
>>>> <#else>
>>>>
>>>
>>>>         <#list keys as key>
>>>>
>>>
>>>> ${data[key]!""}
>>>
>>>>         &lt;/#list&gt;
>>>>       
>>>
>>>> Processed script: "${parameters.scriptName}"
>>>
>>>>         <#if data?has_content && (data?is_sequence || data?is_hash)>
>>>>
>>>
>>>> &lt;/#if&gt;
>>>> &lt;/#if&gt;
>>>> &lt;/#macro&gt;
>>>>
>>>> On the off chance that there might be a problem elsewhere, I removed the
>>>> section for displaying data and I noticed that the header were composed
>>>> of
>>>> the sql statements the delegator
>>>> uses to retrieve the entities. I am very new to ofbiz and aware there's
>>>> a
>>>> lot of ground to cover, however this book is several years old and I'd
>>>> like to know if there's an easier/alternate way to
>>>> retrieve the data. I should mention that I use groovy wherever possible
>>>> in
>>>> my tests as the book suggests that this is the new scripting method to
>>>> replace bsh (learning groovy at the same
>>>> time also).
>>>> I am working with opentaps 1.5 which I believe ships with ofbiz 10.x
>>>> Thanks
>>>
>>>
>>>
>>>
>>>
>>> -----
>>> --
>>> Coherent Software Australia Pty Ltd
>>> http://www.coherentsoftware.com.au/
>>>
>>> Bonsai ERP, the all-inclusive ERP system
>>> http://www.bonsaierp.com.au/
>>>
>>> --
>>> View this message in context:
>>> http://ofbiz.135035.n4.nabble.com/Recommended-entity-retrieval-method-tp4639244p4639774.html
>>> Sent from the OFBiz - Dev mailing list archive at Nabble.com.
>>>
>
>
>
>
>
> -----
> --
> Coherent Software Australia Pty Ltd
> http://www.coherentsoftware.com.au/
>
> Bonsai ERP, the all-inclusive ERP system
> http://www.bonsaierp.com.au/
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/Recommended-entity-retrieval-method-tp4639244p4639807.html
> Sent from the OFBiz - Dev mailing list archive at Nabble.com.
>