Search your blog

Sunday, January 30, 2011

How to use jquery tooltip in jsp


jQuery tooltip is a very important feature in jquery . There are many plugin but i am very much comfortable and feel easy to use tipsy tooltip.

There are some steps to implement it.

step1:
Include javascript in your html head block
<!-- you can download jquery.js from http://docs.jquery.com/Downloading_jQuery
and jquery.tipsy.js from http://plugins.jquery.com/project/tipsy
-->
<script type='text/javascript' src='js/jquery.js'></script>
<script type="text/javascript" src="js/jquery.tipsy.js"> </script>

step2: call your tipsy function

<div id='main'/>

<script type='text/javascript'>
$(function() {

$('#example-1').tipsy();

});
</script>

<a id='example-1' href='#' title='like'> like </a>

</div>

Tuesday, August 10, 2010

How to Internationalization of page in JSF

How to internationalization in JSF

In this week I am writing a blog on internationalization in JSF .It is very use to implement in your jsf project. There are some steps to implement the very important feature.

Step1.
Writing some properties file for your language required. Properties file is a key-value.
Messages_en.properties as follows:

welcome =Welcome on this site.
login = Enter Number.

Messages_fr.properties as follows:

welcome =Bienvenu Sur MyCV
login =Entrée membre.

We have to save these properties file into source folder in com.messageresource package
Step2.
Configure faces-config.xml file::

< application>
< locale-config>
< default-locale>en< /default-locale>
< supported-locale>fr< /supported-locale>
< /locale-config>
< message-bundle>
com.messageresource.Messages
< /message-bundle>
< /application>

Managed bean configure::

< managed-bean>
< managed-bean-name> localeBean < /managed-bean-name>
< managed-bean-class>com.locale. LocaleBean < /managed-bean-class>
< managed-bean-scope>request< /managed-bean-scope>
< /managed-bean>

Step 3

Create a JavaBean class to hold current instance value from FacesContext and set value into context using setLocale() metheod .

public class LocaleBean {

private HashMap< String, Locale> locales = null;

public LocaleBean() {
locales = new HashMap< String, Locale>(2);
locales.put("english", new Locale("en", "UK"));
locales.put("french", new Locale("fr", "FR"));
}

public void onChooseLocale(ActionEvent event) {
String current = event.getComponent().getId();
FacesContext context = FacesContext.getCurrentInstance();
context.getViewRoot().setLocale((Locale) locales.get(current));
}

}


Step 4
Create a .jspx page for change language of page. Here I am using command link to select language::

< %@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
< %@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
< %@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

< f:view>
< f:loadBundle basename="Messages" var="msg"/>
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
< html>
< head>
< meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
< title>welcome Page< /title>

< /head>
< body>
< h:form >
< div class="pageTitle">< h:outputText value="#{msg.welcome}"/>< /div>
< br/>
< h:panelGrid columns="3"
styleClass="center"
style="border:2px solid black"
headerClass="tableHeader">

< h:outputText value="#{msg.login}"/>

< h:commandLink id="english" action="chooseLocale"
actionListener="#{localeBean.onChooseLocale}">
< h:outputText value="#{msg.english}" />
< /h:commandLink>
< h:outputText value=" "/>
< h:commandLink id="french" action="chooseLocale"
actionListener="#{localeBean.onChooseLocale}">
< h:outputText value="#{msg.french}" />
< /h:commandLink>
< /h:panelGrid>
< /h:form>
< /body>
< /html>
< /f:view>

Wednesday, May 12, 2010

How to create custom operation in ADF



In ADF there are many operations to perform of various functionality. To fulfill user requirement, we need to create custom operation. Now I will describe how to create custom operation .

Step 1: create a function into ApplicationModuleImp Class.

            String  getHelloMsg(){
                        String msg=”Hello”;
                        return msg;
            }
Step 2 Open AppModule -- > java --> client Interface then shuttle this function.

Step 3: From your Data Control you drug  your  function  in the page  and right click on your function  and select button.



