JSF datatable filtering: Placeholders - java

Since not all of our users are guaranteed to support the HTML 5 placeholder attribute, I was trying to build a workaround for it in JavaScript:
$(document).ready(function() {
var searchInColumn = $('#searchInColumn').text();
$(".ui-widget-glossary-editor-column-filter").on('focus', function() {
var $this = $(this);
if ($this.val() == searchInColumn) {
$this.val('');
$this.css('color', '#444444');
}
}).on('blur', function() {
var $this = $(this);
if ($this.val() == '') {
$this.val(searchInColumn);
$this.css('color', '#c9c9c9');
}
}).blur();
});
While that works as it's supposed to, this now of course poses the problem that an actual (localized) text is present in the input text field, triggering the datatable filter. Can I somehow intercept the PrimeFaces datatable filtering in order to treat this localized placeholder text as an empty string?
Thanks for your suggestions and best regards
Pascal

You mean you placeholder being interpreted as value and sent to server ?
If so you better use jq-watermark to apply the watermark properly...

Related

Kendo UI grid custom datasource URL

I have a comboBox called clientCCBox, I need a javascript that retrieves the selected option value, wich will be the client id, and then passes it on the kendo grid datasource read property as follow:
<kendo:dataSource-transport-read url="/read.html?*clientID*"/>
I've been trying to use this js snippet to recover the selected value; the document write is there to visually see if it actually retrieved the value, but it displays nothing. How would I once I get the clientID use it in HTML?
<script>
function onSelect(e){
var clientId = clientCCBox.value();
document.write(clienteId);
}
</script>
If I do manage to pass clientID on the querystring, the following code on the controller would return a list and populate the grid right?
#RequestMapping(value = "/read.html*")
public #ResponseBody List<Workers> read(HttpServletRequest request) {
return workerDAO.listWorker(Integer.parseInt(request.getQueryString()));
}
You can define your additional parameters using parameterMap attribute in kendo:dataSource-transport tag.
Example:
<kendo:dataSource-transport parameterMap="additionalParameters">
<kendo:dataSource-transport-read url="/ListBeer" type="GET" contentType="application/json"/>
</kendo:dataSource-transport>
Where additionalParameters is:
<script type="text/javascript">
var theId = "xyz";
function additionalParameters(data, type) {
if (type === "read") {
return "id=" + theId;
}
return data;
}
</script>
Here, I would be loading data from the following url /ListBeer?id=xyz where xyz is the value of theId.
You can also send more than one parameter:
function additionalParameters(data, type) {
if (type === "read") {
return "id=" + data + "&param=" + JSON.stringify(data);
}
return "param= "+ JSON.stringify(data);
}
Use the "Data" event on the read action parameter for the drop down to specify dynamic javascript parameters to the drop down. Note the exact syntax for the .Read method. Often you see the syntax .Read("ActionName", "ControllerName") but we want the other overloaded version of .Read:
.DataSource(data => data.Read(read => read.Action("GetDropDownValues", "Quote").Data("getCriteria")))
function getCriteria() {
return {
id: "put value here",
anotherParameter: 55
};
}
you need to put the client id in the data field of the transport.
Look at the following link.
http://docs.kendoui.com/api/framework/datasource#transportcreatedata-objectstringfunction
this is part of jquery not kendo ui

how to copy data with fontstyle from excel to browser or java? [duplicate]

