May 18, 2012 - Google Earth Plug-in and the ATL 10.00

Comments


While playing with the Google Earth Plug-in to integrate in a WebBrowser control of a WPF application I'm currently developing, I started getting this strange background text instead of the map/earth: ATL 10.00.
ATL 10.00
I needed to do two things to get my page working. one simple thing.


Update:  It seems my previous method could still fail in some random times and even throw beautiful IE script errors, so here's what's really going on:

The WebBrowser control will by default, for compatibility reasons, render pages as in Internet Explorer 7 standards. The Google Earth plug-in seems to currently have some compatibility issues with IE7, therefore problems can arise. In this case, the ATL 10.00 stays above the map, blanking it.

The Fix
Use the most recent version of Internet Explorer. In order to do this, you must declare a meta tag in your HTML page like the following (this enables IE9 in WebBrowser when it loads the page):
<meta http-equiv="X-UA-Compatible" content="IE=9"/>


First, I used a workaround which consists in delaying the creation of the Google Earth plug-in, thus avoiding a race condition as mentioned in issue 701 from the earth-api-samples:


function Init() {
if (google.earth.isSupported()) {
// timeout is required or google earth plugin may get into a race condition and die
setTimeout("google.earth.createInstance('map3d', initCB, failureCB); alert('done');", 500);
}
}

/* other functions like initCV and failureCB */

google.setOnLoadCallback(Init);
google.load("earth", "1");


Second, I made sure the #map_canvas is above everything, especially during loading.


My application initially hides the WebBrowser. If I displayed the WebBrowser before the loading timeout, I could see the map alright... but if I waited longer than the loading timeout and then displayed the map, I just got the ATL 10.00.


So I thought, maybe the map is always being rendered but the ATL 10.00 layer is above it. I set #map_canvas the style z-index: -1 and it worked properly!


#map_canvas {
z-index: -1;
/* etc */
}


My JS scripts are simple and small and I cannot reproduce ATL 10.00 in native Internet Explorer (in my case IE9) because, I suppose, the map is always visible with positive dimensions (instead of what happens in my WPF application).

Useful links:

May 14, 2012 - Aligning contents of PrimeFaces' PanelGrid

Comments

If you are trying to align the contents of a panelGrid and nothing seems to work (styles that you define eventually don't appear in the rendered page) then this might help you.


This post covers a very specific case of alignment not working, and it depends on the following:

  • You are using the columns property in your panelGrid;
  • You are trying to define rows and columns manually, with <p:row> and <p:column>, because you probably want to use colspan or rowspan

Well, you probably checked the ShowCase of PrimeFaces to learn about PanelGrid. However, it is not clear in their example (neither in their Documentation) that when manually defining rows and columns, the total number of columns in the panelGrid should not be defined, i.e, the columns property should not exist. Their example is correct but doesn't make it clear that it should be exactly like that.

In conclusion, you cannot use the panelGrid like the following:
<p:panelGrid columns="2">
<p:row>
<p:column>
<h:outputText value="Hello"></h:outputText>
</p:column>
<p:column>
<h:outputText value="World"></h:outputText>
</p:column>
</p:row>
</p:panelGrid>

Useful links:

May 5, 2012 - EJB is null inside RESTful web service

Comments

While developing my enterprise application and learning Java EE at the same time, I came to a situation where injecting an EJB inside a RESTful web service class would be the same as nothing. The EJB variable was always null.

So, what did I change to fix this?
This was my source code before:
@Path("/mypath")
public class MyREST {

@EJB
private MyFacadeLocal myFacade;

public MyREST() {
}

@GET
@Produces("text/plain")
public String respond() {
return "DONE";
}
}
I forgot to tell the scope of the service. I managed to make it work by turning it request scoped (although from what I read it should be, by default, request scoped):
@RequestScoped
@Path("/mypath")
public class MyREST {

@EJB
private MyFacadeLocal myFacade;

public MyREST() {
}

@GET
@Produces("text/plain")
public String respond() {
return "DONE";
}
}

If I make it session scoped, I end up with the issue: Error creating managed object for class.

If I make it @Stateless, it also works properly and seems to be the recommended way:
@Stateless
@Path("/mypath")
public class MyREST {

@EJB
private MyFacadeLocal myFacade;

public MyREST() {
}

@GET
@Produces("text/plain")
public String respond() {
return "DONE";
}
}

Notice that MyFacadeLocal is actually an interface for the session bean (which doesn't have the @LocalBean annotation itself). If I want to directly inject the session bean (called MyFacade) I need to have the @LocalBean annotation in it. If not, the EJB inside the RESTful web service may not be properly deployed and the following error may appear:

java.lang.IllegalStateException: Exception attempting to inject Remote ejb-ref name=rest.MyREST/myFacade,Remote 3.x interface =ejb.MyFacade,ejb-link=null,lookup=,mappedName=,jndi-name=ejb.MyFacade,refType=Session into class rest.MyREST: Lookup failed for 'java:comp/env/rest.MyREST/myFacade' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}

Here's MyFacade without requiring an interface (assuming you'll be using it locally anyway):
@LocalBean
@Stateless
public class MyFacade extends AbstractFacade {
@PersistenceContext(unitName = "myjpaunit")
private EntityManager em;

@Override
protected EntityManager getEntityManager() {
return em;
}

public MyFacade() {
super(My.class);
}

@Override
public int count() {
return super.count();
}

@Override
public void create(My entity) {
super.create(entity);
}

@Override
public void edit(My entity) {
super.edit(entity);
}

@Override
public My find(Object id) {
return super.find(id);
}

@Override
public List findAll() {
return super.findAll();
}

@Override
public List findRange(int[] range) {
return super.findRange(range);
}

@Override
public void remove(My entity) {
super.remove(entity);
}
}

Another cause for having a null EJB is if, for any reason, an exception is thrown inside of it. Java EE will not inject it if running the EJB methods that are supposed to be called through the dependent object leads to exceptions. So, if you comment every call in your dependent object and then just check if the EJB is null, you'll see it isn't. But if you make use of a malfunctioning method, the EJB will just become null.
Useful links:
Glassfish embedded with JUnit for EJB testing