Share on Google+Share on Google+

Working with JavaScript & CSS

Advertisement
JSF provides so many attributes to provide javascript support like onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmouseover, onmouseup, onselect etc.

Working with JavaScript & CSS

        

JSF provides so many attributes to provide javascript support like onblur, onchange, onclick, ondblclick, onfocus, onkeydown, onkeypress, onkeyup, onmousedown, onmouseover, onmouseup, onselect etc. For using CSS, JSF provides style and styleClass attributes for the components. You can use this as in the example below:

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<f:view>
<html>
<head>
<title>JSF JavaScript & CSS</title>
<script type="text/javascript">
function checkName(){
  var name = document.getElementById("myform:name").value; 
  if(name.length<1){
  alert("Name can not be blank.");
  return false;
  }
  if(name.length>4){
  alert("Name can not be more than 4 characters.");
  return false;
   }
}
</script>


<style type="text/css">
   .inputbox {
   background-color:#FFFFFF; 
   color: #333333;
   width:200px;
   border-width:1px;
   border-style:solid;
   border-color:#808080;
  }
  .submitbutton{
   background-color:#367BB7;
   border:1px solid #2E76B4;
   color: #ffffff;
   text-align: center;
   width: auto;
   padding: 2px 3px 2px 3px;
   } 
</style>


</head>

<body>
<h:form id="myform"> 
<h:outputText value="Enter your Name: " style="font-weight:bold;"/>
<h:inputText id="name" styleClass="inputbox"/>

<br><br> 
<h:commandButton onclick="return checkName()" styleClass="submitbutton" action="test" value="Submit" /> 
</h:form>
</body>
</html>
</f:view>

Download code for all examples

Advertisements

Advertisement

Posted on: December 30, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Working with JavaScript & CSS  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0