Hello Guy's
Some time many of us faces difficultly in searching record from dynamic data list in Liferay 6.2, so for your help below I am mentioning how you can do this-
Here I have created two methods for search record from dynamic data list in liferay 6.2.
ddlRecordnew.get(i).getField("firstName").getValue()
Here :
"ddlRecordnew" is instance of List<DDLRecord> and "firstName" is field name of data list in dynamic data list.
So now :
ddlRecordnew.get(i).getField("FieldName").getValue()
Following method print the matched record from searchString to database.
public void SearchDdlRecord(String searchString){
List<DDLRecord> ddlRecordnew = null;
try {
ddlRecordnew = DDLRecordLocalServiceUtil.getDDLRecords(-1, Integer.MAX_VALUE);
if (ddlRecordnew != null) {
StringTokenizer strPermit = null;
String ptype = null;
for (int i = 0; i < ddlRecordnew.size(); i++) {
if (isRecordMatchingSearchCriteria(searchString, ddlRecordnew.get(i)) ) {
strPermit = new StringTokenizer(String.valueOf(ddlRecordnew.get(i).getField("permitType").getValue()),"[]\"");
while (strPermit.hasMoreTokens()) {
ptype = strPermit.nextToken().trim();
}
System.out.println(ddlRecordnew.get(i).getRecordId()+" "+ddlRecordnew.get(i).getField("firstName").getValue()+" "+ddlRecordnew.get(i).getField("lastName").getValue());
}
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
Following method match the searchString to database record and return boolean .
public boolean isRecordMatchingSearchCriteria(String searchString,
DDLRecord ddlRecord) {
try {
if (searchString == null || searchString.length() < 0
|| searchString.equals(""))
return true;
searchString = searchString.toUpperCase();
String searchStringArr[] = searchString.split(" ");
for (int i = 0; i < searchStringArr.length; i++) {
String recordId = ddlRecord.getRecordId() + "";
if (recordId.contains(searchStringArr[i]))
return true;
if (ddlRecord.getField("firstName").getValue().toString()
.toUpperCase().contains(searchStringArr[i]))
return true;
if (ddlRecord.getField("lastName").getValue().toString()
.toUpperCase().contains(searchStringArr[i]))
return true;
if (new DateBefore()
.UIdateFormats(
(ddlRecord.getCreateDate().toGMTString())
.toString()).toUpperCase()
.contains(searchStringArr[i]))
return true;
if (ddlRecord.getField("phoneNumber").getValue().toString()
.toUpperCase().contains(searchStringArr[i]))
return true;
if (ddlRecord.getField("Email").getValue().toString()
.toUpperCase().contains(searchStringArr[i]))
return true;
if (ddlRecord.getField("permitType").getValue().toString()
.toUpperCase().contains(searchStringArr[i]))
return true;
if (ddlRecord.getField("address").getValue().toString()
.toUpperCase().contains(searchStringArr[i]))
return true;
if (ddlRecord.getField("describeBusiness").getValue()
.toString().toUpperCase().contains(searchStringArr[i]))
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
That's it! Thank you :)
0 Comment(s)