Liferay SearchContainer with multiple classes - liferay

I want to make a date list with patients and doctors, in database have 1: N, and the patients is reference by the id, when i do a simple serach-container the column doctorName is null because the patient class has not a name namedDoctor , Only have idDoctor and the doctorName it owns a doctor class, so i have two classes and 1 search-container and i do not know how to put the names of doctors :/
Search-container
' emptyResultsMessage="empty-cita-menssage-result">
"
total="<%= CitaLocalServiceUtil.getCitasCount() %>"
/>
<
<liferay-ui:search-container-row className="com.everis.formacion.model.Cita"
keyProperty="idCita"
modelVar="cita"
escapedModel="<%= true %>">
<liferay-ui:search-container-column-text
name="fechaCita"
property="<%= CitaPortlet.REQUEST_FECHA_PACIENTE_PARAM %>"
/>
<liferay-ui:search-container-column-text
name="nombrePaciente"
property="<%= CitaPortlet.REQUEST_NOMBRE_PACIENTE_PARAM %>"
/>
<liferay-ui:search-container-column-text
name="nombreDoctor"
property="<%= DoctorPortlet.REQUEST_NOMBRE_PARAM %>"
/>
<liferay-ui:search-container-column-text
name="comentarios"
property="<%= CitaPortlet.REQUEST_COMENTARIO_PARAM %>"
/>
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />

<liferay-ui:search-container-column-text
value="<%= DoctorLocalServiceUtil.getDoctor(cita.getIdDoctor()).getNombreDoctor() %>"
name="Nombre Doctor"
/>
with this return the name of the doctor :)

Related

Liferay 7: hidden aui input won't set value based on parameter

I have an entity with a primary key and two other fields.
I am able to display them in a Search Container in my primary View JSP, and I want to implement an edit/update function, so I created a different JSP for that. I pass the properties of the entity I wish to edit in portlet:renderURL portlet:param tags just like this:
<portlet:renderURL var="editEntity">
<portlet:param name="jspPage" value="/update-page.jsp" />
<portlet:param name="primaryKey" value="<%= entityId %>" />
<portlet:param name="name" value="<%= entityName%>" />
<portlet:param name="description" value="<%= entityDesc%>" />
</portlet:renderURL>
In the update-page JSP if I set any input field hidden, the parameter based values disappear, so the controller cannot process the fields' values.
i.e.:
<aui:input name="primaryKey" type="hidden" value="${primaryKey}" />
<aui:input name="primaryKey" type="hidden" value="${name}" />
<aui:input name="primaryKey" type="hidden" value="${description}" />
Note: I only want to hide the primary key field, the controller servlet should be able to process it and update my entity based on the primary key, like this:
<aui:input name="primaryKey" type="text" value="${name}" />
<aui:input name="primaryKey" type="text" value="${description}" />
The funny thing is, that everything just works when I set the input fields text type, but I wouldn't want the users to enter the primary key, duh...
Any ideas how could I fix this?
It's work for me
view.jsp
<%# include file="init.jsp" %>
<portlet:actionURL name="testURL" var="testURL" />
<aui:form name="fm" method="post" action="<%= testURL.toString()%>">
<aui:input name="primaryKey" type="hidden" value="123" />
<aui:button-row>
<aui:button name="submit" type="submit" value="OK" />
</aui:button-row>
</aui:form>
TestmvcportletPortlet.java
package com.example.portlet;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import com.liferay.portal.kernel.util.ParamUtil;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.Portlet;
import javax.portlet.ProcessAction;
import org.osgi.service.component.annotations.Component;
#Component(
immediate = true,
property = {
"com.liferay.portlet.display-category=category.sample",
"com.liferay.portlet.instanceable=true",
"javax.portlet.display-name=Test Portlet",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user"
},
service = Portlet.class
)
public class TestmvcportletPortlet extends MVCPortlet {
#ProcessAction(name = "testURL")
public void addBook(ActionRequest actionRequest,ActionResponse actionResponse) throws SystemException {
String a = ParamUtil.getString(actionRequest, "primaryKey");
System.out.println("Value is "+a);
}
}
have you found anything that you missed code?
I found a solution to the problem.
So, after long hours of testing I found out that I just could not get the values stored in parameters just as ${paramName} anywhere in a simple HTML tag, but I still don't know why.
What I did was request for the needed values stored within the parameters inside a JSP scriptlet just like this:
<%
String primaryKey = request.getParameter("primaryKey");
String name = request.getParameter("name");
String description = request.getParameter("description");
%>
Then I was good to go with my form:
<aui:form action="<%= updateAbbreviationURL %>" method="post">
<aui:input name="primaryKey" type="hidden" value="<%= primaryKey %>" />
<aui:input name="entityName" label="Name" type="text" value="<%= name %>" />
<aui:input name="entityDesc" label="Description" type="text" value="<%= description %>" />
<aui:button name="submit" value="submit" type="submit" />
<aui:button name="cancel" value="cancel" type="button" onClick="<%= viewURL %>" />
</aui:form>
I'd be really grateful if someone told me why my initial implementation didn't work, I mean referring to the parameter values as mentioned above, ${paramName}
Thanks in advance!

