commandLink and commandButtonand changing form target

We're observing some odd behaviour when using a <h:commandLink ...> in a form which also has normal Submit actions.

If our commandLink has a target="_blank" (for contextual help) this link works and brings up in a new window. But after that, all form submits using commandButton come up in a new window too.

<h:commandLink action="#{bean.help}" value="Help" target="_blank" />

...

<h:commandButton action="#{bean.submit}" value="Submit" />

Click Submit after clicking Help and it also brings up a new window, when it should have submitted to the same window.

The javascript that runs on commandLink set the target of theform to _blank until the page is re-rendered.

So then we modified the commandButton's behaviour with this hack:

<h:commandLink action="#{bean.help}" value="Help" taget="_blank"/>

...

<h:commandButton action="#{bean.submit}" onclick="this.form.target='_self'" value="Submit" />

Which was working until we tried it on Safari. In Safari, click Help and up comes a new window, then click Submit and it stays in the same window but runs the action #{bean.help}

Anybody come across this?

Many thanks,

Andy.

[1528 byte] By [dookkaa] at [2007-11-27 2:34:54]
# 1
Sounds like a bug in the generated JavaScript. Which JSF version?
BalusCa at 2007-7-12 2:52:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Sorry, Sun JSF RI 1.2_03-b09-FCS with facelets.I'll try with the later version, though changelogs don't mention this.
dookkaa at 2007-7-12 2:52:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Yes, I can confirm the first problem with 1.2_04-b07-FCS, though I won't be able to test Safari's behaviour for a while.My hack above works with IE6/Firefox/Opera9 on Windows.
dookkaa at 2007-7-12 2:52:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Can't you just try and use h:outputLink or a href? It looks like that it is actually an ordinary link to a help page without the need to do some business logic in the backing bean.
BalusCa at 2007-7-12 2:52:45 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

In this particular case the help page changes depending on whether we're creating or editing the application. I'll hard-code both urls in there as you suggest and render the correct one accordingly.

As a correction to Safari's behaviour, in both 1.2_03 and 1.2_04 it is actually invoking the correct action, but when that action returns null to indicate staying on the same page that's when it gets 'hijacked' by the previous commandLink's view.

I'll get some proper test cases and file a bug in both cases.

Thanks!

dookkaa at 2007-7-12 2:52:46 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...