Joshua van Aalst’s blog

June 29th, 2007

Netbeans 5.5.1 Visual Web Pack ‘webui’ is undefined javascript solution/fix.

Posted by Joshua van Aalst in Java and Web Development, Netbeans

Hi everyone,

I recently upgraded from Netbeans 5.5 to Netbeans 5.5.1 and noticed that some of my Visual Web Pack pages were rendering with the javascript error ‘webui’ is undefined.

If this error occurs most UI components on the page will cease to function.

Basically some new javascript libraries were added to Netbeans 5.5.1 and all components require them but some pages were not generating the required javascript code.

So what is required to fix this?

Ensure the following lines are at the top of the Visual Web Pack page that is causing the ‘webui’ is undefined error:

dojo.hostenv.setModulePrefix("webui.suntheme", "http://www.joshandfriends.com.au/dancemusic//theme/com/sun/webui/jsf/suntheme/javascript");
dojo.require('webui.suntheme.*');

]]>

Obviously change the domain above to your own.

If you would like a simpler way of doing the above that is dynamic and can be reused on any page with the issue then create a converter like so:

package com.jafp.web.jsf.converter;

import com.jafp.common.configuration.SystemConfiguration;

import org.apache.log4j.Logger;

/**
*
* @author Joshua van Aalst
*/
public class DojoJsConverter implements Converter
{

public String getAsString(
FacesContext context,
UIComponent component,
Object object)
throws ConverterException
{
try
{
Logger.getLogger(getClass()).debug(”Start DojoJsConverter”);
ResponseWriter writer = context.getResponseWriter();

writer.startElement(”script”, component);
writer.writeAttribute(”type”, “text/javascript”, “type”);

writer.writeText(”\ndojo.hostenv.setModulePrefix(\”webui.suntheme\”, \”"
+ SystemConfiguration.getSystemConfiguration().getApplicationPath()
+ “/theme/com/sun/webui/jsf/suntheme/javascript\”);\n”, “dojoscript”);
writer.writeText(”dojo.require(’webui.suntheme.*’);\n”, “dojoscript”);

writer.endElement(”script”);

Logger.getLogger(getClass()).debug(”End DojoJsConverter”);
return “”;
}
catch (Exception e)
{
throw new ConverterException(”Unable to generate a link for supplied object”, e);
}
}

public Object getAsObject(
FacesContext context,
UIComponent component,
String displayString)
throws ConverterException
{
return 3;
}

}

Now you can simply do this:

]]>

You can of course simplify this further by adding all .js includes to your converter. Then all you will have is 1 line:

]]>

Leave a reply

You must be logged in to post a comment.