PDA

View Full Version : directFn is not defined error, when store.load() is called



sandeep.r
15 Mar 2011, 2:24 AM
Sub : Error in firebug console like this:
LoginFacade is not defined. directFn : LoginFacade.getAllCompanies, when I call store.load()


Sir,

My project was in ExtJs 2.2. It used DWR and Spring 2.0 and Java. Now we are trying to convert our old project to Extjs 3.0 with DirectJngine, Spring and Java. I created a mavan project, make changes in Ext.data.DirectStore,web.xml, all necessary JAR added.

In extjs_remote_methods/Api.js ( In console Script) I got like this.

Ext.namespace("Ext.app");
2Ext.app.PROVIDER_BASE_URL=window.location.protocol+"//"+window.location.host+"/"+(window.location.pathname.split("/").length>2?window.location.pathname.split("/")[1]+"/":"")+"djn/directprovider";
3Ext.app.POLLING_URLS={};
4Ext.app.REMOTING_API={url:Ext.app.PROVIDER_BASE_URL,type:"remoting",actions:{LoginFacade:[{name:"getAllCompanies",len:0,formHandler:false}]}};


My code as follows.

web.xml
********
<?xml version="1.0" encoding="UTF-8" ?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>

<!-- DirectJNgine servlet -->

<servlet>
<servlet-name>DjnServlet</servlet-name>
<servlet-class>com.softwarementors.extjs.djn.servlet.DirectJNgineServlet</servlet-class>

<init-param>
<param-name>debug</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>createSourceFiles</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>providersUrl</param-name>
<param-value>djn/directprovider</param-value>
</init-param>
<init-param>
<param-name>batchRequestsMultithreadingEnabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>apis</param-name>
<param-value>extjs_remote_methods</param-value>
</init-param>
<init-param>
<param-name>extjs_remote_methods.apiFile</param-name>
<param-value>extjs_remote_methods/Api.js</param-value>
</init-param>
<init-param>
<param-name>extjs_remote_methods.apiNamespace</param-name>
<param-value>Ext.app</param-value>
</init-param>
<init-param>
<param-name>extjs_remote_methods.classes</param-name>
<param-value>
com.bs.tg.login.facade.LoginFacade
</param-value>
</init-param>

<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>DjnServlet</servlet-name>
<url-pattern>/djn/directprovider/*</url-pattern>
</servlet-mapping>

Store
*****
Ext.ux.bs.login.CompanyComboStore = new Ext.data.DirectStore({
paramsAsHash : true,
directFn : LoginFacade.getAllCompanies,
root : '',
idProperty : 'value',

fields : [{
name : 'value'
}, {
name : 'label'
}],
});

Java
****
package com.bs.tg.login.facade;
import com.bs.tg.commons.Company;

public class LoginFacade {

@DirectMethod
public Collection<Company> getAllCompanies() throws NumberFormatException, Exception {

Collection<Company> companyList = new ArrayList<Company>();
Company company = new Company();

company.setName("HP");
company.setId(1);
companyList.add(company);

return company
}
}

When I called Ext.ux.bs.login.CompanyComboStore.load(), I got the error in console like this.
LoginFacade is not defined directFn : LoginFacade.getAllCompanies,

I am struggling with this error for the last 2 days. How to resolve this problem . Please help me ?

steffenk
15 Mar 2011, 5:27 AM
try with late binding in Ext.onReady, something like

Ext.ux.bs.login.CompanyComboStore.directFn = LoginFacade.getAllCompanies;

You have tu assure that the API was generated before you use it.

And please use code-tags arround your code!

sandeep.r
21 Mar 2011, 1:28 AM
Hi,
I tried all these things. In firebug I checked Api.js. It like this

Ext.namespace("Ext.app");
2Ext.app.PROVIDER_BASE_URL=window.location.protocol+"//"+window.location.host+"/"+(window.location.pathname.split("/").length>2?window.location.pathname.split("/")[1]+"/":"")+"djn/directprovider";
3Ext.app.POLLING_URLS={};

4Ext.app.REMOTING_API={url:Ext.app.PROVIDER_BASE_URL,type:"remoting",actions:{LoginFacade:[{name:"getAllCompanies",len:0,formHandler:false}]}};


Error is LoginFacade is not defined. I think script didn't get LoginFacade class in serverside.

In web.xml I put like this.

<init-param>
<param-name>extjs_remote_methods.classes</param-name>
<param-value>
com.bs.tg.login.facade.LoginFacade
</param-value>
</init-param>

I also tried this,
chrome://firebug/content/blank.gif
directFn : com.brainscript.tangram.login.facade.LoginFacade.getAllCompanies,

then I got the error : com is not defined

I didn't get the reason for this. Is it because of js didn't get LoginFacade class. Please help me


In java LoginFacade class I wrote the methode like this.

@DirectMethod
public Collection<Company> getAllCompanies() throws NumberFormatException, Exception {

return new ArrayList<Company>();
}