CKEditor is a great editor and the pastefromword plugin is very good. I'd like to have the filtering provided by the plugin applied to all pasted text. For example, when pasting from word, all fonts and sizes are stripped. This does not happen when pasting from an email.
That said, I came up with the following solution and posting it here to get some feedback. I'm wondering if I made it too complicated, or if there is an easier way. I kind of just copied the code from pastefromword/plugin.js.
via my custom config.js
...
CKEDITOR.config.pasteFromWordCleanupFile = '/pastefromword.js';
...
CKEDITOR.on( 'instanceReady', function( ev ) {
/**
* Paste event to apply Paste From Word filtering on all text.
*
* The pastefromword plugin will only process text that has tell-tale signs
* it is from Word. Use this hook to treat all pasted text as if
* it is coming from Word.
*
* This method is a slightly modified version of code found in
* plugins/pastefromword/plugin.js
*/
ev.editor.on( 'paste', function( evt ) {
var data = evt.data,
editor = evt.editor,
content;
/**
* "pasteFromWordHappened" is a custom property set in custom
* pastefromword.js, so that filtering does not happen twice for content
* actually coming from Word. It's a dirty hack I know.
*/
if( editor.pasteFromWordHappened ) {
// Reset property and exit paste event
editor.pasteFromWordHappened = 0;
return;
}
var loadRules = function( callback ) {
var isLoaded = CKEDITOR.cleanWord;
if( isLoaded ) {
callback();
}
else {
CKEDITOR.scriptLoader.load( CKEDITOR.config.pasteFromWordCleanupFile, callback, null, false, true );
}
return !isLoaded;
};
content = data['html'];
// No need to filter text if html tags are not presence, so perform a regex
// to test for html tags.
if( content && (/<[^<]+?>/).test(content) ) {
var isLazyLoad = loadRules( function(){
if( isLazyLoad ) {
editor.fire('paste', data);
}
else {
data[ 'html' ] = CKEDITOR.cleanWord( content, editor );
// Reset property or if user tries to paste again, it won't work
editor.pasteFromWordHappened = 0;
}
});
isLazyLoad && evt.cancel();
}
});
});
My solution is now in this blog entry: http://www.keyvan.net/2012/11/clean-up-html-on-paste-in-ckeditor/
Commenting on a old question:
The issue at hand is not just word cleaning in CKEditor.
Its also a matter of what the browser does when you ask for clip board content via javascript api. that differs heavily between IE, FF, Safari etc. Typically the non IE browsers will clean up the HTML themself, beofore giving the HTML to the browser. Thus removing a lot of formatting.

split method for text value in Appcelerator

I have a window that displays my tweets in a label.
My tweets come from my FB page statuses and if i have put a pic or write more than 140 characters then i get a link in tweet to the actuall post.
I wonder if there is any way to get the label text to split so i can point the link into an url to open in webview
This is how far i have got:
var win = Ti.UI.currentWindow;
win.showNavBar();
var desc = Ti.UI.createLabel({
text: win.data,
font:{
fontSize:'20dp',
fontWeight:'bold'
},
height:'300dp',
left:'5dp',
top:'10dp',
color:'#111',
touchEnabled:true
});
win.add(desc);
desc.addEventListener('click',function(e){
var v = desc.text;
if(v.indexOf('http') != -1){
// open new window with webview
var tubeWindow = Ti.UI.createWindow({
modal: true,
barColor: '#050505',
backgroundColor: '#050505'
});
var linkview = Ti.UI.createWebView({
url: e.v,
barColor: '#050505',
backgroundColor: '#050505'
});
// Create a button to close the modal window
var close_modal = Titanium.UI.createButton({title:'Stäng'});
tubeWindow.rightNavButton = close_modal;
// Handle close_modal event
close_modal.addEventListener('click', function() {
tubeWindow.close();
});
tubeWindow.add(linkview);
tubeWindow.open({
modalTransitionStyle: Ti.UI.iPhone.MODAL_TRANSITION_STYLE_FLIP_HORIZONTAL,
});
}
});
win.open();
What i´ve been told i need to split the win.data to get the link. (win.data is the tweet)
now i just have: url: e.v, i need to get the link out
Any ideas on how this can work?
Thanx
//R
I did a similar thing a while ago. pull down the tweet(s) run the text through a regular expression to pull out a URL.
What I did was put each tweet in a tableview row, and set the tableview row to hasChild=true if the regular expression returned anything, then onClick of a tableView row, if hasChild == true open a webview with the given URL (stored in the row).
A regualr expression like the one here should work:
http://www.geekzilla.co.uk/view2D3B0109-C1B2-4B4E-BFFD-E8088CBC85FD.htm
So something like:
str= <<tweet text>>;
re= <<URL expression>>;
check=str.match(re);
now check contains either null or a url.

