09-09-2011 11:25 AM - edited 09-09-2011 11:28 AM
I am creating an application where loading html content in browserField2 from server. and everthing is working fine
and this is the sample code
BrowserFieldConfig _config = new BrowserFieldConfig();
_config.setProperty( BrowserFieldConfig.JAVASCRIPT_ENABLED , Boolean.TRUE );
b = new BrowserField(_config);
ButtonField b2 = new ButtonField("fault");
b2.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
url = "http://myserver/Test.html";
b.requestContent(url);
}
});
add(b2);
add(b);
}
--------------------------------------------------
but the issue is that when server javascript redircting the page on another site the browserField2 throw the "illegalStateException".
------------------------------------------------
http://myserver/Test.html content
-----------------------------------------------
<html>
<head>
<script type="text/javascript">
window.location.href = "http://www.google.co.in";
</script>
</head>
<body>
</body>
</html>
Please help me to solve this strange issue. it is urgent. also i can not modified the server html page or script
( if I remove the window.location.href = "http://www.google.co.in" in script then page content display properly.)
Thanks in advance
09-12-2011 01:10 AM - edited 09-12-2011 01:13 AM
Can anyone help me on this ?
OR this script will not work in case of blackberry borwserField2
<script type="text/javascript">
window.location.href = "http://www.google.co.in";
</script>
09-12-2011 08:17 AM
Hi Rakesh,
i am also getting same problem..
Is any one found that type of problems.
Thanx
vishal
09-12-2011 08:22 AM
09-12-2011 09:53 AM
Thanx for reply
But now it is giving me ilegalStateException on setFocus() method...
09-12-2011 09:57 AM
09-13-2011 01:41 AM
Still i am getting ilegal state exception
Plz help me ..
09-13-2011 03:14 AM
I have also tried method invokelater() and acquireEventLock() to browserField.setFocus()
but still there is illegalStateException issue
09-13-2011 03:43 AM - edited 09-13-2011 03:44 AM
I have experienced the same problem with the BrowserField. The workaround using the BrowserFieldListener is correct, but when I used it I had to put the setFocus() call into invokeAndWait() in order to a) have it executed on the event thread and b) have it executed before documentCreated() returns.
09-14-2011 02:33 AM
package com.mypckg.screen;
import org.w3c.dom.Document;
import com.mypckg.screen.KpiWebView.MyBrowserFieldListen
import com.mypckg.util.Logger;
import net.rim.device.api.browser.field.RenderingOptions;
import net.rim.device.api.browser.field.RenderingSession;
import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.browser.field2.BrowserFieldConf
import net.rim.device.api.browser.field2.BrowserFieldHist
import net.rim.device.api.browser.field2.BrowserFieldList
import net.rim.device.api.browser.field2.BrowserFieldRequ
import net.rim.device.api.browser.field2.ProtocolControll
import net.rim.device.api.script.ScriptEngine;
import net.rim.device.api.system.Backlight;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;
public class TestScreen extends MainScreen
{ String url="";
BrowserField b;
public TestScreen()
{
BrowserFieldConfig _config = new BrowserFieldConfig();
_config.setProperty(BrowserFieldConfig.JAVASCRIPT_
b = new BrowserField(_config);
b.addListener(new MyBrowserFieldListener());
ProtocolController p = new MyProtocolController(b);
b.getConfig().setProperty(BrowserFieldConfig.CONTR
b.getRenderingOptions().setProperty(RenderingOptio
ButtonField b2 = new ButtonField("Got exception to load this URL:http://na3.salesforce.com/0065000000GI8nqAAD");
b2.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
url = "http://na3.salesforce.com/0065000000GI8nqAAD";
b.requestContent(url);
}
});
add(b2);
add(b);
}
class MyBrowserFieldListener extends BrowserFieldListener{
public void documentLoaded(BrowserField browserField, Document document)
throws Exception {
//here some code to handle loaded event
super.documentLoaded(browserField, document);
}
public void documentCreated(BrowserField browserField,
ScriptEngine scriptEngine, Document document) throws Exception {
UiApplication.getUiApplication().invokeAndWait(new Runnable() {
public void run() {
b.setFocus();
}
});
super.documentCreated(browserField, scriptEngine, document);
}
}
class MyProtocolController extends ProtocolController
{
BrowserField _browserField;
// constructor
MyProtocolController(BrowserField bf2){
super(bf2);
_browserField = bf2;
}
public void handleNavigationRequest(BrowserFieldRequest request) throws Exception {
try {
super.handleNavigationRequest(request);
} catch (Exception e) {
}
};
}
}