Wednesday 23 May 2018

Birthday Portlet

<%
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd");
List<EmployeeDetails> list = EmployeeDetailsLocalServiceUtil.getEmployeeDetailses(-1, -1);
List<EmployeeDetails> blist = new ArrayList<>();
Date date = new Date();
for(EmployeeDetails e : list){
Date dob = e.getDob();
if( dob.getDate() == date.getDate() && dob.getMonth() == date.getMonth()){
blist.add(e);
}
}
%>
<%if(blist.isEmpty()){%>
<b>There is no B day</b>
<%}else if(!list.isEmpty()){
for(EmployeeDetails emp : blist){%>
<%

FileEntry dlfileentry = DLAppServiceUtil.getFileEntry(emp.getFileEntryId());
String imageURL ="/documents/" + dlfileentry.getGroupId() + "/"
+ dlfileentry.getFolderId() + "/" + dlfileentry.getTitle()
+ "/" + dlfileentry.getUuid();
%>
<a href="<%=imageURL%>"><img src="<%=imageURL%>" alt="image" class="mmm"/></a>

<p class="bday nomargin"><%=emp.getEmployeename() %></p>
<b class="wish">Wish you happy B day</b>

<%String dates=formatter.format(emp.getDob()); %>

<p class="bday"><%=dates%></p>
<%} }%>


Search By User Name

In jsp

<%PortletURL userNameURL = renderResponse.createActionURL();
userNameURL.setParameter(ActionRequest.ACTION_NAME, "userfilter");%>
<%
List<Billclaim> bill = null;
if(request.getAttribute("fn") != null){
bill = (List<Billclaim>) request.getAttribute("fn");
}else{
bill = BillclaimLocalServiceUtil.getBillclaims(-1, -1);
}
%>
<aui:form method="POST" name="fm" action="<%=userNameURL.toString() %>" >
<aui:input type="text" label="" name="userName" placeholder="Search By User Name">
</aui:input>
<aui:button type="submit" value="Search"/>
</aui:form>

BillclaimLocalServiceImpl.java
public List<Billclaim> getUserName(String userName){
   return billclaimPersistence.findByuserName(userName);
}

Controller
 public void userfilter(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException, SystemException, PortalException {
  String userName = ParamUtil.getString(actionRequest, "userName");
  List<Billclaim> fn = BillclaimLocalServiceUtil.getUserName(userName);
  actionRequest.setAttribute("fn", fn);
  actionResponse.setRenderParameter("jspPage", "/billView.jsp");
  SessionMessages.add(actionRequest, "searched");
  }

Service.xml
<finder name="userName" return-type="Collection">
<finder-column name="userName"></finder-column>
 </finder>