jQuery clock not working in jsf 1.2 - javascript

I am implementing jQuery clock in my application. This clock is working fine in HTML/JSP page but not working in jsf 1.2.
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%#taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<f:view>
<f:verbatim>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>JSF</title >
<link rel="stylesheet" href="WEB-INF/clock/include/ui-1.10.0/ui- lightness/jquery-ui-1.10.0.custom.min.css" type="text/css" />
<script type="text/javascript" src="WEB-INF/clock/include/jquery-1.9.0.min.js/"></script>
<script type="text/javascript" src="WEB-INF/clock/include/jquery-1.9.0.min.js"/>
<script type="text/javascript" src="jquery-1.9.0.min.js/"></script>
<link rel="stylesheet" href="WEB-INF/clock/include/ui-1.10.0/ui-lightness/jquery-ui-1.10.0.custom.min.css" type="text/css" />
<script type="text/javascript" src="WEB-INF/clock/include/ui-1.10.0/jquery.ui.core.min.js"></script>
<script type="text/javascript" src="WEB-INF/clock/include/ui-1.10.0/jquery.ui.widget.min.js"></script>
<script type="text/javascript" src="WEB-INF/clock/include/ui-1.10.0/jquery.ui.tabs.min.js"></script>
<script type="text/javascript" src="WEB-INF/clock/include/ui-1.10.0/jquery.ui.position.min.js"></script>
<script type="text/javascript" src="WEB-INF/clock/jquery.ui.timepicker.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#timepicker_showon').timepicker({
showOn: 'button',
button: $('.timepicker_button_trigger'),
showLeadingZero: false,
timeSeparator: ':'
});
});
</script>
</head>
</f:verbatim>
<h:form id="clock">
<body>
<h1><h:outputText value="JavaServer Faces"/></h1>
<f:verbatim> <label for="timepicker_showon">Select Time</label></f:verbatim>
<h:inputText style="width: 70px;" id="timepicker_showon" value="00:00" />
<f:verbatim> <div class='timepicker_button_trigger'
style="width: 16px; height:16px;
display: inline-block; border: 1px solid #222222; margin-top: 3px; cursor:pointer"></div>
</f:verbatim>
</body>
</h:form>
</html>
</f:view>
I have read that $ is not defined. I have tried alternatives like:
$ = jQuery
$jq = jQuery.noConflict();
But these solutions are also not working.
I have requirements to implement the clock, and I have already used Tomahawks calender to select a date, so I need to implement a different timepicker. Please suggest any other alternatives (if any).

Seem like you've included jQuery three times:
<script type="text/javascript" src="WEB-INF/clock/include/jquery-1.9.0.min.js/"></script>
<script type="text/javascript" src="WEB-INF/clock/include/jquery-1.9.0.min.js"/>
<script type="text/javascript" src="jquery-1.9.0.min.js/"></script>
The second <script> tag also missing closing </script>. Try to keep one link only and see how.

The problem is in the generated IDs for your component on HTML. The <h:form> ID will be automatically appended to the IDs of the inner components, so
<h:form id="clock">
<h:inputText id="timepicker_showon" />
</h:form>
Will generate this HTML:
<form id="clock">
<input type="text" id="clock:timepicker_showon" />
</form>
You have two ways to solve this:
Pass the right client ID to your jQuery functions:
$('#clock\\:timepicker_showon')
Note that you must use \\: because : is reserver for jQuery selector (more info here).
Use prependId="false" in your <h:form> so the inner components IDs won't have the form ID:
<h:form id="clock" prependId="false">
<h:inputText id="timepicker_showon" />
</h:form>
This will generate this HTML:
<form id="clock">
<input type="text" id="timepicker_showon" />
</form>
An additional note: In your profile you say I want to learn jsf., if you're learning in your own way, then it would be better to study JSF 2.

Related

How to use bootstrap datepicker

