Search code examples
javaalfrescofreemarker

Calling the execute method from the web form in alfresco


I'm quite new to alfresco. How can I call this method from a web form:

@Override
public void execute(final WebScriptRequest req, final WebScriptResponse res) throws IOException {
    try {

        AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>() {
            @Override
            public Void doWork() throws Exception {
                searchInvoice(req, res);
                return null;
            }
        }, AuthenticationUtil.getSystemUserName());

    } catch (Exception e) {
        logger.error("Can not verify query result");
        e.printStackTrace();
    }
}

Is it even possible to implement this approach in alfresco. From this web form :

<form action="execute()" enctype="text/plain"  method="get">
    <input type="hidden" name="url" value="http://book.myrest.com/api?sort=TransDate">
    <label>From: <input type="date" name="from" ></label>
    <lable>To:<input type="date" name="to"></lable>
    <input type="submit" name="submit" value="search">
</form>

Solution

  • You can put your code in a java backed webscript and make its url as action in your <form ..>

    please refer this for to create java backed webscript