Ranch Hand
posted 9 years agoHi there, I'm newbie in jsf and need your help.
I have a h:form with several h:inputTexts and submit button. Pressing enter during filling a form causes the same action as submit button. But i need cursor to go to the next input field like using TAB key. I'm only able to disable enter key using a <h:form onkeypress='return event.keyCode != 13;'> expression.
Do you have some idea? Javascript or some jsf function?
I have a h:form with several h:inputTexts and submit button. Pressing enter during filling a form causes the same action as submit button. But i need cursor to go to the next input field like using TAB key. I'm only able to disable enter key using a <h:form onkeypress='return event.keyCode != 13;'> expression.
Do you have some idea? Javascript or some jsf function?
Ranch Hand
posted 9 years agoNobody? I've found this working solution (IE only):
<h:form onkeydown='javascript:if(window.event.keyCode 13) window.event.keyCode = 9;'>
but now, I need to use ENTER normally on submit button. I don't know why, but this solution:
onkeydown='javascript:if(window.event.keyCode 13 && window.event.srcElement.id !='btnSubmit') window.event.keyCode = 9;
throws javax.servlet.ServletException: null source
some suggestions?
<h:form onkeydown='javascript:if(window.event.keyCode 13) window.event.keyCode = 9;'>
but now, I need to use ENTER normally on submit button. I don't know why, but this solution:
onkeydown='javascript:if(window.event.keyCode 13 && window.event.srcElement.id !='btnSubmit') window.event.keyCode = 9;
throws javax.servlet.ServletException: null source
some suggestions?
Ranch Hand
posted 9 years ago. Type – If field passes “required” validation (if any), then JSF checks if string can be converted to expected type. Validators – If field passes required and type validation, then any explicit validators (see next section) are checked. Bypassing validation – As discussed in event-handling section, a button can use immediate='true' to bypass the above behavior. E.g. For event-handler button, or for “Cancel” button 28. EncodeAll(FacesContext) method added to, 146 JSF 1.2 tag handlers, use of. 8–9 JSF developer types, table of, 3–4 JSF EL syntax, using in the faces-config.xml file to. ViewID, 35 JSF view layer, function of, 12–13 JSFWeb application factory. For adding a label to each input field, 46 JSR-276: Design-Time Metadata for.
Problem is in &&, 'and' works normally. But now, it's submitted whenever I press ENTER.
![Input Input](/uploads/1/2/6/4/126478115/222751493.png)
Saloon Keeper
posted 9 years agoYou're better off using 'and', anyway. But your problem is in XML entities. Because the View is defined as an XML document, the 5 magic characters (& ', ', <, > usually need to be coded. So instead of '&&', you'd have to code '&&'. It's much easier to just say 'and'.
And you don't even want to know what I had to do to make the above display correctly! The CodeRanch edit/display feature has many of the same restrictions!
And you don't even want to know what I had to do to make the above display correctly! The CodeRanch edit/display feature has many of the same restrictions!
Being persecuted doesn't in any way prove your righteousness or your beliefs. Many people get persecuted because they are repugnant or annoying. Or just because they can be.
Ranch Hand
posted 9 years agoTim Holloway wrote:And you don't even want to know what I had to do to make the above display correctly! The CodeRanch edit/display feature has many of the same restrictions!
Thanks Tim, but I don´t understand.. display correctly what?
However, this method works completely (included in .js file):
function enter2tab(){
if(window.event.keyCode 13 && window.event.srcElement.id !='scrap:btnSubmit')
window.event.keyCode = 9;
}
<h:form onkeydown='enter2tab();'>
<h:commandButton value='save' type='submit' action='#{myScrap.saveNew}'/>
Saloon Keeper
posted 9 years agoI had to use XML entities on the 'magic' characters when editing that message to ensure that they would display properly.
However, your latest is mixing apples and oranges, I think.
If you put the javascript in a javascript file (apple), the XML rules don't apply to that file. In fact, they won't work. You have to say '&&'.
But JavaScript in an XML file (xhtml file, JSF View source. orange) does have to follow XML rules. Otherwise, it wouldn't be XML! So you usually have to do && or just code 'and'. Although I don't think 'and' works in JavaScript, just in EL.
However, your latest is mixing apples and oranges, I think.
If you put the javascript in a javascript file (apple), the XML rules don't apply to that file. In fact, they won't work. You have to say '&&'.
But JavaScript in an XML file (xhtml file, JSF View source. orange) does have to follow XML rules. Otherwise, it wouldn't be XML! So you usually have to do && or just code 'and'. Although I don't think 'and' works in JavaScript, just in EL.
Being persecuted doesn't in any way prove your righteousness or your beliefs. Many people get persecuted because they are repugnant or annoying. Or just because they can be.
Ranch Hand
posted 9 years agoStill don't understand.. 'and' (and maybe &_amp;&_amp; - aha here's the first restriction :-) works when I call it directly from jsf tag using onkeydown or onclick attributes.
But in the js file only && works. I've found only one solution which I've posted before....
But in the js file only && works. I've found only one solution which I've posted before....
Saloon Keeper
posted 9 years agoWell, the name of the game is to create JavaScript. If the javascript is in a JavaScript file, then it's already javascript and therefore usable 'as is'.
But a JSF xhtml View is an XML file. And, like I said, XML has a constraint on the '5 magic characters', because if you coded them directly, the XML parsers wouldn't be able to tell XML markup from data within the markup. For example:
Question: is the first double-quote the string terminator, or is the second double-quote the string terminator? OK, so that's easy to tell. For you. The CodeRaqnch syntax colorer obviously doesn't thing it's so simple. What if you have a whole FILE full of those puppies? Stack enough of them together and they start being readable in multiple (ambiguous) ways. So the proper usage is via the XML double-quote entity:
That way, no guesswork is involved. Since the Ampersand is the escape character, the Ampersand itself must be escaped, so that you don't end up trying to puzzle out stuff like the following:
And so forth.
Now, in some cases, the parser will cut you some slack. For example, you can usually use an apostrophe 'as is' within quotes without having to resort to its XML entity form. But if there's a chance of confusion, you won't be allowed that. And it's never wrong to do it anyway.
Since '&' is the escape character, you're pretty much required to use its entity form at all times.
As for the use of the word 'and' instead of '&&', like I said, I don't believe that 'and' is valid javascript. The confusion there is that 'and' is valid EL, and if you don't pay attention to context, you can confuse EL with javascript, since they're both java-like languages.
In JSF, however, the giveaway is that EL is delimited using the '#{}' construct.
What makes this even MORE fun is that you can have EL embedded within JavaScript! And I have, in fact. Basically, EL becomes a 'macro language' at that point, and the results of evaluating the EL subexpression(s) replaces the EL to form an ordinary text string, which is then interpreted as JavaScript.
And no, 'a #{&&} b' isn't legal. The double-ampersand is going to be interpreted as a binary operator, and there's no left and right terms of the expression that it would be applied to. 'a' and 'b' are outside the EL context.
But a JSF xhtml View is an XML file. And, like I said, XML has a constraint on the '5 magic characters', because if you coded them directly, the XML parsers wouldn't be able to tell XML markup from data within the markup. For example:
Question: is the first double-quote the string terminator, or is the second double-quote the string terminator? OK, so that's easy to tell. For you. The CodeRaqnch syntax colorer obviously doesn't thing it's so simple. What if you have a whole FILE full of those puppies? Stack enough of them together and they start being readable in multiple (ambiguous) ways. So the proper usage is via the XML double-quote entity:
That way, no guesswork is involved. Since the Ampersand is the escape character, the Ampersand itself must be escaped, so that you don't end up trying to puzzle out stuff like the following:
And so forth.
Now, in some cases, the parser will cut you some slack. For example, you can usually use an apostrophe 'as is' within quotes without having to resort to its XML entity form. But if there's a chance of confusion, you won't be allowed that. And it's never wrong to do it anyway.
Since '&' is the escape character, you're pretty much required to use its entity form at all times.
As for the use of the word 'and' instead of '&&', like I said, I don't believe that 'and' is valid javascript. The confusion there is that 'and' is valid EL, and if you don't pay attention to context, you can confuse EL with javascript, since they're both java-like languages.
In JSF, however, the giveaway is that EL is delimited using the '#{}' construct.
What makes this even MORE fun is that you can have EL embedded within JavaScript! And I have, in fact. Basically, EL becomes a 'macro language' at that point, and the results of evaluating the EL subexpression(s) replaces the EL to form an ordinary text string, which is then interpreted as JavaScript.
And no, 'a #{&&} b' isn't legal. The double-ampersand is going to be interpreted as a binary operator, and there's no left and right terms of the expression that it would be applied to. 'a' and 'b' are outside the EL context.
Being persecuted doesn't in any way prove your righteousness or your beliefs. Many people get persecuted because they are repugnant or annoying. Or just because they can be.
Ranch Hand
posted 9 years agoAha, I've got it. You're talking about differencies between XML based views and JavaScript character representing.
If I'm right, my javascript function is ok now and you told me why doesn´t work my previous post. && in jsf.
Thanks for your patience, If I'm not wrong, now I understand what are we talking about:)
If I'm right, my javascript function is ok now and you told me why doesn´t work my previous post. && in jsf.
Thanks for your patience, If I'm not wrong, now I understand what are we talking about:)