Okay, So I'm new to using frameworks and js libraries and I'm wanting to us bootstrap and bootstrap datepicker for a form and I have no clue if I have the file order correct but the links is how the files are setup, and I know very little about javascript, pretty much all I code in is php but I need this for a form.
Here's my testing form for the bootstrap datepicker:
<!DOCTYPE html>
<html>
<head>
<title>Testing</title>
<meta charset="utf-8">
<link rel="stylesheet" href="_css/datepicker.css">
<link rel="stylesheet" href="_css/bootstrap.css">
<link rel="stylesheet" href="_css/bootstrap-responsive.css">
<script type="text/javascript" src="datepicker/bootstrap-datepicker.js"></script>
</head>
<body>
<center>
<h1>BootStrap Datepicker</h1>
<form>
<div class="well span12 main">
<input type="text" id="dp1" class="span2 datepicker" placeholder="Date..."
name="date"> <br>
</div>
<input type="submit" value="Search" class="btn">
</form>
</center>
<!-- JAVAscript ----------------------------------------------------------------->
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="_js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="_js/bootstrap.js"></script>
</body>
</html>
What exactly am I doing wrong?
You should include bootstrap-datepicker.js after bootstrap.js and you should bind the datepicker to your control.
$(function(){
$('.datepicker').datepicker({
format: 'mm-dd-yyyy'
});
});
man you can use the basic Bootstrap Datepicker this way:
<!DOCTYPE html>
<head runat="server">
<title>Test Zone</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="Css/datepicker.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="../Js/bootstrap-datepicker.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#pickyDate').datepicker({
format: "dd/mm/yyyy"
});
});
</script>
and inside body:
<body>
<div id="testDIV">
<div class="container">
<div class="hero-unit">
<input type="text" placeholder="click to show datepicker" id="pickyDate"/>
</div>
</div>
</div>
datepicker.css and bootstrap-datepicker.js you can download from here on the Download button below "About" on the left side.
Hope this help someone, greetings.
I believe you have to reference bootstrap.js before bootstrap-datepicker.js
Just add this below JS file
<script type="text/javascript">
$(document).ready(function () {
$('your input's id or class with # or .').datepicker({
format: "dd/mm/yyyy"
});
});
</script>
Couldn't get bootstrap datepicker to work until I wrap the textbox with position relative element as shown here:
<span style="position: relative">
<input type="text" placeholder="click to show datepicker" id="pickyDate"/>
</span>

$(document).ready() handler fires immediately

I've made a small page that just has this as the HTML:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>hi</title>
<script type="text/javascript" src="js/jquery-1.8.2.js"></script>
<link type="text/css" href="js/jquery-ui-1.9.1.custom/css/black-tie/jquery-ui-1.9.1.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="js/jquery-ui-1.9.1.custom/js/jquery-ui-1.9.1.custom.js"></script>
<link type="text/css" href="css/main.css" rel="Stylesheet" />
<script src="js/main.js"></script>
<script>
$(main());
/* or $(document).ready(main()); */
</script>
</head>
<body>
<div id="loginDiv" class="popupDiv">
<div id="usernameDiv">
<label for="username">username</label>
<input type="text" id="username"/>
</div>
<div id="passwordDiv">
<label for="password">Password</label>
<input type="password" id="password"/>
</div>
</div>
<div id="introDiv">
<div class="headerDiv">
<button id="loginButton">Login</button>
</div>
</div>
</body>
</html>
And then I have my main.js:
function main()
{
var $loginButton = $('#loginButton');
var $loginDiv = $('#loginDiv');
$loginDiv.dialog({ autoOpen: false });
$loginButton.click(function() {
$loginDiv.dialog("open");
//alert('sfsdf');
});
}
I can trigger alerts, but selectors will not return any elements if the .ready() handler is specified in the head.
I have tried moving it to the end of the body tag and everything works fine. According to the JQuery docs, the entire DOM and all images and resources are supposed to be loaded before the handler gets called. What gives?
Firefox 16.0.2 on Linux x86
JQuery 1.8.2
JQuery UI 1.9.2 (not really used for the purposes here)
Because you are calling your function!
$(main()); <--() means run it
You want to assign a reference to it
$(main); <-- no ()!

