AnsweredAssumed Answered

facesContext is null while running a java-backed webscript

Question asked by walid on May 1, 2011
Latest reply on May 1, 2011 by walid
Hello,

I'm writing an AMP for alfresco explorer 3.2r

webscript description file :
<webscript>
    <shortname>Créer des regles de contenu</shortname>
    <description>Créer des regles de contenu</description>
    <url>/xxxx/contentRules/trywebscript</url>
    <authentication>admin</authentication>
    <format default="">argument</format>
</webscript>

Java class for webscript :
public class RuleUtilScript extends AbstractWebScript {
public RuleUtilScript() {
     }
    @Override
    public void execute(WebScriptRequest req, WebScriptResponse res)
            throws IOException {
        CreateRuleTest ruleTest = new CreateRuleTest();
        ruleTest.createRule();
        res.getWriter().write("yup, i did it !!");
    }
}

In module-context.xml :
    <bean id="webscript.xxxx.contentRules.trywebscript.get"
        class="fr.xxxxxx.alfresco.xxxx.CreateDynamicContentRules.RuleUtilScript"
        parent="webscript">
    </bean>

I followed http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples, i found the webscript registred in /service/index, when i run it, it throws :
16:21:24,651  ERROR [web.scripts.AbstractRuntime] Exception from executeScript - redirecting to status template error: null
java.lang.NullPointerException
    at org.alfresco.web.app.context.UIContextService.getInstance(UIContextService.java:62)
    at org.alfresco.web.bean.dialog.BaseDialogBean.init(BaseDialogBean.java:78)
    at org.alfresco.web.bean.actions.BaseActionWizard.init(BaseActionWizard.java:123)
    at org.alfresco.web.bean.rules.CreateRuleWizard.init(CreateRuleWizard.java:119)
    at fr.starxpert.alfresco.xxxx.CreateDynamicContentRules.CreateRuleTest.<init>(CreateRuleTest.java:35)
    at fr.starxpert.alfresco.xxxx.CreateDynamicContentRules.RuleUtilScript.execute(RuleUtilScript.java:62)
    at org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:372)
    at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:327)
    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:422)
    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:439)
    at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:303)
    at org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:306)
    at org.alfresco.web.scripts.AbstractRuntime.executeScript(AbstractRuntime.java:183)
    at org.alfresco.web.scripts.servlet.WebScriptServlet.service(WebScriptServlet.java:122)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:662)

In debug :
this line : UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();     throws NullPointerException
====> FacesContext.getCurrentInstance() returns null.

I spent some hours on this, i tried to add managed-bean to faces-config-custom.xml but with no success.

thanks in advance :)

Outcomes