Liferay search container in Spring MVC portlets

Is it possible to use Liferay search container in spring portlets? when i tried, nothing is rendering in the page. i have enclosed the code. am just adding the data in session and trying to show in search container.
<%
final PortletSession sessData = renderRequest.getPortletSession();
List<Detail> details = (List<Detail>) sessData.getAttribute("DETAILS",PortletSession.PORTLET_SCOPE);
%>
<liferay-ui:search-container delta="3" emptyResultsMessage="No Details found" headerNames="User ID, First Name, Last Name, Address">
<%
int numOfRecords = details.size();
%>
<liferay-ui:search-container-results results="<%= details %>" total="${numOfRecords}">
</liferay-ui:search-container-results>
<liferay-ui:search-container-row className="Detail" modelVar="detailData">
<liferay-ui:search-container-column-text name="User ID" property="userId" />
<liferay-ui:search-container-column-text name="First Name" property="firstName" />
<liferay-ui:search-container-column-text name="Last Name" property="lastName" />
<liferay-ui:search-container-column-text name="Address" property="address" />
</liferay-ui:search-container-row>
</liferay-ui:search-container>
I missed to add the search-iterator.
<liferay-ui:search-iterator searchContainer="<%=searchContainer%>"
paginate="<%=isNeeded%>" />

How to add SELECT ALL function in Search Container?

I want to have a SELECT ALL function in my Search Container like this:
This is my code of Search container :
<liferay-ui:search-container delta="5">
<%-- <c:choose>
<c:when test="">
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose> --%>
<liferay-ui:search-container-results
results="<%= RegUserAccountLocalServiceUtil.getRegUserAccounts(searchContainer.getStart(), searchContainer.getEnd()) %>"
total="<%= RegUserAccountLocalServiceUtil.getRegUserAccountsCount() %>"
/>
<liferay-ui:search-container-row
className="com.pmti.bir.triu.model.RegUserAccount"
keyProperty="acctId"
modelVar="aRegUserAccount" >
<liferay-ui:search-container-column-text>
<input name="rowChecker" type="checkbox" value="<%=aRegUserAccount.getAcctId()%>" />
</liferay-ui:search-container-column-text>
<liferay-ui:search-container-column-text
property="acctStatusFlag" name="STATUS"
orderable="<%=true %>"/>
<liferay-ui:search-container-column-text property="acctFirstName"
name="FULL NAME" orderable="<%= true %>"/>
<liferay-ui:search-container-column-text property="acctEmailAdd"
name="USERNAME" orderable="<%= true %>"/>
<liferay-ui:search-container-column-text property="acctBusinessName" name="POSITION" orderable="<%= true %>"
orderableProperty="acctLevelStatus"/>
<liferay-ui:search-container-column-text property="createdBy"
name="DIVISION" orderable="<%=true %>"/>
<liferay-ui:search-container-column-text property="acctUsername" name="USER TYPE" orderable="<%= true %>"
orderableProperty="acctUsername"/>
<liferay-ui:search-container-column-jsp
align="right"
path="/html/viewuseraccount/view_user_actions.jsp"
/>
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>
And this is what it looks like:
How will I achieve to have a Select all inside my Search container? I don't know how. Please help me. Thank you very much in advance! Good day!
You have to specify rowChecker attribute to search-container tag.
e.g. rowChecker=<%=new RowChecker(renderResponse)%>
And you can get all-selected values by example code below.
Liferay.Util.listCheckedExcept(document.<portlet:namespace />fm, "<portlet:namespace />allRowIds");