Jquery Datepicker is not populated on Button click?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link type="text/css" href="Styles/Site.css" rel="Stylesheet" ></link >
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
var textBox = $('#mdatepicker');
var icon = $('#myButton');
var mydatepicker = textBox.datepicker();
icon.click(function () {
mydatepicker.datepicker("show");
});
});
</script>;
<form id="form1" runat="server">
<input type="text" id="mdatepicker" value="date" />
<input type="button" id="myButton" value="PopUp"/>
</form>
</body>
</html>
Is there anything missing in this html snippet .??
datepicker is not getting populated, ErrorConsole showing error that-
'textBox.datepicker is not a function'
in below code;
var mydatepicker = var mydatepicker = textBox.datepicker();
Can someone help please.?
Thats my working copy of your code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<link type="text/css" href="Styles/Site.css" rel="Stylesheet" ></link >
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
var textBox = $('#mdatepicker');
var icon = $('#myButton');
var mydatepicker = textBox.datepicker();
icon.click(function () {
mydatepicker.datepicker("show");
});
});
</script>;
<form id="form1" runat="server">
<input type="text" id="mdatepicker" value="date" />
<input type="button" id="myButton" value="PopUp"/>
</form>
Is datepicker not a function from the jQuery-UI library?
If so, then you need to include a script reference to the jQuery-UI Library.
EDITS
No You need to add a script reference to the jQuery-UI library and jQuery-UI Css file
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="src of desired theme" />
Are you giving full refrences to js files. Including jquery and datepicker's .js files.
The issue is in this:
<script type="text/javascript" src="Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
I can not see any js files regarding datepicker in your head tag where you've included all js refrences.
There must be some file like:
<script type="text/javascript" src="Scripts/datepicker.js"></script>
or something like that, which you are missing to include.
Hope this helps.
if you use jquery datepicker, the 'myButton' object is not necessary, datepicker will handle it for use, see the code:
<html>
<head><title>jQuery Open on button</title>
<link rel="stylesheet" href="ui.all.css" type="text/css" media="screen" />
</head>
<body>
<form>
<input id="date" type="textbox"/>
</form>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#date").datepicker({ showOn: 'button', buttonText: "select" });
});
</script>
</body>
</html>

checkbox image replacement,nothing happend

<?php
//require 'includes/db.inc.php';
require 'includes/configs.inc.php';
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><?php $site_name ?></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
<link rel="stylesheet" type="text/css" href="/css/style.css">
<script type="text/javascript" src="/js/jquery.imageTickBox.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("input:[type=checkbox]").imageTickBox({
tickedImage: "/images/checked.png",
unTickedImage: "/images/unchecked.png",
imageClass: "tickbox"
});
});
</script>
</head>
<body>
<div id="mirror" class="center">
<!--some code deleted-->
<input type="checkbox" id="Music" name="hobbies[]" value="Music">
<!--some code deleted-->
</div>
</body>
</html>
any wrong with the code above????name index.php and put it on root dir.
but not work , i see the jquery checkbox plugin guide at
http://blog.leenix.co.uk/2009/10/jquery-plugin-imagetickbox-change-any.html
ALWAYS close your script tags, even if using external resources.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
You need to close the jquery script tag:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

YUI SimpleEditor not right layout

I've downloaded the YUI library for the nice SimpleEditor. When installed and created a simple test. It will not display right.
this is how it should look like.
http://developer.yahoo.com/yui/examples/editor/simple_editor.html
and this is how it looks with my example:
http://ms.robertcabri.nl/testing.php
Here is the code of my testing page:
<html>
<head>
<title>Test</title>
<link rel="stylesheet" type="text/css" href="http://ms.robertcabri.nl/js/yui/assets/skins/sam/skin.css" />
<link rel="stylesheet" type="text/css" href="http://ms.robertcabri.nl/js/yui/editor/assets/skins/sam/simpleeditor.css" />
<link rel="stylesheet" type="text/css" href="http://ms.robertcabri.nl/js/yui/button/assets/skins/sam/button.css" />
<script type="text/javascript" src="http://ms.robertcabri.nl/js/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="http://ms.robertcabri.nl/js/yui/element/element-min.js"></script>
<script type="text/javascript" src="http://ms.robertcabri.nl/js/yui/container/container_core-min.js"></script>
<script type="text/javascript" src="http://ms.robertcabri.nl/js/yui/editor/simpleeditor-min.js"></script>
<script type="text/javascript">
window.onload = function () {
var Dom = YAHOO.util.Dom, Event = YAHOO.util.Event;
var editor = new YAHOO.widget.SimpleEditor('blaat', {
dompath: true,
handleSubmit: false
});
editor.render();
};
</script>
</head>
<body>
<form action="#" method="post" id="test">
<fieldset>
<legend>test</legend>
<textarea name="blaat" id="blaat" cols="30" rows="5"></textarea>
</fieldset>
</form>
</body>
</html>
Well found the answer myself.
YUI SimpleEditor documentation is really bad. The Main styling has to be set for this element.
in my example i've set a wrapper around the textarea and then the styling picks up.
<div class="yui-skin-sam">
<textarea></textarea>
</div>
You also could place this class on a form element or on the body. It has to be a parent of the textarea node you want to replace with the simpleeditor
You need to put the "yui-skin-sam" class on your body tag, for one thing.

Categories

Resources