[ 
https://issues.apache.org/jira/browse/OFBIZ-2831?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12743223#action_12743223
 ] 

Adrian Crum commented on OFBIZ-2831:
------------------------------------

Have you tried using from-field= instead of value=? The from-field attribute 
always returns an object.

I like the proposal. One thing I would prefer though, instead of

{code}<set field="name" from-bsh="org.ofbiz.Foo.Bar()" type="Integer" />{code}

make it

{code}<set field="name" from-scriptlet="org.ofbiz.Foo.Bar()" type="Integer" 
/>{code}

that makes it more generic.

Also, as Jacques mentioned, you can leverage UEL. If one of the existing 
built-in functions doesn't meet your need, then you can always add your own. 
The UelFunctions.java class is fairly well documented, and it has been set up 
so it is extensible.



> Allow fields to be set directly from a bsh scriptlet
> ----------------------------------------------------
>
>                 Key: OFBIZ-2831
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-2831
>             Project: OFBiz
>          Issue Type: Improvement
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Bob Morley
>         Attachments: OFBIZ-2831.patch
>
>
> We have made an improvement to the SetField class in Screen, Field, Menu, and 
> Tree.  You used to do something like this --
> <set field="name" value="${bsh:org.ofbiz.Foo.Bar()}" type="Integer" />
> A disadvantage of this technique is that the value is handled by a 
> FlexibleStringExpander (which will always return a string).  Implementation 
> of this expander will notice the "bsh" and parse out the scriptlet, interpret 
> and get an Object back, then convert the Object to a String.  The caller (say 
> ModelScreenAction) will then take this Object and do a simple type conversion 
> (on ObjectType) to the desired type for the user.  This works fine if the 
> function can return something that can convert to a String and then back to 
> the desired type.  When the return result can not (say a List) then you are 
> pooched.
> My proposed solution is make the grammar more clear in the xml for the Model 
> Action by explicitly stating that we will be providing a bsh scriptlet.  
> Moreover, since we directly call for the Object we can directly convert to 
> the desired object which will work properly for non-string serializable 
> objects like lists and maps.
> <set field="name" from-bsh="org.ofbiz.Foo.Bar()" type="Integer" />
> The implementation does treat the scriptlet as a FlexibleString so it will 
> convert inside for labels resolution and the like.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to