liferay-ui view selecting a row - liferay

I'm working on a portlet for showing a list of rules, for selection.
And I want to focus the row of content selected on my database (rules variable loaded on init.jsp).
What I should do for focusing/highlighting exactly one row?
Should I use <c:when <c:otherwhise for all the .jsp:
I show a list of rules with this code:
<%# taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<liferay-ui:search-container emptyResultsMessage="there-are-no-products" delta="5">
<liferay-ui:search-container-results>
<%
List<IRRule> tempResults = ActionUtil.getRules(renderRequest);
results = ListUtil.subList(tempResults, searchContainer.getStart(),
searchContainer.getEnd());
total = tempResults.size();
pageContext.setAttribute("results", results);
pageContext.setAttribute("total", total);
%>
</liferay-ui:search-container-results>
<liferay-ui:search-container-row
className="com.everis.oriol.inputrules.model.IRRule"
keyProperty="ruleId"
modelVar="rule">
<liferay-ui:search-container-column-text
name="ruleName"
property="ruleName"
/>
<liferay-ui:search-container-column-text
name="ruleDescription"
property="ruleDescription"
/>
<liferay-ui:search-container-column-jsp
path="/row.jsp"
align="right"
/>
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>
In the init.jsp file I have...
<%
long groupId = themeDisplay.getScopeGroupId();
List<IRSelect> rulesPas = IRSelectLocalServiceUtil.getRule(groupId);
String rules = rulesPas.get(0).getRuleName();
%>
I exactly want to compare...
<liferay-ui:search-container-column-text
name="ruleName"
property="ruleName"
/>
with...
rules
Thank you for your help

One of the ways I can think of is by setting the bold attribute of <liferay-ui:search-container-row> tag
which would show the element as bold if its value is true:
<liferay-ui:search-container-row
className="com.everis.oriol.inputrules.model.IRRule"
keyProperty="ruleId"
modelVar="rule"
bold="<%=rules.equals(rule.getRuleName()) %>">
...
</liferay-ui:search-container-row>
Or by setting a CSS class for the entire row if you want more options to style the row:
<liferay-ui:search-container-row
className="com.everis.oriol.inputrules.model.IRRule"
keyProperty="ruleId"
modelVar="rule">
<%
if (rules.equals(rule.getRuleName())) {
// here "row" is the ResultRow object, instance for each row
row.setClassName("my-custom-css-class");
}
%>
<liferay-ui:search-container-column-text
name="ruleName"
property="ruleName"
/>
...
</liferay-ui:search-container-row>
If you want that only the rule column text in that one row should be shown differently and not the entire row then:
<liferay-ui:search-container-column-text
name="ruleName"
property="ruleName"
cssClass="<%=rules.equals(rule.getRuleName()) ? \"my-custom-css-class\" : \"\" %>"
/>

Related

Liferay SearchContainer with multiple classes

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 :)

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%>" />

Issue with Liferay UI tab Navigation

