how to properly call a java function from a ftl file in ofbiz?

倖福魔咒の 提交于 2019-12-11 18:39:00

问题


I think I have already done the necessary splicing for me to allow the gui to invoke a java method.

This is my ftl file where the process should start, this is on a widget screens xml file and it is properly displaying the contents but i'm just not sure of the parameters that I used here to do a proper call to the java class

<form action="<@ofbizUrl>methodToInvoke</@ofbizUrl>" method="POST">
    <input type="submit" value="id"></input>
    <input type="text" name="input"></input>
</form>

and this is the code on my controller

<request-map uri="methodToInvoke">
    <security https="true" auth="true"/>
    <event type="java" path="com.report.SomeClass" invoke="methodToInvoke"/>
    <response name="success" type="view" value="reports" />
    <response name="error" type="view" value="reports" />
</request-map>

When I run the application and I hit the button, the address on my browser looks to be trying to call the method but nothing seems to happen. it should download a file to the user and I have already done the setup on the java method such as the reponse headers and the file that needs to be written on it.

When I click on it it does not really do anything and it just goes back to the same page.


回答1:


With ofbiz controllers, you can send back response in two ways:

  1. Preffered more common way: in your java event you call some services, or do some processing, then you the result of the processing a request attribute, and then render these attributes in the view. As you can see, your controller points to a view.
  2. This is less common case, when you need to send to the user some data, which cannot be rendered in the view, in that case, you manually write the data in the response object, and the close the reponse stream. I assume you are doing exactly that. In that case you should not return a view in your controller, because you already have written the data and hopefully closed the response stream. So just change your controller to this:
<response name="success" type="none" />



回答2:


I was not able to build the buildfile of the applcation SPECIFICALLY because I was just using the build.xml for the whole ofbiz and that does not seem to update the modifications on the application that I am using.

After doing that, the changes that I made on the java class worked



来源:https://stackoverflow.com/questions/15740641/how-to-properly-call-a-java-function-from-a-ftl-file-in-ofbiz

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!