Step 4: Right-click in the generated button then choose "Create Method Binding For Action" then create a managed bean.




Step 5: The commandButton Method will be like this
public String cb1_action() {
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("getHelloMsg ");
Object result = operationBinding.execute();
System.out.println("Result= " + result); // result will be the output of PL function
if (!operationBinding.getErrors().isEmpty()) {
return null;
}
return null;
}
Step 6- Save your Application then run index.jspx.

Sunday, May 02, 2010

How to remove row using removeRowWithKey in ADF

How to remove row from table using removeRowWithKey in ADF

In ADF we can delete row using delete operation .But it has a limitation to delete the specific row from table .It can only delete first row not to remove user specific row .I want to discuss how to delete user specific row from custom bean method using removeRowWithKey operation from command button .

Step1. You have to use two listener one is client Listener and Server Listener

<af:inputText value="#{row.bindings.TSexCode.inputValue}"
label="#{bindings.T02006View1.hints.TSexCode.label}"
required="#{bindings.T02006View1.hints.TSexCode.mandatory}"
columns="#{bindings.T02006View1.hints.TSexCode.displayWidth}"
maximumLength="#{bindings.T02006View1.hints.TSexCode.precision}"
shortDesc="#{bindings.T02006View1.hints.TSexCode.tooltip}"
id="it2">
<f:validator binding="#{row.bindings.TSexCode.validator}"/>

<af:clientListener method="getRowKeyStr" type="click" />
<af:serverListener type="clickOnRow" method="#{tb02006.getRowKeyStr}"/>
</af:inputText>

I am using javaScript function getRowKeyStr as a Client Listener method and click as an event .you can use any type of event for calling javaScript function .

<![CDATA[
<script>
function getRowKeyStr(event){
component=event.getSource();
alert("CALLED");
AdfCustomEvent.queue(component, "clickOnRow",{}, false);
}
</script>
]]>

Step 2.
From java Script function I am calling server Listener clickOnRow and it will call bean method getRowKeyStr().In the method I have hold the current row when user click on row then put into rowKey property.

public String getRowKeyStr(ClientEvent event){
System.out.println("getRowKeyStr Server Listener METHOD IS CALLING");
FacesContext context=FacesContext.getCurrentInstance();
Application app=context.getApplication();
ValueBinding bind=app.createValueBinding("#{row.rowKeyStr}");
/**
#{row.rowKeyStr} is a property value for current rowKey
**/
String rowKeyStr = (String)bind.getValue(context);
System.out.println("ROWKEYSTR:: "+rowKeyStr);
/*
put rowKeyStr into bean property rowKey
**/
setRowkey(rowKeyStr);

return rowkey;
}

Step3. Custom operation method remove () will delete row using removeRowWithKey operation.

public String remove(){
//String rowKeyVal=getRowKeyStr(ClientEvent event);
System.out.println("Remove METHOD IS CALLING:: "+getRowkey());
if (rowkey!=null){
DCBindingContainer binding=ADFUtils.getBindings();
OperationBinding opb=(OperationBinding)binding.getOperationBinding("removeRowWithKey");
opb.getParamsMap().put("rowKey", rowkey);
System.out.println("IS PARAM :: "+ opb.getParamsMap().containsKey("rowKey") );
System.out.println("PARAM VAL :: "+ opb.getParamsMap().get("rowKey") );
if(opb!=null){
System.out.println("ACTION NAME :: "+ opb.getName() );
opb.execute();
}
if (!opb.getErrors().isEmpty()) {
return null;
}
}

return "REMOVED";

}

Monday, April 26, 2010

How to create LOV(List Of Values ) in ADF using jDeveloper 11g


How to create LOV (List of Values) in ADF Application
LOV (List Of Values) is  a common feature of  JDeveloper 11g. I will describe how to create LOV easily in my blog.
Step1.
Creating View Object (VO):
Create new view object such AutoEmployeeVO from entity class such Employee into a different package.


