Premature end of file when running junits

Problem:

Premature end of file error when running Junits

[junitreport] [Fatal Error] :-1:-1: Premature end of file.
[junitreport] The file /tmp/repository/Yogesh/task2652_story1984/modulesmgr/junit_report/out/xml/TEST-com.coresecurity.ctrlsvc.modules.ModulesImportAndBasicCRUDTest.xml is not a valid XML document. It is possibly corrupted.

Observations:
1) TESTS-testsuites.xml was coming out to be empty.
2) The resulting xml file was getting too large in size.

Solution:
Hibernate logging was enabled which was leading to large size of XML.
We disabled logging in config.xml as given below
Earlier it was true, we made it false








org.hibernate.dialect.MySQL5InnoDBDialect
false
update
true
5
20
300
50
3000


use OnClick with caution

JSP Code :

<a href="abc.jsp" onclick='’>LOGOUT

The above statement gets converted to Servlet CODE :


out.write("<a href="abc.jsp" onclick='");

session.invalidate();

out.write("'>LOGOUT");


Conclusion:

What ever scriplet you write in onclick, will get executed every time the JSP is called. Not only on onclick as can be wrongly assumed.

BUG in struts2

Actually I used

Now, I have specified type as button, so I expected that it will not go to action on click on the button.

But what happens is

when I click on button, it asks if I want to close the window,
Now, even I click NO, it still goes to action specified in form.

Solution : This is a BUG in struts2.

the HTML tag that is generated is something like:

<button type="submit” id=”test_0″ value=”Submit” class=”button positive save”>Submit

Please note that we have given type=button in s:submit tag, and the HTML generated still contains type=submit.

Can get some information from http://www.ericmmartin.com/struts-2-bug-submit-button-tag-rendering/

Internationalization tips for JSP

In order to display the complex script characters like Japanese, Chinese, etc in the browser window, the following changes need to be made at the beginning of each JSP file:

<%@ page language="java" 
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

Wherever input controls are present, the following additional steps need to be taken:
Add the following code before reading any parameters in the previous JSP file:

request.setCharacterEncoding("UTF-8"); // Set the request encoding

While sending output to a browser:

response.setContentType ("charset=UTF-8");

Color of Error Messages in struts 2

Problem:

I am working on struts 2.
I have one text field and have put validation (with xml)on the text field if its blank, throw an error.
But the field error I am getting is in black colour.
Does anyone have idea how to display the field error in red colour.

Solution:

U can the use the following tag in your .css Stylesheet file

.errorMessage {
color: red;
font-size: 0.8em;
}

And include this Stylesheet in the file where u have the text field.

Source : http://www.roseindia.net/struts/struts2/validations/Struts2-annotations.shtml

How to connect Hibernate with Microsoft Access

1. Go to Control Panel
2. Go to Administrative Tools
3. Go to ODBC Data sources
4. Create a DSN (say mydb), give the path to .mdb file.
5. Get hibernate.jar

6. Extract contents of access.zip and get Access_JDBC30.jar

7. Create a new Java Project in NetBeans 6.7 or greater. and give the above 2 jars in classpath of the project

8. Create the employee class inside demo package with the following contents

package demo;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;

/**
*
* @author Yogi
*/
@Entity
public class Employee implements Serializable {
@Id
int empId;
String empIbu;
String empName;
int empSalary;


public Employee() {
}
public String toString()
{
return empName;
}
public Employee(int empId, String empIbu, String empName, int empSalary) {
this.empId = empId;
this.empSalary = empSalary;
this.empName = empName;
this.empIbu = empIbu;
}

public String getEmpIbu() {
return empIbu;
}

public void setEmpIbu(String empIbu) {
this.empIbu = empIbu;
}

public int getEmpId() {
return empId;
}

public void setEmpId(int empId) {
this.empId = empId;
}

public String getEmpName() {
return empName;
}

public void setEmpName(String empName) {
this.empName = empName;
}

public int getEmpSalary() {
return empSalary;
}

public void setEmpSalary(int empSalary) {
this.empSalary = empSalary;
}

}

9. Create hibernate.cfg.xml in the root directory of the application (outside all packages)





com.hxtt.sql.access.AccessDriver
jdbc:odbc:mydb
com.hxtt.support.hibernate.HxttAccessDialect
<!-- Please note, here the value update is not working with MS-Access
Although it should work theoretically, but practically, the value
update is able to create the table for the first time
and after that it fails every time -->
create
true



10. Create EmployeeClient.java file inside client package (Though not mandatory)

/**
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package client;

import demo.Employee;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.classic.Session;

/**
*
* @author Yogi
*/
public class EmployeeClient {
public static void main(String args[])
{
/* Here we have used AnnotationConfiguration because, we have used Annotations in
* Employee class to map the class fields with the table fields.
* If Employee.hbm.xml is used for this mapping then here we would have used
* Configuration (which we normally do)
*/

SessionFactory factory=new AnnotationConfiguration().configure().buildSessionFactory();
Session session = factory.openSession();
Transaction tx=null;
try
{

Criteria c = session.createCriteria(Employee.class);
List l = c.list();
Iterator it = l.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
// Employee e = new Employee(234, "IVS", "Vinay", 6500);
// tx = session.beginTransaction();
// session.save(e);
// tx.commit();
// tx=null;
}
catch(HibernateException ex)
{
System.out.println("Exception occured : " + ex.getMessage());
}
finally
{
System.out.println("Closing the session");
session.close();
}
}
}

Please note the text in red in EmployeeClient class.
Here we have used AnnotationConfiguration because, we have used Annotations in Employee class to map the class fields with the table fields.
If Employee.hbm.xml is used for this mapping then here we would have used Configuration (which we normally do)

SessionFactory factory=new Configuration().configure().buildSessionFactory();