In a Java web project we are using PrimeFaces 4.0 as a JSF extension. Now we ran into a problem with the Spinner (p:spinner) component in PrimeFaces. We embedded the spinner in our own custom tag to set some defaults such as the stepFactor and the locale. The body of the JSF tag looks like this:
<p:spinner id="#{id}" value="#{value}" min="#{min}" max="#{max}" stepFactor="0.1" size="5" onchange="#{onchange}" >
<f:convertNumber pattern="#0.00" locale="de_DE"/>
</p:spinner>
This works fine as for the binding and the rendering of the component. In the following screenshot you see a float 2.6f that was set and properly formatted in the "de_DE" locale (with a comma instead of a dot as the decimal separator).
However, when the user uses the spinners buttons to change the value the formatting immediately gets wrong. The value is even parsed wrong from the component. In the next screenshot you can see the very same spinner once we clicked the "up" button once. Which should actually result in a value of "2,70" being displayed in the component.
Has anybody else had similar problems like this before?
Is there a standard fix to the JavaScript handling the p:spinner component that we can apply here or do we really need to dig into PrimeFaces JS library and fix this on our own?
f:convertNumber is a server-side conversion. The event of incrementing and decrementing the value is JavaScript, the f:convertNumber won't be taken into consideration until the value goes back to server, therefore an ugly JavaScript solution should be done.
I have created a patch for this problem and I used Number.prototype.toLocaleString() to convert the number into a localized version.
All you have to do is include pf.spinner.local.fix.js and set your preferred locale in the following way (in document.ready):
PF('spinnerWidgetVarName').cfg['local'] = 'de-DE';
There are a couple of notes to be taken:
Number.prototype.toLocaleString()
This patch is tested and confirmed on PrimeFaces 5.0 and 4.0
Here's a small example on github and a Demo
Seems like Primefaces Spinner does not support I18N.
A forum message asking to support locales has been posted since 2010 without any answer : http://forum.primefaces.org/viewtopic.php?f=3&t=6398
A possible solution would be to use Primefaces' Extension component timePicker and customize it to manage your value.
See : http://www.primefaces.org/showcase-ext/sections/timePicker/basicUsage.jsf;jsessionid=7axadfz6by4g1787ncndsf12d
And : https://github.com/primefaces-extensions/primefaces-extensions.github.com/wiki/PrimeFaces-Extensions-Locales
Or you could try to mess with JS...
Related
Pic1
Pic2
Pic3
Hi, I'am new at js. I'am using VSCode. My problem is suggestions. I dont know it's true name maybe not suggestions maybe it's intellisense but When I pick an element with DOM and want to change it's style component, I wrote element.style but there aren't any suggestions showing up you can see in first two pics. But if I write element.style. there are some suggestion showing up. While on chrome dev console if I write elemnt.style
pic4
It shows me the style component. So how can I active it suggestions on visual studio code , like google console? I have some extensions is that cause problems?
extensions
VSCode is using static code analysis to try and guess what the types of your variables are. It has to do this because JavaScript is dynamically typed, so there is no way to be certain of the type of any given variable while you're writing the code. The JavaScript plugin for VSCode uses various heuristics to try and prove useful feedback.
Chrome actually evaluates the expressions you're typing as you type them, against a real DOM and JS runtime, and provides accurate feedback by reflecting on the value of each expression.
You can't make VSCode's static analysis behave like Chrome's dynamic reflection. They are very different systems, and this is a fundamental limitation of code-completion/intellisense for dynamic languages.
I'm writing some automated test scripts using Python (2.7) with Selenium RC (2.42.1) for a page that contains multiple tinymce controls (2 to be precise). The code that I've been using up to date looks like the following:
sel.focus( field_values[ id_value ] + "_ifr" )
sel.get_eval( "window.parent.tinyMCE.activeEditor.setContent('<p>" +
field_values[ test_data ] + "</p>');" )
To date, this code has worked fine for me, but after a recent build, I have been having issues when there are multiple copies of the tinymce control on the page. The setContent() function seems to always want to send the text to the second tinymce control, regardless of which ID I set the focus() to. And as a wonderful caveat, if I shrink my window frame so only the first tinymce control is visible on the screen, then only the first tinymce control gets sent any text.
My going theory right now is that the .activeEditor is not pointing to the right tinymce control when I set my content. It seems to always point to the last visible tinymce that it sees on the screen so I'm trying to find a way to force the focus to the appropriate tinymce control.
My question is, is there a better way to force the focus to the correct tinymce control using Python Selenium? I've tried using sel.click("tinymce") and sel.type_keys("tinymce","") after setting the focus(), but they don't seem to work.
I confirmed with the development team that no changes were made to the tinymce control, and I'm using the same Selenium RC version as always.
And I don't know if this will help, but there has been a push to move our automated testing over to a C# framework. We had the same issue as with the Python code, but we came up with a solution for that:
driver.SwitchTo().Frame(iWeb);
// This was added to ensure the tinymce control edit area has focus. This is necessary for pages that have multiple tinymce controls.
IWebElement body = driver.FindElement( By.TagName( "body" ) );
body.SendKeys( "" );
driver.Execute("window.parent.tinyMCE.activeEditor.setContent('" + Test_Data + "');");
driver.SwitchTo().DefaultContent();
I want to be able to do the same thing, but with the Python code.
I finally found the reason why I could no longer handle multiple instances of TinyMCE controls on the same page. I recently had to rebuild my machine due to hardware problems, and in the process, I updated my Firefox browser to the latest ESR release (24.7.0). I rolled back to v24.2.0 with no issues. It seems there must have been a security update that was causing the unusual behaviour with my automated code. I'm still researching what updates were made and if it's actually possible to write to multiple TinyMCE's with the latest ESR version of Firefox.
I'm looking into turning my AngularJS application to be compatible with IE8 and I'm getting this popup confirmation error:
Now, I want to get more details about this - like what file & line caused this to invoke.
I've google it and I understand that it appears in a different occasion based on which browser is running.
I'd like to get more details about the script that caused this popup to invoke (specifically in IE8).
IE8 makes this warning based on the number of statements and not based on the time the scripts are taking to run. This warning in my opinion is inaccurate.
By default threshold limit for the time-out dialog box is 5,000,000 statements.
Microsoft released a patch to correct this: http://support.microsoft.com/kb/175500
Please note that microsoft also indicates that which is the registry entry to increase this to any level if necessary:
Using a Registry Editor such as Regedt32.exe, open this key:
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Styles
Note If the Styles key is not present, create a new key that is called Styles.
Create a new DWORD value called "MaxScriptStatements" under this key, and set the value to the desired number of script statements.
If you are not sure about which value you need to set this to, you can set it to a DWORD value of 0xFFFFFFFF to avoid the dialog box.
When I faced this same problem with Angular/IE8 what I ended up doing was to reducing the size of the objects and "re-architecting" the app along with applying the patch above. I think this is part of the limitation of supporting IE8.
Our application was using Kendo, JQuery and Angular and we find out that the error could occur at any 'given' time in any 'given' library part of our re-architecting was using lighter UI-Frameworks as well and more custom specific controls only when it was strictly necessary.
Hope it helps and sorry to hear that you are also supporting IE8 :D
I can't get Netbeans to auto-complete my selectors for JQuery, example:
<a id="hello" href="#">Hello</a>
<script type="text/javascript">
$("|").hide();
</script>
As far as i understand the documentation at this point it should show the tags available on the page when i press control+space at the | position, but instead displays no suggestions. Links [1] and [2] shows clearly that this has been implemented. I have not tried prototype, link [2] shows that JQuery support has been added as well.
The auto-complete of functions works perfectly, with the embedded library of JQuery 1.4.2, it is only the selector auto-complete that does not work. Any suggestions?
[1] http://wiki.netbeans.org/JavaScript#Embedded_Completion
[2] http://wiki.netbeans.org/JavaScript#Recently_Added
Product Version: NetBeans IDE 6.8 (Build 200912041610)
Java: 1.6.0_18; Java HotSpot(TM) Client VM 16.0-b13
System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)
5 years later update:
As of at least version 8.0.2 Netbeans now properly auto-completes jQuery selectors in both php and html pages. I am unsure if this is due to some other changes on the editor engine or they finally caught the discrepancy but either way it works now, yay!
Naor answer made me rethink what I was doing, but it didn't quite answer my question. So let me provide the solution I found in case anyone is interested.
When working with netbeans, the auto-complete function behaves differently between php files and html. In html jquery selectors auto-completes as expected. But when trying to do the same within a php file in an html section of code, it will fail to auto-complete.
Just make sure that if you are expecting this feature to work, that you are using html files, not php. I will submit this as a feature/bug to the netbeans guys, hopefully they can fix it and make html/js auto-completion available to all file types that can include html/js code.
Link 1 says that there is code completion on element ids that appear in the html itself. They also say that it works with Prototype.js. I believe that it would work for jquery too, but don't forget - in order to select an element using it id in jquery you do $('#id') - with #.
What they meant in their example if you have $("f|") is that if you start writing $("f and the cursor of typing is after the f (they put "|" in order to mark the cursor), then code completion should show all relevant elements.
Try that:
in html: <div id="blabla">12345</div>
in jscript: $('bl');
after the bl press control+space, and I believe that it will display to you blabla.
Update: this question is bunk. Move along, nothing to see here. You can set the value of the password text field from either JS or ObjC. I was wrong.
I have a WebKit-based Cocoa app which loads an HTML document containing an HTML form in a WebView. The HTML form contains a password text field like:
<form name="foo">
<input type="password" name="bar">
</form>
I'd like to set the value of this text field programmatically (from Objective-C if possible, but I'll do whatever works).
I believe WebKit (and every other modern browser) implements a JavaScript security feature which prevents JS scripts from setting this value programmatically.
Unfortunately, it seems that the same security restriction applies to Objective-C, as I can't seem to set the value using ObjC either. While the JS restriction is reasonable, the ObjC seems a bit unreasonable.
Is there any way to programmatically set the value of this field (short of bundling a custom WebKit in my app that has been altered to allow this)? I'm open to any suggestion.
Here's what I've tried in ObjC:
DOMHTMLDocument *doc = (DOMHTMLDocument *)[webView mainFrameDocument];
DOMHTMLFormElement *formEl = (DOMHTMLFormElement *)[[doc forms] namedItem:#"foo"];
DOMHTMLInputElement *inputEl = (DOMHTMLInputElement *)[[formEl elements] namedItem:#"bar"];
[inputEl setValue:#"baz"];
this has no effect.
This should definitely work without having to jump through any hoops to do so. I just wrote a quick test app that loaded http://mail.google.com/ and signed into it fine with the following code on SnowLeopard and Leopard:
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
if (![[sender mainFrame] isEqual:frame])
return;
DOMHTMLFormElement *form = (DOMHTMLFormElement *)[[frame DOMDocument] getElementById:#"gaia_loginform"];
DOMHTMLInputElement *username = (DOMHTMLInputElement *)[[form elements] namedItem:#"Email"];
[username setValue:#"myemailacct"];
DOMHTMLInputElement *password = (DOMHTMLInputElement *)[[form elements] namedItem:#"Passwd"];
[password setValue:#"omghi"];
[form submit];
}
I also have very similar code at work whose only job is to sign into website and its been working fine on Tiger for a year. In that case I do everything, including creating the WebView via code. I would also be very surprised if Safari's autofill didn't use very similar code to this.
That said, I would make sure your app isn't doing anything crazy to the WebView. Do you do any other modification the DOM anywhere else? Try doing this in a sample app like I did and see if it works there.
Is the HTML you're loading your own or on a remote server? Some websites include Javascript that clears out form fields on load or a second or two after to prevent autofill. Perhaps you're running into that?
If all else fails, make sure nothing is being logged to the WebView's console. You can see that by opening up the web inspector or temporarily implementing the private WebUIDelegate method:
- (void)webView:(WebView *)webView addMessageToConsole:(NSDictionary *)message;
The restriction is probably because the DOM bridge hooks directly into the same code as the javascript runtime, so you need to bypass any javascript/DOM bridge.
Maybe you could set the focus on the field (if the bridge allows just that) and send keyboard events to the WebView or the Document view.
Alternatively, since those fields are native OS X components you could potentially directly talk to these (and the WebKit source code should help you figure how to get to them).
Sorry, both solutions are a little involved and I have no idea if that works! Maybe the webkitdev mailing list would have an answer, or you could try to ask the 1Password developer ;-)
how about trying to set the field as a normal text field then programmatically changing it to a password field all while the display of the field is :none then change it back to visible.
I would use -stringByEvaluatingJavaScriptFromString:.
Here's what I used (I added an 'id' attribute to the field to make it easier to grab):
[_webView stringByEvaluatingJavaScriptFromString: #"document.getElementById(\"bar\").value = \"hello\""];