<context-param>
<param-name>jmesaPreferencesLocation</param-name>
<param-value>WEB-INF/jmesa.properties</param-value>
</context-param>
Place Jmesa related css,js and image files inside css,js and images folders respectively, all these folders are under WebContent. Please see the set up image below:
public class CustomHtmlRowRenderer extends HtmlRowRendererImpl
{
public Object render(Object item, int rowcount)
{
HtmlBuilder html = new HtmlBuilder();
html.tr(1);
html.id(getCoreContext().getLimit().getId() + "_row" + rowcount);
//Get the actual value of ok field
Object okValueObj = ItemUtils.getItemValue(item, "ok");
String valueStr = String.valueOf(okValueObj).toLowerCase();
if (valueStr.contains("true"))
{
html.style("background-color:green");
}
else
{
html.style(getStyle());
}
html.styleClass(getStyleClass(rowcount));
html.append(getRowEvents(item, rowcount));
html.close();
return html.toString();
}
}
Now we need to inform the Tablefacade object about this renederer .Inside getHtml we do this by the following lines of code
/*
* Override and customize the sorting of the table facade
*/
ColumnSort customColumnSort = new CustomColumnSort();
tableFacade.setColumnSort(customColumnSort);
Before row rendering customization, the grid was like :
public class CustomColumnSort implements ColumnSort
{
public Collection<?> sortItems(Collection<?> items, Limit limit)
{
ComparatorChain chain = new ComparatorChain();
SortSet sortSet = limit.getSortSet();
Iterator sortItr= sortSet.getSorts().iterator();
while(sortItr.hasNext())
{
Sort sort =(Sort)sortItr.next();
GenericComparator genericComparator = null;
if (sort.getOrder() == Order.ASC)
{
if(sort.getProperty().equalsIgnoreCase("age"))
{
genericComparator= new GenericComparator(sort.getProperty(),true,GenericComparator.NUMERIC_STRING);
}
if(sort.getProperty().equalsIgnoreCase("displayDate"))
{
genericComparator= new GenericComparator(sort.getProperty(),true,GenericComparator.DATE_STRING);
}
}
else if (sort.getOrder() == Order.DESC)
{
/*
* For descending sort one extra parameter sorting mode (value false)
* is passed to the GenericComparator.
* By default its value is true.
*
*/
if(sort.getProperty().equalsIgnoreCase("age"))
{
genericComparator= new GenericComparator(sort.getProperty(),true,GenericComparator.NUMERIC_STRING,false);
}
if(sort.getProperty().equalsIgnoreCase("displayDate"))
{
genericComparator= new GenericComparator(sort.getProperty(),true,GenericComparator.DATE_STRING,false);
}
}
/*
* This is the main place where the Generic comparator is added to the
* ComparatorChain for sorting
*
*/
chain.addComparator(genericComparator);
}
if (chain.size() > 0)
{
Collection((List<?>) items, chain);
}
return items;
}
}
Now we need to inform the HtmlTable object about this custom sort object .Inside getHtml we do this by the following lines of code:
HtmlTable table = (HtmlTable) tableFacade.getTable();
HtmlRow row = table.getRow();
/*
* Override and customize the rendering of the table facade
*/
CustomHtmlRowRenderer customHtmlRowRenderer = new CustomHtmlRowRenderer();
row.setRowRenderer(customHtmlRowRenderer) ;
GenericComparator comparator= new GenericComparator(<String fieldNameToBeSorted>)
For hybrid java data type you need to create the comparator like
public GenericComparator(<String fieldNameToBeSorted>,<boolean hybridDataType>,<String hybridDataTypeName>)
GenericComparator genericComparator= new GenericComparator(sort.getProperty(),true,GenericComparator.NUMERIC_STRING);
If it was a normal data type the code would have been like:
GenericComparator genericComparator= new GenericComparator(sort.getProperty());
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (1)
Author
Commented:First of all I apologize to mwvisa1 as I could not respond on time .I am very sorry that I could not help the the editor mwvisa1 and myself to make the article a better one .
Many thanks to the experts exchange team for publishing my article .
Regards,
Ayan