May 11, 2012

Paging Algorithm

Paging Algorithm
int topage = maxRecords * currentPage;
int offset = topage - (maxRecords);

May 9, 2012

Struts - Formating Text, Date or Number


Formating Pattern

format.time = {0,time}
format.number = {0,number,#0.0##}
format.percent = {0,number,##0.00'%'}
format.money = {0,number,\u00A4##0.00}

Formatting a number

<s:property value="getText('{0,number,#,##0.00}',{product.price})" />

May 8, 2012

JAVA - Reading file relatively

This will all getting the base path of you application to know how/where to read the file

Eclipse

Java Application


* File function
File fXmlFile = new File("test.xml");
The will look on the PROJECT_DIR path.
/YOUR/PROJECT_DIR/test.xml
* FileInputStream
FileInputStream is = new FileInputStream("test.cfg.xml");

The will look on the ECLIPSE path.
/YOUR/ECLIPSE_DIR/test.cfg.xml

*
Loader context
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
classLoader.getResource(".").getPath()
This will return: PROJECT_DIRt/build/classes/

Web Application(Running in Tomcat)


*
Loader context
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
classLoader.getResource(".").getPath()
This will return the path TOMCAT_DIR/lib/

* File function
File fXmlFile = new File("test.xml");
The will look on the ECLIPSE_DIR path.
/YOUR/ECLIPSE_DIR/test.xml

Deployed


* Java Application

* Web Application(Running in Tomcat)
* Loader context
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
classLoader.getResource(".").getPath()
This will return the path TOMCAT_DIR/lib/

* File function
File fXmlFile = new File("test.xml");
The will look on the
TOMCAT_DIR path.
/TOMCAT_DIR/test.xml

May 2, 2012

Java: org.hibernate.ObjectNotFoundException: No row with the given identifier exists:

None-annotated

<many-to-one name="employee" class="Employee"
column="CITY_ID" not-null="false" lazy="false" not-found="ignore">
</many-to-one>

Annotated

@NotFound(action=NotFoundAction.IGNORE)
@OneToOne
@JoinColumn(name="CITY_ID")
private City city;
// your getter and setter here