Default action on JSF pages (ie pressing enter on

2019-08-28 13:15发布

问题:

A HTML page is created using JSF and facelets (xhtml). There are 2 h:forms that goes to different places. The user enters data on one form and presses the "Enter" key. Here is where it gets tricky. On IE 6 and above, either the forms action gets submitted (which usually points to the page you are on) which then just reloads the page, or the first h:commandbutton/link that is on the page. Its totally random, but its consistant on that page.

Here is what I have tried, I tried placing the components that have to be submitted in their own form...it works but not everywhere. Then I tried creating a hidden input with the id of the button, it works quite effectively, but it is then bypassed somehow by IE trying to invoke the first button on the page. I tried a product called j4j that supposedly creates a default action, but it doesn't work, outputting the tag itself in the rendered HTML. When it does work, it creates javascript they looks for key 13, and then invokes oamsubmit(...., which incidently I tried also with varying degrees of success.

Is there a solution out there that work permanently? Have I missed something or am I not understanding JSF?

回答1:

This is how I solved it in JSF (just add this to your h:form)

<h:inputText id="StackOverflow1205114" value="Fix IE bug" style="{display:none}" /> 

which will create output to this:

<input id="_id3:StackOverflow1205114" type="text" name="_id3:StackOverflow1205114" value="Fix IE bug" style="{display:none}" />