How to make Enter Key Press behave like Submit in JSF. It works with InputBoxes; but not with inputSecret boxes
I haven't seen this issue before. The chance is little that this behaviour is browser specific. Try in different kinds of browsers to exclude the one and other (IE6/7/8, FF, Safari, Chrome, etc). The chance is bigger that this is caused by a (poor) Javascript key event listener which incorrectly suppresses the enter key (for example a JS password validator which checks the entered characters).
If still in vain, just add the following onkeypress to the h:form:
<h:form onkeypress="if (event.keyCode == 13) this.submit();">
You need to take textareas into account however. If you have them, then you need to copy all onkeypress events over the h:inputXXX elements expect of textareas yourself.
If you want to press ENTER key instead of submit in any form, what we have to do here is add defaultcommand attribute in af:form tag and give id of the submit button as value. Sample code snippet for this is
<af:form id="f1" defaultCommand="cb1">
<af:outputText value="User Name" id="usename"/>
<af:inputText value="#{BackingBean.userName}" id="uname" />
<af:outputText value="Password" id="pword"/>
<af:inputText value="#{BackingBean.password}" id="paword" secret="true"/>
<af:commandButton text="Submit" action="#{BackingBean.method}" id="cb1" />
</af:form>
I made it work by placing an additional inputBox and hiding it using javascript. Let me know if you have any other suggestions
Thanks baluC for pointing me in the right direction
Jerry
tested with jsf 2. put:
<h:commandButton id="hidden" style="visibility: hidden;" action="#{mybean.myaction()}" />
in your form
From ComputerPilot's answer I came to know that it's bug in IE which wouldn't make the parent form to submit if there's only one input element. To overcome this problem I added one more input Box with attribute style="display:none" and it worked fine.
There is an old specification that pops into my mind with this one. If you have a form that contains just one input field, the behaviour of submitting on the enter-key doesn't work in some versions of Internet Explorer. The easiest fix is to make sure you have more than one input field.
Other reasons for this problem include...
Not having an input of type submit
Having an input of type submit, but it isn't visible on the page (hidden or positioned off-page)
This behaviour is very specific to this browser.
MS Bug Report Here: connect.microsoft.com: submit button value not posted with form submission
Related
Currently, i am dealing with rich:tabPanel in my web application based on JSF 2.0.
I encounter a very strange problem, which is related to my richface component.
Basically, i print some same stuff on each panel (here, it is a schedule table of a show, tab contains the day and content of tab contains the differents hours ).
Consequently, i have something like that:
<rich:tabPanel>
<c:forEach items="#{show}" var="hour" ...>
<rich:tab>
<a4j:commandLink ...>
<a4j:param value="hour.something" assignTo="#{bean.method}" />
</a4j:commandLink>
</ ..... >
When i click on the first commandlink, when my webpage is displayed, it's ok. But when i choose an other tab, and i click on the commandlink, the "bean.method" is not call. I need to click a second time to make the call of the function.
Finally, when i put the tabPanel as "switchtype=server", it works very well (without clicking 2 times).
But that's not the purpose, i want to use the client mode.
I see that on JIRA of richfaces v3, this problem has been solved JIRA JBoss. But there is no more information (except a comment but it's not working).
If anyone can help, it would be great.
Regards,
The problem is you are using nested forms(form within form). This is not recommended in JSF. Even in HTML it is invalid. Remove one form and it will work.
Read this post too.
I was wondering if there is a way to make an easy keyboard shortcut in my JSF page
each page has several buttons and I would like to be able to have a user press something like alt+a to activate a button called 'Add Report to Group'
in .net you just put an & before the letter you want to be the shortcut key, is there an option like this in JSF (apart from writing some javascript code which is what I found on the web)
Use the HTML-provided accesskey attribute which is also mapped in <h:commandButton> and <h:commandLink>.
<h:commandButton value="Add" accesskey="a" action="#{bean.add}" />
This button can then be invoked by Alt+A or Shift+Alt+A, depending on the browser used.
I want to render using Richfaces a context menu on left click on a link-appearing text (blue text, and underline and cursor onmouseover). So, imagine a link which when clicked shows a context menu. Note that I don't care if the text is indeed a link, I just want it to appear as a link. So, even normal text would be fine, I would make it appear as a link using CSS.
I have the following conditions:
The context menu must appear on client side, without making a request.
The context menu must appear using a rich:componentControl (these "links") are inside a datatable, so the same rich:contextMenu must be re-used.
I still have not found a satisfactory solution, as each approach I have tried has caused a problem for me:
If I use h:outputText (that would be ideal), I cannot attach on it a rich:componentControl (I guess because it cannot fire an onclick event).
If I use a4j:commandLink, although I can attach a rich:componentControl, it makes a server request. I tried to add onclick="return false;" to prevent the request, but Richfaces adds the JS generated by the rich:componentControl after whatever is inside the onclick, which causes this code not to be reached at all, and of course the context menu not to appear at all.
Is there any way to do this? Please remember, no request!
You may try
<rich:componentControl disableDefault="true" ...>
According to documentation with this param componentControl should add return false; itself.
But be aware of corresponding bug: RF-5607
In case documentation lies you may use html anchors. This answer shows how to create a link with componentControl and without page refresh:
<h:outputLink value="#" id="link" onclick="return false;">
<h:outputText value="Link text"/>
<rich:componentControl attachTo="link" for="panel" operation="show" event="onclick"/>
</h:outputLink>
The onclick="return false;" prevents the anchor from scrolling the page to the clicked link.
This is the submit button:
<h:commandButton
actionListener="#{regBean.findReg}"
action="#{regBean.navigate}" value="Search" />
This is the form:
<h:form onsubmit="this.disabled=true;busyProcess();return true;">
If the submit button is pressed, the page shows a "busy" icon until request is processed. The problem is, the form is never submitted and the request never reaches the backend. However, if I instead take out the "disabled" call like so:
<h:form onsubmit="busyProcess();return true;">
Then everything works. Any ideas?
JSF relies on the presence of the name-value pair of the submit button to invoke a specific action in the server side. If you disable the form (at least, the button) before submitting the form, then no information will be available in the request parameter map and JSF will not invoke any action.
Your best bet is to introduce a timeout wherein you disable the button about 50ms after submitting. E.g.
onsubmit="setTimeout(function(){document.getElementById('formId:buttonId').disabled=true;},50);busyProcess();"
The explicit return true; at end is by the way superflous. Also, disabling the the HTML form element directly ain't going to work since it doesn't have a disabled attribute, you want to disable the button (and if necessary the other input elements as well).
Here's some improvement:
<h:form onsubmit="busyProcess(this);">
with
function busyProcess(form) {
setTimeout(function() {
for (var i = 0; i < form.elements.length; i++) {
form.elements[i].disabled = true;
}
}, 50);
// Remnant of your code here.
}
Update: since I wondered that you told that it "works", I tested the form's disabled attribute in various browsers, it only works in MSIE (surprising..), but not in the other (real) browsers. You don't want to be browserdependent, so forget it and go ahead with disabling the form's individual elements.
Change this.disabled = true into [buttonref].disabled = true
I'm pretty sure that disabling the whole form will mean to the browser that you don't want it to be submittable. When you disable individual input elements, those aren't included in the parameters sent to the server when the form is posted.
You've disabled the entire form, you need to disable just the button instead.
Also you will want to ensure that your busyProcess() returns a truthy value or the submission could be disabled as well.
if you want the user not to submit anything, let a layer appear above the form and remove the focus from the active component.
Another way would be to make sure the AJAX requests use a common channel that has a queue in which only one request is processed at a time (easy using frameworks like prototype etc)
BalusC, your very creative timeout option works well. I actually came to the same conclusion when I tried the "disabled" attribute in other browsers. It didn't disable the form at all in Opera and Firefox. I just chalk it up to those browsers being more versatile than IE.
Sean K, disabling the button only without setting a timeout produces the same issue as the form disable, as info is passed to the server.
Thanks for all your help guys!
I'm trying to fill-out a form automatically and press a button on that form and wait for a response. How do I go about doing this?
To be more particular, I have a a --HUGE-- collection DNA strains which I need to compare to each-other. Luckily, there's a website that does exactly what I need.
Basically, I type-in 2 different sequences of DNA and click the "Align Sequences" button and get a result (the calculation of the score is not relevant).
Is there a way to make a Java program that will automatically insert the input, "click" the button and read the response from this website?
Thanks!
You can use the apache http client to send a request to a web site.
Look at the source to the page in question, and you'll find the part. This contains all the fields that need to be sent to the server. In particular, you'll see that it needs to be sent as a Post, rather than the more common Get. The link above shows you how to do a post with the http client code.
You'll need to provide a nameValuePair for every field in the form, such as these ones:
<input type="hidden" name="rm" value="lalign_x"/>
<input type="checkbox" name="show_ident" value="1" />
<textarea name="query" rows="6" cols="60">
It will probably take some trial and error for you to get all the fields set up correctly. I'd recommend doing this with small data sets. Once it all seems to be working, then try it with your bigger data.
In Python you can use mechanize library (http://wwwsearch.sourceforge.net/mechanize/). It's quite simple and you doesn't need to know Python very well to use it.
Simple example (filling login form):
br = Browser()
br.open(login_link)
br.select_form(name="login")
br["email"] = "email#server.com"
br["pass"] = "password"
br.submit()
You could probably do this using Selenium.