You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by "G.Ben" <g....@gmail.com> on 2012/07/22 20:37:01 UTC

Beanshell

Hello everyone,

Please, can anyone tell me what is wrong with this script ? 

import org.ofbiz.base.location.FlexibleLocation;
import freemarker.ext.beans.BeansWrapper;
String scriptName = request.getParameter("scriptName");
if (scriptName == null || scriptName.length() == 0) {
return "success";
}
String lookInLocation =
"component://learning/webapp/learning/WEB-INF/actions/entityaccess/";
URL location = FlexibleLocation.resolveLocation(lookInLocation +
scriptName);
if (location == null) {
context.put("errorMsg", "Script name \"" + scriptName + "\" not found at " +
lookInLocation);
return "success";
}
source(location);
bw = BeansWrapper.getDefaultInstance();
bw.setSimpleMapWrapper(true);
Object massaged;
if (data instanceof List) {
massaged = new ArrayList();
dataItr = data.iterator();
while (dataItr.hasNext()) {
record = (Map) dataItr.next();
massaged.add(bw.wrap(record));
}
}
else if (data instanceof Map) {
massaged = bw.wrap(data);
}
if (massaged != null) {
context.put("data", massaged);
}
return "success";



Thank you so much for your help,

Regards.



--
View this message in context: http://ofbiz.135035.n4.nabble.com/Beanshell-tp4635129.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Beanshell

Posted by Jay Jain <ja...@hotwaxmedia.com>.
Hi Ben
It is a mistake in 'p', use it.

<request-map uri="processEntityAccessBSF">
     <response name="success" type="view" value="ProcessEntityAccessBSF"/>
</request-map>

Regard
Jay Jain

On 07/23/2012 03:33 PM, G.Ben wrote:
> Helloo, I found another Error,
>
> Actually I'm trying to run a beanshell script that allows me to run another
> script to access entities (according to a tutorial), I did all what they
> said however when trying to visualize the URL I get the following error :
> (The URL first show a field when I enter the script that I would run, trying
> to click on submit I get an error)
>
> "org.ofbiz.webapp.control.RequestHandlerException: Unknown request
> [processEntityAccessBSF]; this request does not exist or cannot be called
> directly."
>
>
>
> here are the files that are involved in this operation :
>
> "processEntityAccessBSF.bsh" it's described above,
>
> "test.bsh"
> data = delegator.findAll("PostalAddress");
>
> "Learning Screens.xml"
> <screen name="ProcessEntityAccessBSF">
> 			<section>
> 				<actions>
> 					<script
> location="component://learning/webapp/learning/WEB-INF/actions/entityaccess/processEntityAccessBSF.bsh"/>
> 				</actions>
> 				<widgets>
> 					<decorator-screen name="main-decorator"
> location="${parameters.mainDecoratorLocation}">
> 						<decorator-section name="title">
> 							<label text="Generic Screen for Displaying Data Retrieved"/>
> 						</decorator-section>
> 						<decorator-section name="body">
> 							<include-form name="ScriptNameForm"
> location="component://learning/widget/learning/LearningForms.xml"/>
> 							<section>
> 								<condition>
> 									<not>
> 										<if-empty field-name="parameters.scriptName"/>
> 									</not>
> 							</condition>
> 								<widgets>
> 									<platform-specific>
> 										<html>
> 											<html-template
> location="component://learning/webapp/learning/entityaccess/displaydataretrieved.ftl"/>
> 										</html>
> 									</platform-specific>
> 								</widgets>
> 							</section>
> 						</decorator-section>
> 					</decorator-screen>
> 				</widgets>
> 			</section>
> 		</screen>
>
>
>
> "LearningForms.xml"
> <form name="ScriptNameForm" type="single" target="processEntityAccessBSF">
> 		<field name="scriptName"><text/></field>
> 		<field name="submit"><submit/></field>
> </form>
>
> "displaydataretrieved.ftl"
> <#if errorMsg?has_content>
> ${errorMsg}
>
> <#else>
> Processed script: "${parameters.scriptName}"
>
> <#if data?has_content&&  (data?is_sequence || data?is_hash)>
>
> <@displayData data=data/>
>
> <#else>
> No data records retrieved.
>
> </#if>
> </#if>
> <#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>
>
> </#if>
> </#macro>
>
>
>
> "controller.xml"
>
> <request-map uri="ProcessEntityAccessBSF">
>      <response name="success" type="view" value="ProcessEntityAccessBSF"/>
> </request-map>
>
>
> <view-map name="ProcessEntityAccessBSF" type="screen"
> page="component://learning/widget/learning/LearningScreens.xml#ProcessEntityAccessBSF"/>
>
>
> Anyhelp please,
> I appreciate
>
>
> Thank you.
>
>
> Regards.
>
>
>
>
>
>
> --
> View this message in context: http://ofbiz.135035.n4.nabble.com/Beanshell-tp4635129p4635148.html
> Sent from the OFBiz - User mailing list archive at Nabble.com.


