To complete
You can define a request-map
<request-map uri="DisplayTastCalc">
<security https="true" auth="true"/>
<event type="service" invoke="testCalc"/>
<response name="success" type="view" value="DisplayTestCalc">
</request-map>
<view-map name="DisplayTestCalc" type="screen"
page="component://myCompo/MyScreens.xml#DisplayTestCalc"/>
on
<field name="calcTest" title=" " widget-style="buttontext">
<hyperlink description="Calculate C" target="DisplayTestCalc" also-hidden="false"
link-type="update-area" target-window="DisplayTestCalcContainer">
<parameter param-name="scale-factror"/>
<!-- e.g add an allowance for packing material -->
</hyperlink>
</field>
<field name="calcTestContainer" title=" " id-name="DisplayTestCalcContainer" title="
"><container/></field>
This works only on OFBiz 22.01, on previous version you need to use
javascript call directly
<hyperlink description="Calculate C" also-hidden="false" target="javascript:ajaxUpdateArea('DisplayTestCalc',
'DisplayTestCalcContainer', 'scale-factror =${scale-factror}');" target-type="plain" />
Don't forget to define your screen DisplayTestCal with the simple decorator to
minimize the html code return on the response
Nicolas
On 24/01/2023 08:23, Taher Alkhateeb wrote:
Hello,
So you cannot call groovy, or any other programming language for that matter,
from your browser. The only thing you can call from the browser is javascript
and the DOM.
So if you want to wire a button to some piece of code that you would like to
execute, then this is simply a good-old http-request / http-response thing just
like in any other technology / programming language / framework.
So what you want to do, is to call an end-point that is defined in
Controller.xml and pass whatever parameters you need to it, and from there now
you're in server-land and you can do whatever you're used to in OFBiz. Note
that it's quite different to call an HTTP end-point by submitting a form (the
browser does it) vs calling it from Javascript (you do it) because in the
latter case you are not redirected to another page.
In other words, perhaps the problem is simply not differentiating between what
is server-side code and client-side code. If you make the distinction clear
then you just realize it's a matter of HTTP communication between the two.
I hope this helps!
Cheers,
Taher Alkhateeb
On Tuesday, January 24, 2023 04:09 +03, Ernest
Hocking<[email protected]> wrote:
Hi everyone
I'd like to use groovy to implement some business logic and call that logic
from a button in a form.
E.g Add a button on the product measures form to calculate the volume
given a product's dimensions.. I've tried
<field name="calcTest" title=" " widget-style="buttontext">
<hyperlink description="Calculate C" target="testCalc"
also-hidden="false">
<parameter param-name="scale-factror"/>
<!-- e.g add an allowance for packing material -->
</hyperlink>
</field>
I can call/test the service "testCalc" from webtools etc but not use the
button.
Can anyone point me to an example in the existing code base that I can use
as a reference model.
thanks in advance
Ernest