15 April 2011

Strange and annoying problem with {NOBR}

I wrote a web app about 10 years ago which used Javascript to pop up a hidden table when an input field gets focus. Each cell in the table contains a checkbox and text which are surrounded by a NOBR to keep them together.

Recently users with IE8 complained that the first cell is not visible when the table pops up. After MUCH trial and error I narrowed it down to the NOBR tag. I replaced it with a SPAN with style set to white-space : nowrap and this seems to solve the problem :-/

05 April 2011

Using 3rd party libraries in Silverlight

I downloaded a 3rd party library for a Silverlight app I am writing. When I ran the app I got an error message telling me to add

<loadFromRemoteSources enabled="true"/>

to 'devenv.exe.config' (Usually in 'C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE').

It seems you also need to edit the 'Blocked' property of the DLL.

See How to: Use an Assembly from the Web in Visual Studio for full details.

23 March 2011

Adding commands for menuitems in WPF

http://social.msdn.microsoft.com/Forums/en/wpf/thread/d93003e9-45e4-4b3d-a1af-45af92f1ef48

10 March 2011

RAP + BIRT on Websphere

I used the blog from Tim Pietrusky to get started: http://blog.tim-pietrusky.de/2009/rich-ajax-platform-rap/integrating-birt-into-rap-applications/

Perhaps I did something wrong but all the image links in the resulting HTML were broken. The URL to my dynamically-generated images was invalid. Even the examples from the RAP wiki showed the same problem.

In the end I decided to store my images under /rwt-resources/birt as I noticed that all the images from RWT are loaded from this address. I also changed the URL to use a context-relative address and not a fully-defined URL with host and port. On Websphere the result was an IP address and the port of the AppServer which was not accessible directly from the client.

I set the resources extension point as follows:

<extension point="org.eclipse.equinox.http.registry.resources">
  <resource
    alias="/resources/birt"
    base-name="/rwt-resources/birt">
  </resource>
</extension>


The modified View part looks like this (sorry about the formatting):


public class ChartView extends ViewPart {
public static final String ID = "com.acme.fair.views.ChartView";

private static final String reportName = "simplechart.rptdesign";
private static final String reportDirLocal = "/resources/birt/";
private static final String reportDirServer = "/rwt-resources/birt/";

private Browser browser;
private String reportDesign; // Full path to the local BIRT report file
private String URL;

private IReportEngine engine = null;
private EngineConfig config = null;
private IReportRunnable design = null;
private IRunAndRenderTask task;

@SuppressWarnings("restriction")
public void createPartControl(Composite parent) {
this.setPartName("BIRT in RAP");
browser = new Browser(parent, SWT.NONE);
configureURL();

try {
config = new EngineConfig();
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(config);

InputStream fs = null;
try {
URL url = Activator.getDefault().getBundle().getResource("/resources/birt/simplechart.rptdesign");
fs = url.openStream();
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}

design = engine.openReportDesign(fs);

// Create task to run and render the report
task = engine.createRunAndRenderTask(design);

// Set the dataset for the chart as report parameter
task.setParameterValue("CHART_DATASET", MesseSql.getFairsPerYear());

// Render the report to HTML
HTMLRenderOption renderOptions = new HTMLRenderOption();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
renderOptions.setOutputFormat(HTMLRenderOption.HTML);
renderOptions.setOutputStream(outputStream);

// Get the path to the local context directory to save the rendered
// chart image
String webAppBase = (ContextProvider.getWebAppBase()).replaceAll("\\\\", "/");
String path = webAppBase + reportDirServer + RWT.getSessionStore().getId();

// Handle the image path
renderOptions.setImageHandler(new HTMLServerImageHandler());
renderOptions.setImageDirectory(path);
renderOptions.setBaseImageURL(RWT.getRequest().getContextPath() + reportDirServer + RWT.getSessionStore().getId());

task.setRenderOption(renderOptions);
task.run();
task.close();

// Set the HTML output to the Browser widget
browser.setText(outputStream.toString());

engine.destroy();

} catch (Exception ex) {
ex.printStackTrace();
}
}

// Set the URL for the BIRT report for different environments.
private void configureURL() {

// Protocol, ip & port
ServletContext sc = RWT.getRequest().getSession().getServletContext();
String realPath = sc.getRealPath("/");
HttpServletRequest request = RWT.getRequest();
String protocol = "http://";
String ip = request.getLocalAddr();
int port = request.getLocalPort();
URL = protocol + ip + ":" + port;
String webAppName = "";

if (realPath == null) { // Start application locally within Eclipse
// (Windows)
reportDesign = URL + reportDirLocal + reportName;
} else { // Start application on a server (Apache Tomcat or so)
webAppName = sc.getContextPath();
reportDesign = URL + webAppName + reportDirLocal + reportName;
URL = URL + webAppName;
}
}

public void setFocus() {
}

/**
* Execute the given script, for example to print the

* content of the Browser
*
* @param script
* String to be executed
*/
public void executeScript(String script) {
browser.execute(script);
}
}