Re: Beanshell

Posted by "G.Ben" <g....@gmail.com>.
Helloo, I found another Error,

Actually I'm trying to run a beanshell script that allows me to run another
script to access entities (according to a tutorial), I did all what they
said however when trying to visualize the URL I get the following error :
(The URL first show a field when I enter the script that I would run, trying
to click on submit I get an error)

"org.ofbiz.webapp.control.RequestHandlerException: Unknown request
[processEntityAccessBSF]; this request does not exist or cannot be called
directly."



here are the files that are involved in this operation : 

"processEntityAccessBSF.bsh" it's described above,

"test.bsh"
data = delegator.findAll("PostalAddress");

"Learning Screens.xml"
<screen name="ProcessEntityAccessBSF">
			<section>
				<actions>
					<script
location="component://learning/webapp/learning/WEB-INF/actions/entityaccess/processEntityAccessBSF.bsh"/>
				</actions>
				<widgets>
					<decorator-screen name="main-decorator"
location="${parameters.mainDecoratorLocation}">
						<decorator-section name="title">
							<label text="Generic Screen for Displaying Data Retrieved"/>
						</decorator-section>
						<decorator-section name="body">
							<include-form name="ScriptNameForm"
location="component://learning/widget/learning/LearningForms.xml"/>
							<section>
								<condition>
									<not>
										<if-empty field-name="parameters.scriptName"/>
									</not>
							</condition>
								<widgets>
									<platform-specific>
										<html>
											<html-template
location="component://learning/webapp/learning/entityaccess/displaydataretrieved.ftl"/>
										</html>
									</platform-specific>
								</widgets>
							</section>
						</decorator-section>
					</decorator-screen>
				</widgets>
			</section>
		</screen>



"LearningForms.xml"
<form name="ScriptNameForm" type="single" target="processEntityAccessBSF">
		<field name="scriptName"><text/></field>
		<field name="submit"><submit/></field>
</form>

"displaydataretrieved.ftl"
<#if errorMsg?has_content>
${errorMsg}

<#else>
Processed script: "${parameters.scriptName}"

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

<@displayData data=data/>

<#else>
No data records retrieved.

</#if>
</#if>
<#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>

</#if>
</#macro>



"controller.xml" 

<request-map uri="ProcessEntityAccessBSF">
    <response name="success" type="view" value="ProcessEntityAccessBSF"/>
</request-map>


<view-map name="ProcessEntityAccessBSF" type="screen"
page="component://learning/widget/learning/LearningScreens.xml#ProcessEntityAccessBSF"/>


Anyhelp please, 
I appreciate


Thank you.


Regards.






--
View this message in context: http://ofbiz.135035.n4.nabble.com/Beanshell-tp4635129p4635148.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Beanshell

Posted by "G.Ben" <g....@gmail.com>.
Thank you so much Robert G.

I couldn't understand the error message.

Thank you again.

Regards.




--
View this message in context: http://ofbiz.135035.n4.nabble.com/Beanshell-tp4635129p4635145.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Beanshell

Posted by "Robert G." <ga...@mercon24.de>.
Sorry, I meant

if (!scriptName) {
return "success";
} 

cause you wanted the success return when it is null or empty.



--
View this message in context: http://ofbiz.135035.n4.nabble.com/Beanshell-tp4635129p4635134.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Beanshell

Posted by "Robert G." <ga...@mercon24.de>.
The error message tells you the problem exactly:

/Attempt to resolve method: length() on undefined variable or class name:
scriptName : at Line: 4 : in file: eval stream : scriptName .length ( ) /