Can I trigger an IceFaces action using JavaScript?

If I have a simple button:
<ice:panelGroup>
<ice:commandButton value="foobar"
action="#{fileManager.openNoFlashVisiblePopup}" />
</ice:panelGroup>
Is it possible to trigger the action openNoFlashVisiblePopup using just javascript? I know that there IceFaces has a JavaScript bridge but I don't know see a simple way to do just this.
i need to do this because I have a chunk of JavaScript that detects Flash and I need to show a IceFaces popup.
One way is to get the button element by ID and call its click() function.
document.getElementById('clientId').click();
You only need to give the form and button a fixed id so that you can use the generated HTML ID as clientId in Javascript code.
I know I'm a little late in seeing this, but the correct way to handle this (minus perhaps the overly exhuberant error checking) is:
// There's a <div> that looks like: <div class="portletfaces-bridge-body" id="A8660">.
// We'll find it and pull out the value of the ID to build elementId like: A8660:wtfForm:editeventparent
var div = null;
var divCollection = document.getElementsByTagName("div");
for (var i=0; i<divCollection.length; i++) {
if(divCollection[i].getAttribute("class") == "portletfaces-bridge-body") {
div = divCollection[i];
break;
}
}
if (div == null){
alert("could not find div portletfaces-bridge-body.");
return;
}
// Pull the id out of divInnerText.
var id = div.getAttribute("id");
if (id == null){
alert("id was null");
}
// prepare initializes fields to null so rendered cannot begin until both itemId and parentId are set.
var prepare = document.getElementById(id + ":wtfForm:editeventprepare");
if (prepare == null){
alert("editeventprepare element was not found.");
return;
}
prepare.click();

java equivalent of swfobject

looking for a javascript class like swfobject to embed java and have a simple fallback if the user doesn't have java or refuses the security prompt.
thanks,
Josh
You could build one pretty easily.
Have something like a div set up like this:
<div id="java-applet">
Message to user saying that they need Java here
</div>
Then add Java Plugin Detection (builder) to your JavaScript. Then if that returns true, then do something like:
document.getElementById("java-applet").innerHTML = "<applet>stuff here</applet>";
appletobject may work, but I have not used it.
Just embed the applet like you normally do and insert the fallback inside or insert a javascript snippet to remove the object: Besides param, you can add other elements, e.g. paragraphs with text or javascript calling some function to replace the object.
<script type="text/javascript">
function replace_object(x) {
$(x)...
}
</script>
<object x="y" id="some_applet">
<param name="y" value="z">
<p>java not available. some alternative here. <!-- option 1 --></p>
<script type="text/javascript">
replace_object('some_applet'); // option 2
</script>
</object>
This helps!
I got a very strange problem while using applet to do batch file downloading from the server side.
The Ajax request seems conflict with applet request, the applet file downloading interrupted with some socket exception.
The applet works fine under JRE5.0, it might be caused by our recent upgrade to JRE6.0.
<div id="java-applet"></div>
<script>
var t;
function startApplet() {
var attributes = {codebase:'<%=request.getContextPath()%>',
code:'<%=appletClass%>',
archive:'applet/SignedApplet.jar',
width:0,
height:0} ;
var parameters = {para1:'value1',
para2:'value2',
java_arguments:'-Xms64m -Xmx512m'
} ;
var version = '1.6' ;
var buildAppletTag = function() {
var tag = '<applet';
for (var attribute in attributes){
tag += (' ' + attribute + '="' + attributes[attribute] + '"');
}
tag += ">";
for (var parameter in parameters){
tag += '<param name="' + parameter + '" value="' + parameters[parameter] + '"/>';
}
tag += '</applet>';
return tag;
};
document.getElementById("java-applet").innerHTML = buildAppletTag(attributes, parameters, version);
clearTimeout(t);
}
t = setTimeout("startApplet()", 1000); // delayed
</script>

Categories

Resources