Thursday, April 10, 2008

Generating portlet

  1. open a command prompt then go to mPire folder
  2. ant gen -Dportlet=${portlet}

mPire setup(new liferay)

1. unzip life-{Version(4.3.6,4.4.2, etc)}.zip
2. set the app.server.parent.dir (for example D:/life-4.3.6).
3. unzip mpire-core-4.3.6.zip in to the life-{Version(4.3.6,4.4.2, etc)} directory.
4. open command prompt
4.0. run ant deploy
4.1. run ant setup

Wednesday, April 9, 2008

configuration

1. List Page Configuration(alternate layout)
==========================
a. normal_entity.jsp: for listPage.
b. alternate_entity.jsp for alternate listPage.
c. set alternateList = 1 in list_entity.jsp to change to alternate

2. Normal List Page Configuration, page name is normal_entity.jsp
=================================================================

a. Show / Hide a column by setting (show${columnName} at the top of the page)0 or 1.

b. Enable / Disable Pagination by setting PaginationRequired = 0/1.

c. Enable / Disable Scrollable Table by setting scrollableTable = 0/1.

d. Setting pageSize by pageSize = 0/1

e. Pagination type is by default mpire pagination. Enable the google pagination by uncommenting
//pagination.setFormat(pagination.GOOGLE);
//pagination.setWindow(pageSize);

f. Enable / Disable the add,delete,search,child button by setting corresponding flags to 1/0.

g. Setting table height for tableHeight by 0/1.

3. Other changes
================

a. custom SQL example - ext-impl/classes/custom-sql/defalult.xml,entityName.xml

b. get the sql_id from the entity.xml by using CustomSQLUtil.get(sql_id) in class;

this the sample code for getting and process the id through custom-sql.

try {
//open a new session
session = HibernateUtil.openSession();

//pull out our query from MessageBoards.xml, make sure you have added an entry in the default.xml file
String sql = CustomSQLUtil.get(FIND_BY_GROUP_ID);

//create a SQLQuery object
SQLQuery q = session.createSQLQuery(sql);

q.setCacheable(false);

//replace the "MBMessage" in the query string with the fully qualified java class.. this has to be the hibernate table name
q.addEntity("MBMessage", MBMessageImpl.class);

QueryPos qPos = QueryPos.getInstance(q);

//fill in the "?" value of the custom query
qPos.add(groupId);

//execute the query and return a list from the db
return QueryUtil.list(q, HibernateUtil.getDialect(), begin, end);
}
catch (Exception e) {
throw new SystemException(e);
}
finally {
//must have this to close the hibernate session.. if you fail to do this.. you will have alot of open session..
HibernateUtil.closeSession(session);
}

c. showing links based on roles, some example methods.
package com.mpower.util.CommonUtil

methods - isOperator(user),isAdmin(User user),isUser(User user),isUserInRole(User user, String role)

d. Image file as thumbnail - file taglib display="pagination", in xml thumbnail="yes".

e. For client side validation, set (serverValidation = 0) in ${portlet}.jsp

Custom Queries in mPire

There are 3 files that we will be working with
  • ext/ext-impl/classes/custom-sql/${portlet}.xml
  • ext/ext-impl/src/com/mpower/queryutil/${portlet}.ApiHelper.java
  • extext-impl/classes/custom-sql/default.xml

Step 2) Find the XML files for the queries of the desired portelt

AddressBook.xml









AddressbookApiHelper.java

package com.mpower.queryutil;

import com.liferay.portal.SystemException;
import com.liferay.portal.spring.hibernate.CustomSQLUtil;
import com.liferay.portal.spring.hibernate.HibernateUtil;

import com.liferay.portlet.service.BasePersistence;

import com.mpower.common.addressbook.model.Address;
import com.mpower.common.addressbook.model.impl.AddressImpl;

import org.hibernate.SQLQuery;
import org.hibernate.Session;

import java.math.BigInteger;

import java.util.List;


public class AddressbookApiHelper extends BasePersistence {
public static String GET_RECORD_COUNT = Address.class.getName() +
".getRecordCount";

public static long getRecordCount() throws SystemException {
Session session = null;

try {
long count = 0;

session = HibernateUtil.openSession();

String sql = CustomSQLUtil.get(GET_RECORD_COUNT);

SQLQuery q = session.createSQLQuery(sql);

q.setCacheable(false);

List list = q.list();

if (list != null) {
BigInteger bint = (BigInteger) list.get(0);
count = Long.parseLong(bint.toString());
}

return count;
} catch (Exception e) {
throw new SystemException(e);
}
}
}

package com.mpower.queryutil;

import com.liferay.portal.SystemException;
import com.liferay.portal.spring.hibernate.CustomSQLUtil;
import com.liferay.portal.spring.hibernate.HibernateUtil;

import com.liferay.portlet.service.BasePersistence;

import com.mpower.common.addressbook.model.Address;
import com.mpower.common.addressbook.model.impl.AddressImpl;

import org.hibernate.SQLQuery;
import org.hibernate.Session;

import java.math.BigInteger;

import java.util.List;


public class AddressbookApiHelper extends BasePersistence {
public static String GET_RECORD_COUNT = Address.class.getName() +
".getRecordCount";

public static long getRecordCount() throws SystemException {
Session session = null;

try {
long count = 0;

session = HibernateUtil.openSession();

String sql = CustomSQLUtil.get(GET_RECORD_COUNT);

SQLQuery q = session.createSQLQuery(sql);

q.setCacheable(false);

List list = q.list();

if (list != null) {
BigInteger bint = (BigInteger) list.get(0);
count = Long.parseLong(bint.toString());
}

return count;
} catch (Exception e) {
throw new SystemException(e);
}
}
}

Default.xml







If you are Connecting to Another Datasource/Database. Need two extra steps:

  1. Go to ext-spring-training.xml and get the id trainingSessionFactory or what you name it.
  2. Whith this id, open a new hibernate session on the code above, refering to the another database, like this:
                        //open a new session
session = HibernateUtil.openSession(&trainingSessionFactory);


Criterion class

Criterian class is renamed to Criterion, it includes constructers for making Criterion class now we can create Criterion object by following.

  1. Criterion criterion = new Criterion(String columnName, String operator, String operand1, String operand2).
  2. Criterion criterion = new Criterion(String columnName, String operator, String operand1).
  3. Criterion criterion = new Criterion()

Tuesday, April 8, 2008

special-features tag in portle.xml

add this tag at the top of the ${portlet}.xml inside portlet tag





Features included:
  1. default-properties : this will override the common properties is language-ext.properties(for example instead of add_button it will generate ${portlet}.add_button) so that any modification on this portlet keys will not affect other portlet.

Tabs

to add a new tab
  • Open tabs.jsp modify 'tabNames' add csv of tabs(if the tab-name is same that of your method while clicking the tab will invoke the particular method for example if tab-name specified is "Add Page" it will invoke loadAddPage(then it will load add page) ).
  • If a new page have to be loaded then add method for that page in View${Entity}Action.java
  • If the display name and methode is defferent then specify particular url for each tabs means
    add new attribute in liferay-tag: url0,url1,url2 then append the particular method name to the url, for example if you specify 'New' instead of Add Page in the tag-name then append this code to the particular url(for the first tab it is url0) "&METHOD=Add Page"