This means, that you cannot call this method (length()) on a "null" value.

In Groovy, a null or empty string evaluates to a boolean false value, so you
can just write:

/
if (scriptName) {
return "success";
} 
/




G.Ben wrote
> 
> When trying to see the URL, I get the following error message : 
> 
> 
> org.ofbiz.widget.screen.ScreenRenderException: Error rendering screen
> [component://learning/widget/learning/LearningScreens.xml#ProcessEntityAccessBSF]:
> java.lang.IllegalArgumentException: Error running script at location
> [component://learning/webapp/learning/WEB-INF/actions/entityaccess/processEntityAccessBSF.bsh]:
> javax.script.ScriptException: Sourced file: eval stream : Attempt to
> resolve method: length() on undefined variable or class name: scriptName :
> at Line: 4 : in file: eval stream : scriptName .length ( ) 
> in eval stream at line number 4 (Error running script at location
> [component://learning/webapp/learning/WEB-INF/actions/entityaccess/processEntityAccessBSF.bsh]:
> javax.script.ScriptException: Sourced file: eval stream : Attempt to
> resolve method: length() on undefined variable or class name: scriptName :
> at Line: 4 : in file: eval stream : scriptName .length ( ) 
> in eval stream at line number 4)
> 
> Thanks  for replying
> 




--
View this message in context: http://ofbiz.135035.n4.nabble.com/Beanshell-tp4635129p4635133.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Beanshell

Posted by "G.Ben" <g....@gmail.com>.
When trying to see the URL, I get the following error message : 


org.ofbiz.widget.screen.ScreenRenderException: Error rendering screen
[component://learning/widget/learning/LearningScreens.xml#ProcessEntityAccessBSF]:
java.lang.IllegalArgumentException: Error running script at location
[component://learning/webapp/learning/WEB-INF/actions/entityaccess/processEntityAccessBSF.bsh]:
javax.script.ScriptException: Sourced file: eval stream : Attempt to resolve
method: length() on undefined variable or class name: scriptName : at Line:
4 : in file: eval stream : scriptName .length ( ) 
in eval stream at line number 4 (Error running script at location
[component://learning/webapp/learning/WEB-INF/actions/entityaccess/processEntityAccessBSF.bsh]:
javax.script.ScriptException: Sourced file: eval stream : Attempt to resolve
method: length() on undefined variable or class name: scriptName : at Line:
4 : in file: eval stream : scriptName .length ( ) 
in eval stream at line number 4)

Thanks  for replying



--
View this message in context: http://ofbiz.135035.n4.nabble.com/Beanshell-tp4635129p4635131.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Beanshell

Posted by "Robert G." <ga...@mercon24.de>.
please specify your problem, that we know for what to look.

thanks
G.Ben wrote
> 
> Hello everyone,
> 
> Please, can anyone tell me what is wrong with this script ? 
> 
> import org.ofbiz.base.location.FlexibleLocation;
> import freemarker.ext.beans.BeansWrapper;
> String scriptName = request.getParameter("scriptName");
> if (scriptName == null || scriptName.length() == 0) {
> return "success";
> }
> String lookInLocation =
> "component://learning/webapp/learning/WEB-INF/actions/entityaccess/";
> URL location = FlexibleLocation.resolveLocation(lookInLocation +
> scriptName);
> if (location == null) {
> context.put("errorMsg", "Script name \"" + scriptName + "\" not found at "
> + lookInLocation);
> return "success";
> }
> source(location);
> bw = BeansWrapper.getDefaultInstance();
> bw.setSimpleMapWrapper(true);
> Object massaged;
> if (data instanceof List) {
> massaged = new ArrayList();
> dataItr = data.iterator();
> while (dataItr.hasNext()) {
> record = (Map) dataItr.next();
> massaged.add(bw.wrap(record));
> }
> }
> else if (data instanceof Map) {
> massaged = bw.wrap(data);
> }
> if (massaged != null) {
> context.put("data", massaged);
> }
> return "success";
> 
> 
> 
> Thank you so much for your help,
> 
> Regards.
> 




--
View this message in context: http://ofbiz.135035.n4.nabble.com/Beanshell-tp4635129p4635130.html
Sent from the OFBiz - User mailing list archive at Nabble.com.