Step2. Customize new created view object (AutoEmployeeVO) such Attribute, List UI Hints according to your required.
Step3. Open main view object then select Attribute such EmployeeName  whose LOV will be Created  and create List of Values
Step4.  Select List Data source such new created view object and select List attribute.

Step5.  Drag and drop field from data control.





Tuesday, January 26, 2010

How to Implementation JSF Chart in JSF

How to Implementation JSF Chart in JSF

Many times we have requirement of displaying data using charts in our web application. Jsf-comp is a opensource library which I have used in my JSF application. I have used this for simple bar charts and using it is very simple. Below I have explained steps to use it in your application to create a bar chart.
Here I assume you have already had a jsf application running. If you are new to JSF, please read the earlier post JSF tutorial For Beginner .
For the bar chart demo we’ll create a request scoped bean, and a simple jsf view. The data displayed in charts will be some predefined values.
Step 1: Configuration.
Before starting the code download jsf-comp jar file ( jfreechart-1.0.5.jar) from url:
http://sourceforge.net/projects/jfreechart/files/
Copy the jar to web-inf/lib directrory.
Edit your web.xml file to include following:
<servlet>
<servlet-name>Chartlet</servlet-name>
<servlet-class>net.sf.jsfcomp.chartcreator.Chartlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Chartlet</servlet-name>
<url-pattern>*.chart</url-pattern>
</servlet-mapping>
Step 2: Backing bean part.
To create any chart we need object of DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)
DefaultCategoryDataset categoryDataSet=new DefaultCategoryDataset();
We set graph values in this object using addValue function. The functions is shown below (create a Weather.java and include following function with appropriate getter and setter methods) :


package com.sa.medisys.banamco.chart;

import org.jfree.data.category.DefaultCategoryDataset;

public class Weather {
public Weather(){

}

public DefaultCategoryDataset getGraphData() {
DefaultCategoryDataset categoryDataSet=null;
try{

categoryDataSet = new DefaultCategoryDataset();

Double currentTemperature= 25.3;
//Easy AdSense by Unreal

Double minTemperature=10.2;

Double maxTemperature=45.0;

Double avgTemperature=30.0;

categoryDataSet.addValue(maxTemperature,"","Highest Temperature");

categoryDataSet.addValue(minTemperature,"","Lowest Temperature");

categoryDataSet.addValue(avgTemperature,"","Average Temperature");

categoryDataSet.addValue(currentTemperature,"","current Temperature");

return categoryDataSet;

}catch(Exception sq){

System.out.println("exception2 " +sq);

sq.printStackTrace();

return null;

}

}

}


Define the bean in the faces-config.xml file as Managed Bean:
<managed-bean>
<managed-bean-name>weather</managed-bean-name>
<managed-bean-class> com.sa.medisys.banamco.chart.Weather</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
Now in xhtml file you can use the chart library as follows:
Include tag library definition:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:ch="http://sourceforge.net/projects/jsf-comp">

<ui:composition >
<h:outputText value="chart Display" />
<ch:chart id="pichart" datasource="#{weather.graphData}" type="bar" background="orange" orientation="vertical" is3d="false" title="Compare the Temperatures" xlabel="" ylabel="Temperature" height="300" width="500"></ch:chart>
</ui:composition>

</html>

Run the jsf file to see the chart.

Saturday, January 23, 2010

Jasper Report Calling from JSF Page

Jasper Report Calling from JSF Page

Step-1. Create ReportBean.Java file as a bean class


/****** ReportBean.java Class Start*******************/
package com.report;

