Friday, 29 July 2016

How to add custom fonts in Jasper of GGTS

Hi,

Before going to add, first download any one of the font from google. i downloaded one of the font from http://www.1001freefonts.com/

goto your project workspace,

Step 1: Add Font in Jasper

windows -> prefferences -> jaspersoft studio -> Fonts ->  Add

place family name as font name

browse true type as font file

check the checkbox of Embed this font in PDF doucment

and click Finish and then OK




Step 2: Create jar file of given font through iReport Designer tool

install and run iReport Designer tool

goto tools -> options -> iReport -> Fonts

Click Install Font, 





Browse font location and then click next

place family name as font name

check the checkbox of Embed this font in PDF doucment




and then click Finish

the given font showed in Fonts tab



select that font, click on Export as extension




Save with .jar, then jar is saved in selected location.

then close iReport Designer.

Step 3: Add jar file to GGTS

add jar file in lib folder of ggts

place these 3 lines before calling jasper report

String defaultPDFFont = "LittleLordFontleroyNF";
DefaultJasperReportsContext context = DefaultJasperReportsContext.getInstance();
JRProperties.setProperty("net.sf.jasperreports.awt.ignore.missing.font", "true");
JRProperties.setProperty("net.sf.jasperreports.default.font.name", defaultPDFFont);



extract jar file in outside folder. it showing as follows.


copy the font name which is placed in fonts/fontsfamily1469773845547.xml


place this font name at defaultPDFFont of above groovy code

run project take pdf.

Thank You

Tuesday, 26 July 2016

Improve the performance of GGTS

for improving the performance of ggts, increase the permsize of JVM.

goto -> window -> preferences -> Java -> Installed JREs

select the jdk file then click on edit, place the given values in VM arguments

-XX:PermSize=256m -XX:MaxPermSize=752m

then click Finish and then OK



Thursday, 21 July 2016

Spring CRUD Operations in Eclipse

Hi,

Before going to crude operations first set up the project with spring security as follows.

Spring Project setup in Eclipse

the flow is

  • generate request from JSP
  • the request passed to controller then it send to service then go to dao
  • processing the data at dao and then return back to JSP
      JSP -> Controller -> Service -> Dao

     After login the welcome page should like this

     Welcome page and structure of project given below check once.


Welcome.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Hi This is welcome page...!</h1>

<a href="employee.html">Employee</a> &nbsp;

<a href="<%=request.getContextPath()%>/j_spring_security_logout"> Logout</a>
</body>
</html>

Employee.java:

package com.vamsi.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="employee")
public class Employee {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="employeeId")
private Long employeeId;

@Column(name="name")
private String name;

public Long getEmployeeId() {
return employeeId;
}
public void setEmployeeId(Long employeeId) {
this.employeeId = employeeId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}


}


EmployeeController.java:

package com.vamsi.controller;

import java.util.HashMap;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.vamsi.model.Employee;
import com.vamsi.service.EmployeeService;

@Controller
public class EmployeeController {

@Autowired
EmployeeService employeeService;

@RequestMapping(value = "/employee", method = RequestMethod.GET)
public ModelAndView addEmployee(@ModelAttribute("command") Employee employee) {
Map<String, Object> model = new HashMap<String, Object>();
model.put("employee", employee);
model.put("employeeList", employeeService.getEmployees());
return new ModelAndView("/employee/index", model);
}

@RequestMapping(value = "/employeeSave", method = RequestMethod.POST)
public ModelAndView employeeSave(@ModelAttribute("command") Employee employee) {
employeeService.addEmployee(employee);
return new ModelAndView("redirect:/employee.html");
}

@RequestMapping(value = "/employeeDelete", method = RequestMethod.GET)
public ModelAndView deleteEmployee(@ModelAttribute("command") Employee employee){
employeeService.deleteEmployee(employee);
return new ModelAndView("redirect:/employee.html");
}

@RequestMapping(value = "/employeeEdit", method = RequestMethod.GET)
public ModelAndView editEmployee(@ModelAttribute("command") Employee employee){
Map<String, Object> model = new HashMap<String, Object>();
model.put("employee", employeeService.getEmployee(employee.getEmployeeId()));
model.put("employeeList", employeeService.getEmployees());
return new ModelAndView("/employee/index", model);
}

}

