вторник, 16 ноября 2010 г.

Share smartgwt js over several gwt modules

When you create smartgwt module you have the following lines in your *.gwt.xml file:

...
<inherits name="com.smartgwt.SmartGwt"/>
...

Everything works fine. When you load your module at the first time, the browser gets all smartgwt js libs(ISC_*.js) and caches it. In our application we have got five gwt modules and all of them are using smartgwt. And when we load each module for the first time, it is getting 2 MB of js files. For our five modules browser downloads over 10 MB of smartclient libs. That's too much! To solve this problem I discover SmartGwt.gwt.xml. It inherits from module that called SmartClientDefault:


<module>
<script src="sc/modules/ISC_Core.js"/>
<script src="sc/modules/ISC_Foundation.js"/>
<script src="sc/modules/ISC_Containers.js"/>
<script src="sc/modules/ISC_Grids.js"/>
<script src="sc/modules/ISC_Forms.js"/>
<script src="sc/modules/ISC_RichTextEditor.js"/>
<script src="sc/modules/ISC_Calendar.js"/>
<script src="sc/modules/ISC_DataBinding.js"/>
</module>

And that's our problem. All js have relative paths. But Smartgwt has wonderful module that called SmartGwtNoScript that does not have a dependence on SmartClientDefault and we can include all scripts using absolute paths!
The solution is to replace inherits from com.smartgwt.SmartGwt by the following code in all modules that need smartgwt(or create one root module):


<inherits name="com.smartgwt.SmartGwtNoScript"/>
<script src="/mod/sc/modules/ISC_Core.js"/>
<script src="/mod/sc/modules/ISC_Foundation.js"/>
<script src="/mod/sc/modules/ISC_Containers.js"/>
<script src="/mod/sc/modules/ISC_Grids.js"/>
<script src="/mod/sc/modules/ISC_Forms.js"/>
<script src="/mod/sc/modules/ISC_RichTextEditor.js"/>
<script src="/mod/sc/modules/ISC_Calendar.js"/>
<script src="/mod/sc/modules/ISC_DataBinding.js"/>

4 комментария:

_rootnode комментирует...

Hi, I am developing a small scale app using smart-gwt 2.4. I have 2 pages in my app. Initially, the details that the user enters in page 1 is used to fetch data that has to be displayed in page 2 and from then on, any change that has to be made can be made in page 2 itself. If required, the user can navigate back to page 1. In that case, previously entered data should be populated.
1) Now, how do i navigate between pages. i have defined these pages as two separate modules. I wil need to pass data from page 1 to page 2. Is there an efficient way to do this?
2) In one of my pages i have defined two autocomplete combo boxes. data for one of the combo boxes will be fetched on load and the data for the second one depends on the value of the 1st combo box. I tried adding change and changed event listeners for the 1st combo box but both of the events are getting fired for every letter type. [once for C, A and T if im trying to search CAT. Tried setting setChangeOnKeypress(false) ] I need to fetch data once the user selects the full value ‘CAT’.
Any help will be really useful.

dimka комментирует...

Hi, karthick_r!

1) Yes, you can navigate over modules by change location in browser:
Window.replace("urlOfYourModulde?param1=value&param2=value");
But, when you have more than one modules, you should place it in one place, if not browse can not cache it.

2)Maybe ComboBoxItem.setAddUnknownValues(false) helps you

_rootnode комментирует...

Hi,
thanks for the reply.
I tried setting the setAddUnknownValues to false. in that case, the value which i selected from the drop down gets cleared as and when the control loses focus. My problem, the event corresponding to the 1st combo box should fire when the user selects a valid value, so that i will fire a RPC call to fetch the values for the 2nd combo box based on the 1st selected value.
Also, i fixed the 1st issue by using Window.location.assign(*.html).
Are there any benefits/pitfalls of this page based approach. I am a newbie to smart gwt. any help will be useful.

dimka комментирует...

Hi!

I had this troubles with combo box, too. To solve it, I check value in changed handler(I have the special format of this value). In my case, value and text was different and if user type something in combo box then I see typed text as value and if user select some item I see value of this item(not text).

Most popular

Authors