public class ReportBean {
private Date startDate;
private Date endDate;
private String customerID=null;
private String customerName;
private String itemcode;
private String itemname;

ReportDao dao=new ReportDao();

HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
LoginSession ses=(LoginSession)session.getAttribute("SESSION");

/******* PDF Report ***********/

public void reportCustomer(){

try {
String filename = "Report/KITR009.jasper";
FacesContext facesContext = FacesContext.getCurrentInstance();
ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
//file path of .jasper file
String path = servletContext.getRealPath("/");
String filePath=path+File.separator+filename;
String imgPath=path+File.separator+"images"+File.separator+"MedisysLogo.gif";

dao.report0009(ses.getUserid(),imgPath,filePath);
} catch (Exception e) {
}
}

/******* HTML Report ***********/

public void reportSalesMan(){

try {
String filename = "Report/KITR0042.jasper";
FacesContext facesContext = FacesContext.getCurrentInstance();
ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
//file path of .jasper file
String path = servletContext.getRealPath("/");
String filePath=path+File.separator+filename;
String imgPath=path+File.separator+"images"+File.separator+"MedisysLogo.gif";
dao.report0042(ses.getUserid(),imgPath,filePath);

} catch (Exception e) {
}
}






//////////////////// GETTER SETTER ///////////////////////
public Date getStartDate() {
return startDate;
}

public void setStartDate(Date startDate) {
System.out.println("startDate:: "+startDate);
this.startDate = startDate;
}

public Date getEndDate() {
return endDate;
}

public void setEndDate(Date endDate) {
this.endDate = endDate;
}

public void setCustomerName(String customerName) {
this.customerName = customerName;
}

public String getCustomerName() {
return customerName;
}

public void setCustomerID(String customerID) {
this.customerID = customerID;
}

public String getCustomerID() {
return customerID;
}


}
/****** ReportBean.java Class END*******************/







/**************** ReportDao call form bean ***********/


/********* Start ReportDao.java *********/
package com.sa.medisys.banamco.report;

public class ReportDao extends DBConnection{


/* Customer Information PDF Report */
public void report0009(String userid,String imgPath,String filePath ) throws SQLException, JRException, IOException, NamingException {
try{
System.out.println("User ID ::"+userid);
Map parameter = new HashMap();
parameter.put("USER_ID", userid);
parameter.put("LOGO_PATH", imgPath);
Connection con=dbOpen();
System.out.println("Connection Established"+ con);
JasperPrint jasperPrint =JasperFillManager.fillReport(filePath, parameter,con);
//System.out.println("Report Created..."+parameter.get("itemtype"));
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response =(HttpServletResponse) context.getExternalContext().getResponse();
byte[] bytes = JasperExportManager.exportReportToPdf(jasperPrint);
System.out.println("bytes >> "+bytes.length);

response.setHeader("Content-disposition", "attachment; filename=\"KITR0009.pdf\"");
//response.setContentLength(bytes.length);
response.getOutputStream().write(bytes);
response.setContentType("application/pdf");
//response.setContentType("text/html; charset=utf-8");
//response.setHeader ("Content-disposition", "attachment; filename=\"CustomerReport.pdf\"");
context.responseComplete();
dbClose(con);
//session.removeAttribute("kIT0053Bean");
}catch (Exception e) {
System.out.println(e.getMessage());
}

}

/* Salesman Information HTML Report */

public void report0042(String userid,String imgPath,String filePath ) throws SQLException, JRException, IOException, NamingException{
Connection con=dbOpen();
FacesContext context = FacesContext.getCurrentInstance();
try{
System.out.println("User ID ::"+userid);
Map parameter = new HashMap();
parameter.put("USER_ID", userid);
parameter.put("LOGO_PATH", imgPath);

System.out.println("Connection Established"+ con);
JasperPrint jasperPrint =JasperFillManager.fillReport(filePath, parameter,con);


// html ////////
System.out.println("Report Created... in Format");
JRExporter exporter = null;
HttpServletResponse response =(HttpServletResponse) context.getExternalContext().getResponse();
response.setContentType("text/html; charset=utf-8");
response.setHeader ("Content-disposition", "attachment; filename=\"KITR0042.html\"");
exporter = new JRHtmlExporter();
exporter.setParameter(JRHtmlExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
exporter.setParameter(JRHtmlExporterParameter.OUTPUT_WRITER, response.getWriter());
exporter.exportReport();
context.responseComplete();

}catch (Exception e) {
System.out.println(e.getMessage());
}finally{
dbClose(con);
System.out.println("Created >>>>>>>>");
}
}

}

/********* END ReportDao.java *********/