EmployeeService.java:

package com.vamsi.service;

import java.util.List;

import com.vamsi.model.Employee;

public interface EmployeeService {

public void addEmployee(Employee employee);
public Employee getEmployee(Long employeeId);
public List<Employee> getEmployees();
public void deleteEmployee(Employee employee);
}

EmployeeServiceImp.java:

package com.vamsi.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vamsi.dao.EmployeeDao;
import com.vamsi.model.Employee;

@Service("employeeService")
public class EmployeeServiceImp implements EmployeeService{

@Autowired
EmployeeDao employeeDao;
public void addEmployee(Employee employee) {
// TODO Auto-generated method stub
employeeDao.addEmployee(employee);
}

public Employee getEmployee(Long employeeId) {
// TODO Auto-generated method stub
return employeeDao.getEmployee(employeeId);
}

public List<Employee> getEmployees() {
// TODO Auto-generated method stub
return employeeDao.getEmployees();
}

public void deleteEmployee(Employee employee) {
// TODO Auto-generated method stub
employeeDao.deleteEmployee(employee);
}

}

EmployeeDao.java:

package com.vamsi.dao;

import java.util.List;

import com.vamsi.model.Employee;

public interface EmployeeDao {

public void addEmployee(Employee employee);
public Employee getEmployee(Long employeeId);
public List<Employee> getEmployees();
public void deleteEmployee(Employee employee);
}

EmployeeDaoImp.java:

package com.vamsi.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.vamsi.model.Employee;

@Repository("employeeDao")
public class EmployeeDaoImp implements EmployeeDao {

@Autowired
HibernateTemplate hibernateTemplate;
public void addEmployee(Employee employee) {
// TODO Auto-generated method stub
hibernateTemplate.saveOrUpdate(employee);
}

public Employee getEmployee(Long employeeId) {
// TODO Auto-generated method stub
return hibernateTemplate.get(Employee.class, employeeId);
}

public List<Employee> getEmployees() {
// TODO Auto-generated method stub
return hibernateTemplate.loadAll(Employee.class);
}

public void deleteEmployee(Employee employee) {
// TODO Auto-generated method stub
hibernateTemplate.delete(employee);
}


}

Domain whould be added in sdnext-servlet.xml as follows:


index.jsp:

this is employee management page

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Hi I am Employee Index page</h1>
<form:form method="post" action="employeeSave.html">
<input type="hidden" name="employeeId" value="${employee.employeeId }"/>
Name <form:input type="text" path="name" value="${employee.name }"/><button type="submit">Submit</button>
</form:form>
<br/><br/>
<c:if test="${!empty employeeList }">
<table>
<thead>
<tr>
<th>Sno</th>
<th>Name</th>
<th></th>
</tr>
</thead>
<tbody>
<c:forEach items="${employeeList }" var="e">
<tr>
<td><c:out value=" ${e.employeeId }"/></td>
<td><c:out value=" ${e.name }"/></td>
<td><a href="employeeDelete.html?employeeId=${e.employeeId}">Delete</a> <a href="employeeEdit.html?employeeId=${e.employeeId}">Edit</a></td>
</tr>
</c:forEach>
</tbody>
</table>
</c:if>
</body>
</html>

after run the app the frames as follows:

Login:

After login, welcome page as follows:

Click on Employee, we will navigate to manage employees. here we will do crud operations.


                                Thank You

Monday, 4 July 2016

Friday, 1 July 2016

How to solve permGen space problem in tomcat server

goto tomcat >> bin >> catalina.bat

add this line in first if

set JAVA_OPTS=-XX:PermSize=256m -XX:MaxPermSize=700m