I am using <liferay-ui:tabs> for displaying jsp pages as tabs. I am able to see my pages as tabs but If I navigate to one of my pages in the tab and on click of the button then it is navigating to some other page, that it showing in a separate page instead of showing under that tab. I need to click of button events the control should be still under the tabs. my Code is as follows,
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%><%#include file="/html/users/init.jsp"%>
<portlet: defineObjects />
<portlet:renderURL var="navigateTabURL"/>
<% String navigateTab = ParamUtil.getString(request, "tabs1","Current"); %>
<liferay-ui:tabs names="Current, Available" url="<%=navigateTabURL.toString()%>" >
<c:if test='<%= navigateTab.equalsIgnoreCase("Current")%>' >
<jsp:include page="current_members.jsp" flush="true" />
</c:if>
<c:if test='<%= navigateTab.equalsIgnoreCase("Available")%>' >
<jsp:include page="available_members.jsp" flush="true" />
</c:if>
</liferay-ui:tabs>
The pages "Current" and "Available" are showing correctly, But If I click any button in my Current page it is navigating to some other jsp I need that jsp also under that tabs only not showing as a separate page.
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%><%#include file="/html/users/init.jsp"%>
<portlet: defineObjects />
<%
List<User> userList = (List) request.getAttribute("UserGroupList");
//out.println(userList.size());
%>
<%!
List<User> users = null;
int totalNoOfUsers=0;
String value = null;
%>
<%
//totalNoOfUsers = UserLocalServiceUtil.getUsersCount();
totalNoOfUsers = userList.size();
users = userList;
%>
<liferay-ui:search-container delta="5" emptyResultsMessage="no-users-were-found" rowChecker="<%= new RowChecker(renderResponse) %>" >
<liferay-ui:search-container-results results="<%= ListUtil.subList(users,searchContainer.getStart(),searchContainer.getEnd()) %>"
total="<%= totalNoOfUsers %>">
</liferay-ui:search-container-results>
<liferay-ui:search-container-row className="com.liferay.portal.model.User" keyProperty="userId" modelVar="user">
<liferay-ui:search-container-row-parameter name="userIds" value="<%= user.getUserId()%>">
</liferay-ui:search-container-row-parameter>
<liferay-ui:search-container-column-text name="UserName" value="
<%= user.getScreenName()%>" />
<liferay-ui:search-container-column-text name="First Name" value="<%= user.getFirstName() %>">
</liferay-ui:search-container-column-text>
<liferay-ui:search-container-column-text name="Last Name" value="<%= user.getLastName() %>">
</liferay-ui:search-container-column-text>
<liferay-ui:search-container-column-jsp align="right" path="/html/users/custom_user_actions.jsp" />
</liferay-ui:search-container-row>
<liferay-ui:search-iterator />
</liferay-ui:search-container>
<liferay-ui:search-container delta="5" emptyResultsMessage="no-users-were-found" />
<portlet:actionURL name="viewEntry" var="viewEntryURL"></portlet:actionURL>
<aui:form action="<%= viewEntryURL %>" name="<portlet:namespace />fms">
<aui:button type="submit" value="Cancel"></aui:button>
</aui:form>
How do I navigate the tabs as dynamic requests. Any suggestions please!!
To retain a tab selection, "value" attribute of should be mentioned with name of tab to select.
If "value" attribute not specified then first tab will be considered as active.
For example, please refer following file in liferay portal sources.
portal-web/docroot/html/portlet/dockbar/add_panel.jsp
Also, below post in liferay forum should help.
http://www.liferay.com/en_GB/community/forums/-/message_boards/message/4809190

How to set the selected value in aui:select box

I have form with select box in my user form. I also need to update the form in edit mode. I am able to get selected value in edit mode. But I am unable to set the selected value in the edit mode.
Here I am able to get the selected value from db. <%=user.getTitle() %> Now how can I set the selected value in my select box.
<aui:select name="title">
<aui:option label="Dr" value="dr" />
<aui:option label="Mr" value="mr" />
<aui:option label="Mrs" value="mrs" />
<aui:option label="Ms" value="ms" />
</aui:select>
Example I aset the selected value for input field like this,
<aui:input name="emailAddress" value=""></aui:input>
Any suggestions please!!
You can set selected value as:
Hard-coded Options:
<aui:select name="title">
<aui:option label="Dr" value="dr" selected="<%=user.getTitle().equals("dr") %>" />
<aui:option label="Mr" value="mr" selected="<%=user.getTitle().equals("mr") %>" />
<aui:option label="Mrs" value="mrs" selected="<%=user.getTitle().equals("mrs") %>" />
<aui:option label="Ms" value="ms" selected="<%=user.getTitle().equals("ms") %>" />
</aui:select>
Dynamic Options:
<aui:select name="title">
<%for(int i = 0; i < listOfOptions.size(); i++){
Object option = listOfOptions.get(i);
boolean selected = false;
if(user.getTitle().equals(option.getTitle())){
selected = true;
} %>
<aui:option label=<%=option.getTitle() %> value="<%=option.getValue() %>" selected=<%=selected %> />
<%} %>
</aui:select>
A cleaner way to do it:
<aui:select name="title">
<c:forEach items="${listOfOptions}" var="currOption">
<option value="${currOption}"<c:if test="${currOption == title}"> selected="selected"</c:if>>
${currOption}
</option>
</c:forEach>
</aui:select>
You can use ternary operator
<c:forEach var="currOption" items="${listOfOptions}">
<aui:option value="${currOption}" label="${currOption}" selected="${currOption==selOption?true:false}" />
</c:forEach>

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