Query optimization in liferay

I have created a portlet where I want to print the list of users based on some parameter. So for showing list of users I use the following code,
<liferay-ui:search-container delta="10" emptyResultsMessage="no-users-were-found">
<liferay-ui:search-container-results
results="<%= UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount())%>"
/>
<liferay-ui:search-container-row
className="com.liferay.portal.model.User"
keyProperty="userId"
modelVar="user"
>
<liferay-ui:search-container-column-text
name="name"
value="<%= user.getFullName() %>"
/>
<liferay-ui:search-container-column-text
name="first-name"
property="firstName"
/>
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>
<liferay-ui:search-container delta="10" emptyResultsMessage="no-users-were-found">
But i don't want all the users list. I need only the list of users whose facebookId = 12345. How can query the condition? Any suggestions please..
Thanks in advance

How to have editable fields through liferay search container?

I am new to liferay development.
I have done good work to display the liferay grid by using liferay search container.
But now the requirement is that some of the fields in the grid should have provision to be modified by user.
Is it possible through liferay search container or do I need to follow any other approach to achieve editable liferay grid?
You can use <liferay-ui:search-container-column-jsp tag or directly use <aui-input /> inside the <liferay-ui:search-container-column-text tag.
Example (I have included code comments with the code sample for your understanding):
<liferay-ui:search-container
emptyResultsMessage="no-assets-selected"
iteratorURL="<%= configurationRenderURL %>"
total="<%= assetEntries.size() %>"
>
<liferay-ui:search-container-results
results="<%= assetEntries.subList(searchContainer.getStart(), searchContainer.getResultEnd()) %>"
/>
<liferay-ui:search-container-row
className="com.liferay.portlet.asset.model.AssetEntry"
escapedModel="<%= true %>"
keyProperty="entryId"
modelVar="assetEntry"
>
<aui:form action="doesThisWork?">
<%-- this is the normal way --%>
<liferay-ui:search-container-column-text
name="type"
value="<%= assetRendererFactory.getTypeName(locale, false) %>"
/>
<liferay-ui:search-container-column-date
name="modified-date"
value="<%= assetEntry.getModifiedDate() %>"
/>
<%--
this is the JSP way
You can include anything in the JSP like <input /> fields, textarea, select drop-down etc.
--%>
<liferay-ui:search-container-column-jsp
align="right"
path="/html/portlet/asset_publisher/asset_selection_action.jsp"
/>
<%--
Here is including <input /> field inside the column text field.
Notice I am not using the "value" attribute of this tag, instead I am
writing HTML inside the body of this tag.
--%>
<liferay-ui:search-container-column-text
name="type"
>
<aui:input type="text" name="enterSomething" value="I can enter input here" />
<aui:input type="text" name="enterSomething" value="<%=assetEntry.getTitle %>" />
<aui:input type="hidden" name="enterSomething" value="this is a hidden field of the form" />
</liferay-ui:search-container-column-text>
</aui:form>
</liferay-ui:search-container-row>
<liferay-ui:search-iterator paginate="<%= total > SearchContainer.DEFAULT_DELTA %>" />
</liferay-ui:search-container>
In the above example, there would be a <form> for each row, so you can have a submit button at the end of each row to submit the data for that row.
But you can do it in other ways as well:
You can write the <form> outside the Search-container tag so that you just have one form and can submit all the row data togather
Or else you can have a <form> somewhere down the page and through javascript populate the value in the form and then submit.
Or else you can use ajax and other stuff to accomplish this. Or a combination of several approaches.
I leave this upto you to figure out.
Disclaimer: I have not test this code. But as per my understanding this should work. :-)

Resources