Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
rakeshsoni
Posts: 49
Registered: ‎06-02-2009
My Device: Curve8530, Curve8900, Storm9500

BrowserField2 : javascript redirect (window.location.href) issue

[ Edited ]

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

Developer
rakeshsoni
Posts: 49
Registered: ‎06-02-2009
My Device: Curve8530, Curve8900, Storm9500

Re: BrowserField2 : javascript redirect (window.location.href) issue

[ Edited ]

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>

 

 

Regular Contributor
lakhmapurkarvishal
Posts: 51
Registered: ‎01-13-2011
My Device: 9800
My Carrier: vodaphone

Re: BrowserField2 : javascript redirect (window.location.href) issue

Hi Rakesh,

 i am also getting same problem..

Is any one found that type of problems.

 

Thanx

vishal

Vishal Lakhmapurkar
Developer
simon_hain
Posts: 16,347
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: BrowserField2 : javascript redirect (window.location.href) issue

we have encountered this issue as well and found a solution for it.

implement a http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/browser/field2/BrowserFieldLis... on documentCreated set the focus on the browser field.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
lakhmapurkarvishal
Posts: 51
Registered: ‎01-13-2011
My Device: 9800
My Carrier: vodaphone

Re: BrowserField2 : javascript redirect (window.location.href) issue

Thanx for reply

But now it is giving me ilegalStateException on setFocus() method...

 

Vishal Lakhmapurkar
Developer
simon_hain
Posts: 16,347
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: BrowserField2 : javascript redirect (window.location.href) issue

use invokelater
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
lakhmapurkarvishal
Posts: 51
Registered: ‎01-13-2011
My Device: 9800
My Carrier: vodaphone

Re: BrowserField2 : javascript redirect (window.location.href) issue

Still i am getting ilegal state exception

Plz help me ..

Vishal Lakhmapurkar
Developer
rakeshsoni
Posts: 49
Registered: ‎06-02-2009
My Device: Curve8530, Curve8900, Storm9500

Re: BrowserField2 : javascript redirect (window.location.href) issue

I have also tried method invokelater() and acquireEventLock() to browserField.setFocus()

but still there is illegalStateException issue

Developer
hendrik
Posts: 63
Registered: ‎09-10-2009
My Device: Z10, Bold 9700
My Carrier: O2 Germany

Re: BrowserField2 : javascript redirect (window.location.href) issue

[ Edited ]

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.

----

My Twitter: @hendrik_dev
Regular Contributor
lakhmapurkarvishal
Posts: 51
Registered: ‎01-13-2011
My Device: 9800
My Carrier: vodaphone

Re: BrowserField2 : javascript redirect (window.location.href) issue

package com.mypckg.screen;

import org.w3c.dom.Document;

import com.mypckg.screen.KpiWebView.MyBrowserFieldListener;
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.BrowserFieldConfig;
import net.rim.device.api.browser.field2.BrowserFieldHistory;
import net.rim.device.api.browser.field2.BrowserFieldListener;
import net.rim.device.api.browser.field2.BrowserFieldRequest;
import net.rim.device.api.browser.field2.ProtocolController;
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_ENABLED, Boolean.TRUE);
          b = new BrowserField(_config);
          b.addListener(new MyBrowserFieldListener());
         ProtocolController p = new MyProtocolController(b);
         b.getConfig().setProperty(BrowserFieldConfig.CONTROLLER, p);
         b.getRenderingOptions().setProperty(RenderingOptions.CORE_OPTIONS_GUID,RenderingOptions.JAVASCRIPT_LOCATION_ENABLED, true);
          
                
              
       
        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) {
                  
                      
        }   
};                          
         
    }

}   



Vishal Lakhmapurkar