11 February 2011

RAP: Useful snippets

Just want to record some handy code snippets...

Save/Restore workbench state

In the Application WorkbenchAdvisor


/**
* set auto restore of workbench state
*/

public void initialize( IWorkbenchConfigurer configurer ) {
    getWorkbenchConfigurer().setSaveAndRestore( true );
    super.initialize( configurer );
}

10 February 2011

RAP: App suddenly stopped working

I edited the Preference feature in my app and could not start the app. I was getting the following error:

java.lang.IllegalArgumentException: no layout registered with default id (LayoutRegistry.DEFAULT_LAYOUT_ID) or no layout activated over branding extension.
at org.eclipse.rap.ui.interactiondesign.layout.ElementBuilder.<init>(ElementBuilder.java:96)
at org.eclipse.rap.internal.design.example.builder.DummyBuilder.<init>(DummyBuilder.java:23)
at org.eclipse.rap.internal.design.example.managers.CoolBarManager.<init>(CoolBarManager.java:140)
Turns out that the cookies have got themselves in a muddle and need to be deleted. I don't like to delete all my cookies so I (in IE8) opened Tools -> Internet options -> Browsing history -> Settings -> View files. This shows all the temp files. I sorted by last changed date and deleted the files which looked like 'Cookie@127.0.0.1'

Then it all worked again.

09 February 2011

RAP: First deploy to WebSphere

It didn't work first time but it didn't take too long to get the first results. This is what I did.

  • Ensure RAP WAR Products feature installed -- http://wiki.eclipse.org/RAP/Equinox_WAR_products
  • Create a new WAR Product Configuration in the plugin project. New -> Other... -> Plugin Development
  • Select parent folder, name the product and choose the lauch configuration
  • Open the WAR product file and enter an ID and Name
  • On the configuration page add the JARs used by the project
  • Return to the Overview page and select Validate
  • If necessary, add the missing plugins or JARs
  • Start the export wizard and enter the name of the output file. Press Finish.
  • The WAR file has now been exported
  • Open the Websphere Integrated Solutions Console
  • Create new Application Server. I called it RAP_TEST.
  • I had to modify a few ports because the defaults clashed with other App Servers
  • Install new Enterprise Application and enter the name of the WAR file
  • Accept all defaults and enter a context root such as /apps/rap
  • Finish
  • Might need to sync nodes etc but should now work
  • <servername>/apps/rap/fair?startup=fair (in my case)
So, my app kind of works. Unfortunately, the whole branding is missing so there are no images, styles etc. When I find the cause, I'll post more here.

Missing images problem

I set up a simple Tomcat server to check that it wasn't a WAS problem. I then noticed that there was an exception in the logs. Something to do with Jetty and an 'Address already in use' bind error. I was surprised that Jetty would be active on the Tomcat server so I checked my plugin dependencies. In the end I removed all the dependencies and added the 'Required plugins'. That seemed to cure the problem. After redeploying, there were no Jetty exceptions and I get the images which were missing.