Richfaces, IE-“runtime error” and nested forms

When developing a webapp with Richfaces, you will sometimes encounter a javascript “runtime error”. This error will only occur in MS Internet Explorer (seen at version 6/7).

I struggled and but then i found the reason and the solution. In Richfaces 3.3.2 CR1 there is some JS code in form.js, which tries to get all elements from the surrounding form. Like this

var field = form.elements[fields[i]]

This seems to fail only in Internet Explorer.
But why? I don’t know for sure, but it only occurs when you nest forms. Nesting of forms is invalid HTML, so it is not a bug in Richfaces. Check your UI structure instead.

<!--Not valid / never do this-->

Remember: NEVER ever nest forms into form.


window.print() does not work after JSF-Redirect in IE6

I wanted to present a button with an onclick-handler which invokes the browser printing dialog.

With simple code like this

            <button onclick="window.print();return false;">Print me</button>

It works in Mozilla Firefox 3.x and MS Internet Explorer 6, when the page is called directly. You can click the button, the dialog appears and everything is fine.

Issue 1: But when the page is the result of a JSF-navigation-rule-based <redirect/> the IE6 behaves in a strange way: You click on the button and nothing happens – no js-code is invoked. It works after a manual reload using the F5-key.

Issue 2: I figured out, that not even the following code works in IE6. After such a redirect.

<script type="text/javascript">
    	//your js-code here

Does anybody can reproduce the issues? And knows solutions for them?

Workaround for Issue 1:
Use self.print() instead of window.print(). This works in my usecase in FF3.x and IE6.

            <button onclick="self.print();return false;">Print me</button>