error TLD use in a jsp file - java

I have the following line of code in a JSP File in my web app t
<% if (!maintenance) { %>
<customTag:DialogEntry entry="<%=new com.presentation.generic.session.DialogEntry("dialog1","225px","true","true",new String[]{"authentification.Login.action.logInApplicationLabel"},new String[]{"logInApplication()"}) %>"/>
<% } else { %>
<customTag:DialogEntry entry="<%=new com.presentation.generic.session.DialogEntry("dialog1","225px","true","true",new String[]{},new String[]{}) %>"/>
<% } %>
The error message that I get is:
/WEB-INF/tags/DialogEntry.tag According to the TLD , the value
attribute accepts no expression
How do I resolve this problem?
DialogEntry.tag:
<%# attribute name="entry" rtexprvalue="true" type="com.presentation.generic.session.DialogEntry" %>
<%# taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<%# taglib uri="http://struts.apache.org/tags-html-el" prefix="html" %>
<%# taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean" %>
<%# taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%# taglib uri="http://struts.apache.org/tags-logic-el" prefix="logic" %>
<script type="text/javascript">
//confirm("<c:out value="${entry.id}" /> début");
var <c:out value="${entry.id}" /> = new YAHOO.widget.Dialog("<c:out value="${entry.id}" />",
{
width: "<c:out value="${entry.size}" />",
<c:if test="${\"\" != entry.visible}">
visible:true,
</c:if>
<c:if test="${\"\" == entry.visible}">
visible:false,
</c:if>
close:false,
draggable :false
<c:if test="${\"\" != entry.effect}">
,effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}
} );
</c:if>
<c:if test="${\"\" == entry.effect}">
} );
</c:if>
<c:if test="${\"false\" != entry.hasButtons}">
var myButtons = [
<c:forEach var="button" items="${entry.buttons}" varStatus="ind">
{ text:"<bean:message key="${button}"/>", handler:function() {<c:out value="${entry.functions[ind.index]}" />;}, isDefault:true }
<c:if test="${!empty entry.buttons[ind.index+1]}">
,
</c:if>
</c:forEach>
];
<c:out value="${entry.id}" />.cfg.queueProperty("buttons", myButtons);
</c:if>
// confirm("<c:out value="${entry.id}" /> fin - debut script");
if($.browser.msie && $('#header').size() > 0 ){
// confirm("<c:out value="${entry.id}" /> fin - debut script IE");
var menuWidth = $("div#menu").get(0).clientWidth;
var headerHeight = $("div#header").get(0).clientHeight;
var width = document.body.clientWidth;
var contentWidthConnected = width - menuWidth;
if( $('div#content_onglets').size() > 0){
// confirm("<c:out value="${entry.id}" /> fin - debut script IE Onglet");
<c:out value="${entry.id}" />.cfg.queueProperty("x", 50);
<c:out value="${entry.id}" />.cfg.queueProperty("y", 0);
}
else{
// confirm("<c:out value="${entry.id}" /> fin - debut script IE Pas Onglet");
<c:out value="${entry.id}" />.cfg.queueProperty("x", menuWidth + 50);
<c:out value="${entry.id}" />.cfg.queueProperty("y", headerHeight );
}
// confirm("<c:out value="${entry.id}" /> fin - FIN script IE");
}
else{
<c:out value="${entry.id}" />.cfg.queueProperty("fixedcenter", true);
}
// confirm("<c:out value="${entry.id}" /> fin script");
<c:out value="${entry.id}" />.render();
// confirm("<c:out value="${entry.id}" /> fin script 2");
</script>

Either escape your inner quotes:
<% if (!maintenance) { %>
<customTag:DialogEntry entry="<%=new com.presentation.generic.session.DialogEntry(\"dialog1\",\"225px\",\"true\",\"true\",new String[]{\"authentification.Login.action.logInApplicationLabel\"},new String[]{\"logInApplication()\"}) %>"/>
<% } else { %>
<customTag:DialogEntry entry="<%=new com.presentation.generic.session.DialogEntry(\"dialog1\",\"225px\",\"true\",\"true\",new String[]{},new String[]{}) %>"/>
<% } %>
Or use single quotes:
<% if (!maintenance) { %>
<customTag:DialogEntry entry='<%=new com.presentation.generic.session.DialogEntry("dialog1","225px","true","true",new String[]{"authentification.Login.action.logInApplicationLabel"},new String[]{"logInApplication()"}) %>'/>
<% } else { %>
<customTag:DialogEntry entry='<%=new com.presentation.generic.session.DialogEntry("dialog1","225px","true","true",new String[]{},new String[]{}) %>'/>
<% } %>
Reading the error message is quoted with " which must be escaped when used within the value you see that having " inside your text is the cause. Hence, either your text is not defined with " (the second solution, where you use ') or the " inside the text have a \ to escape them and make them actual characters in the text.

Escape all " with \" inside your block:
entry=""

Related

Liferay 6.2 Media Gallery

<%--
/**
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
--%>
<%# include file="/html/portlet/image_gallery_display/init.jsp" %>
<%
Folder folder = (Folder)request.getAttribute(WebKeys.DOCUMENT_LIBRARY_FOLDER);
long defaultFolderId = GetterUtil.getLong(portletPreferences.getValue("rootFolderId", StringPool.BLANK), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
long folderId = BeanParamUtil.getLong(folder, request, "folderId", defaultFolderId);
boolean defaultFolderView = false;
if ((folder == null) && (defaultFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {
defaultFolderView = true;
}
if (defaultFolderView) {
try {
folder = DLAppLocalServiceUtil.getFolder(folderId);
}
catch (NoSuchFolderException nsfe) {
folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
}
}
long repositoryId = scopeGroupId;
if (folder != null) {
repositoryId = folder.getRepositoryId();
}
int status = WorkflowConstants.STATUS_APPROVED;
if (permissionChecker.isContentReviewer(user.getCompanyId(), scopeGroupId)) {
status = WorkflowConstants.STATUS_ANY;
}
long portletDisplayDDMTemplateId = PortletDisplayTemplateUtil.getPortletDisplayTemplateDDMTemplateId(displayStyleGroupId, displayStyle);
%>
<c:choose>
<c:when test="<%= portletDisplayDDMTemplateId > 0 %>">
<%
String[] mediaGalleryMimeTypes = DLUtil.getMediaGalleryMimeTypes(portletPreferences, renderRequest);
List fileEntries = DLAppServiceUtil.getGroupFileEntries(scopeGroupId, 0, folderId, mediaGalleryMimeTypes, status, 0, SearchContainer.MAX_DELTA, null);
%>
<%= PortletDisplayTemplateUtil.renderDDMTemplate(pageContext, portletDisplayDDMTemplateId, fileEntries) %>
</c:when>
<c:otherwise>
<%
String topLink = ParamUtil.getString(request, "topLink", "home");
long assetCategoryId = ParamUtil.getLong(request, "categoryId");
String assetTagName = ParamUtil.getString(request, "tag");
boolean useAssetEntryQuery = (assetCategoryId > 0) || Validator.isNotNull(assetTagName);
PortletURL portletURL = renderResponse.createRenderURL();
portletURL.setParameter("struts_action", "/image_gallery_display/view");
portletURL.setParameter("topLink", topLink);
portletURL.setParameter("folderId", String.valueOf(folderId));
request.setAttribute("view.jsp-folder", folder);
request.setAttribute("view.jsp-defaultFolderId", String.valueOf(defaultFolderId));
request.setAttribute("view.jsp-folderId", String.valueOf(folderId));
request.setAttribute("view.jsp-repositoryId", String.valueOf(repositoryId));
request.setAttribute("view.jsp-viewFolder", Boolean.TRUE.toString());
request.setAttribute("view.jsp-useAssetEntryQuery", String.valueOf(useAssetEntryQuery));
request.setAttribute("view.jsp-portletURL", portletURL);
%>
<portlet:actionURL var="undoTrashURL">
<portlet:param name="struts_action" value="/document_library/edit_entry" />
<portlet:param name="<%= Constants.CMD %>" value="<%= Constants.RESTORE %>" />
</portlet:actionURL>
<liferay-ui:trash-undo portletURL="<%= undoTrashURL %>" />
<liferay-util:include page="/html/portlet/document_library/top_links.jsp" />
<c:choose>
<c:when test="<%= useAssetEntryQuery %>">
<liferay-ui:categorization-filter
assetType="images"
portletURL="<%= portletURL %>"
/>
<%
SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, "cur2", SearchContainer.DEFAULT_DELTA, portletURL, null, null);
OrderByComparator orderByComparator = DLUtil.getRepositoryModelOrderByComparator("modifiedDate", "desc");
searchContainer.setOrderByComparator(orderByComparator);
long[] classNameIds = {PortalUtil.getClassNameId(DLFileEntryConstants.getClassName()), PortalUtil.getClassNameId(DLFileShortcut.class.getName())};
AssetEntryQuery assetEntryQuery = new AssetEntryQuery(classNameIds, searchContainer);
assetEntryQuery.setEnablePermissions(true);
assetEntryQuery.setExcludeZeroViewCount(false);
int total = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);
searchContainer.setTotal(total);
List results = AssetEntryServiceUtil.getEntries(assetEntryQuery);
searchContainer.setResults(results);
String[] mediaGalleryMimeTypes = null;
request.setAttribute("view.jsp-mediaGalleryMimeTypes", mediaGalleryMimeTypes);
request.setAttribute("view.jsp-searchContainer", searchContainer);
%>
<liferay-util:include page="/html/portlet/image_gallery_display/view_images.jsp" />
</c:when>
<c:when test='<%= topLink.equals("home") %>'>
<aui:row>
<c:if test="<%= folder != null %>">
<liferay-ui:header
localizeTitle="<%= false %>"
title="<%= folder.getName() %>"
/>
</c:if>
<%
SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, "cur2", SearchContainer.DEFAULT_DELTA, portletURL, null, null);
String[] mediaGalleryMimeTypes = DLUtil.getMediaGalleryMimeTypes(portletPreferences, renderRequest);
int foldersCount = DLAppServiceUtil.getFoldersCount(repositoryId, folderId, true);
int total = DLAppServiceUtil.getFoldersAndFileEntriesAndFileShortcutsCount(repositoryId, folderId, status, mediaGalleryMimeTypes, true);
int imagesCount = total - foldersCount;
searchContainer.setTotal(total);
List results = DLAppServiceUtil.getFoldersAndFileEntriesAndFileShortcuts(repositoryId, folderId, status, mediaGalleryMimeTypes, true, searchContainer.getStart(), searchContainer.getEnd(), searchContainer.getOrderByComparator());
searchContainer.setResults(results);
request.setAttribute("view.jsp-mediaGalleryMimeTypes", mediaGalleryMimeTypes);
request.setAttribute("view.jsp-searchContainer", searchContainer);
%>
<aui:col cssClass="lfr-asset-column lfr-asset-column-details" width="<%= showFolderMenu ? 75 : 100 %>">
<div id="<portlet:namespace />imageGalleryAssetInfo">
<c:if test="<%= folder != null %>">
<div class="lfr-asset-description">
<%= HtmlUtil.escape(folder.getDescription()) %>
</div>
<div class="lfr-asset-metadata">
<div class="lfr-asset-icon lfr-asset-date">
<%= LanguageUtil.format(pageContext, "last-updated-x", dateFormatDate.format(folder.getModifiedDate())) %>
</div>
<div class="lfr-asset-icon lfr-asset-subfolders">
<%= foldersCount %> <liferay-ui:message key='<%= (foldersCount == 1) ? "subfolder" : "subfolders" %>' />
</div>
<div class="lfr-asset-icon lfr-asset-items last">
<%= imagesCount %> <liferay-ui:message key='<%= (imagesCount == 1) ? "image" : "images" %>' />
</div>
</div>
<liferay-ui:custom-attributes-available className="<%= DLFolderConstants.getClassName() %>">
<liferay-ui:custom-attribute-list
className="<%= DLFolderConstants.getClassName() %>"
classPK="<%= (folder != null) ? folder.getFolderId() : 0 %>"
editable="<%= false %>"
label="<%= true %>"
/>
</liferay-ui:custom-attributes-available>
</c:if>
<liferay-util:include page="/html/portlet/image_gallery_display/view_images.jsp" />
</div>
</aui:col>
<c:if test="<%= showFolderMenu %>">
<aui:col cssClass="lfr-asset-column lfr-asset-column-actions" last="<%= true %>" width="<%= 25 %>">
<div class="lfr-asset-summary">
<liferay-ui:icon
cssClass="lfr-asset-avatar"
image='<%= "../file_system/large/" + ((total > 0) ? "folder_full_image" : "folder_empty") %>'
message='<%= (folder != null) ? HtmlUtil.escape(folder.getName()) : LanguageUtil.get(pageContext, "home") %>'
/>
<div class="lfr-asset-name">
<h4><%= (folder != null) ? HtmlUtil.escape(folder.getName()) : LanguageUtil.get(pageContext, "home") %></h4>
</div>
</div>
<%
request.removeAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
%>
<liferay-util:include page="/html/portlet/document_library/folder_action.jsp" />
</aui:col>
</c:if>
</aui:row>
<%
if (folder != null) {
IGUtil.addPortletBreadcrumbEntries(folder, request, renderResponse);
if (!defaultFolderView && portletName.equals(PortletKeys.MEDIA_GALLERY_DISPLAY)) {
PortalUtil.setPageSubtitle(folder.getName(), request);
PortalUtil.setPageDescription(folder.getDescription(), request);
}
}
%>
</c:when>
<c:when test='<%= topLink.equals("mine") || topLink.equals("recent") %>'>
<%
long groupImagesUserId = 0;
if (topLink.equals("mine") && themeDisplay.isSignedIn()) {
groupImagesUserId = user.getUserId();
}
SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, SearchContainer.DEFAULT_CUR_PARAM, SearchContainer.DEFAULT_DELTA, portletURL, null, null);
String[] mediaGalleryMimeTypes = DLUtil.getMediaGalleryMimeTypes(portletPreferences, renderRequest);
int total = DLAppServiceUtil.getGroupFileEntriesCount(repositoryId, groupImagesUserId, defaultFolderId, mediaGalleryMimeTypes, status);
searchContainer.setTotal(total);
List results = DLAppServiceUtil.getGroupFileEntries(repositoryId, groupImagesUserId, defaultFolderId, mediaGalleryMimeTypes, status, searchContainer.getStart(), searchContainer.getEnd(), searchContainer.getOrderByComparator());
searchContainer.setResults(results);
request.setAttribute("view.jsp-mediaGalleryMimeTypes", mediaGalleryMimeTypes);
request.setAttribute("view.jsp-searchContainer", searchContainer);
%>
<aui:row>
<liferay-ui:header
title="<%= topLink %>"
/>
<liferay-util:include page="/html/portlet/image_gallery_display/view_images.jsp" />
</aui:row>
<%
PortalUtil.addPortletBreadcrumbEntry(request, LanguageUtil.get(pageContext, topLink), currentURL);
PortalUtil.setPageSubtitle(LanguageUtil.get(pageContext, topLink), request);
%>
</c:when>
</c:choose>
</c:otherwise>
</c:choose>
i m using Liferay 6.2 and using Media Gallery Portlet to display the images which is placed in Multiple folders. i have multiple folders which contain multiple images but the folders are arranged according to alphabetical order but my requirement is to arrange the folders which are recently updated (i,e the recently updated folder must come at the top) so can anybody please provide solution how to achieve this.
thanks in Advance.
Over-ride view.jsp of /html/portlet/image_gallery_display by either hook or ext and add following two lines below the initialization of SearchContainer object at about line# 115:
OrderByComparator orderByComparator =
DLUtil.getRepositoryModelOrderByComparator("modifiedDate", "desc");
searchContainer.setOrderByComparator(orderByComparator);
This will order your Media Gallery's folders and images descending by modified date.
Update:
If you want to control this behavior from preferences, then:
Declare and initialize these properties in init.jsp:
String sortByCol = portletPreferences.getValue("sortByCol", "title");
String sortByOrder = portletPreferences.getValue("sortByOrder", "desc");
Add following drill-downs for value selection in
configuration.jsp:
<div class="aui-column left-selector-column">
<aui:select label="Sort By" name="preferences--sortByCol--">
<aui:option label="Title" value="title"
selected="<%= sortByCol.equals("title") %>" />
<aui:option label="Create Date" value="creationDate"
selected="<%= sortByCol.equals("creationDate") %>"/>
<aui:option label="Modified Date" value="modifiedDate"
selected="<%= sortByCol.equals("modifiedDate") %>" />
</aui:select>
</div>
<div class="aui-column right-selector-column">
<aui:select label="Order" name="preferences--sortByOrder--">
<aui:option label="Ascending" value="asc"
selected="<%= sortByOrder.equals("asc") %>"/>
<aui:option label="Descending" value="desc"
selected="<%= sortByOrder.equals("desc") %>"/>
</aui:select>
</div>
Add these two lines in view.jsp below the
initialization of SearchContainer:
OrderByComparator orderByComparator =
DLUtil.getRepositoryModelOrderByComparator(sortByCol, sortByOrder);
searchContainer.setOrderByComparator(orderByComparator);

Using template in Underscore JAVA

How to use underscore java template library for using template in java.
Library : https://github.com/javadev/underscore-java
Sample Template:
<h2>
<%- listTitle %>
</h2>
<ul>
<% _.each( listItems, function( listItem ){ %>
<li>
<%- listItem.name %>
<% if ( listItem.hasOlympicGold ){ %>
<em>*</em>
<% } %>
</li>
<% }); %>
</ul>
<% var showFootnote = _.any(
_.pluck( listItems, "hasOlympicGold" )
); %>
<% if ( showFootnote ){ %>
<p style="font-size: 12px ;">
<em>* Olympic gold medalist</em>
</p>
<% } %>
How can populate this template in java.
Thanks.

Tag <c:if> doesn't work

I have method to get Cookies, and compare returned boolean with , but it doesn't work. Both condition doesn't work.
static public boolean isUserAuth(HttpServletRequest request){
String cookieName = "forum_login";
Cookie cookies [] = request.getCookies ();
Cookie myCookie = null;
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
if (cookies[i].getName().equals (cookieName)) {
myCookie = cookies[i];
return true;
}
}
}
return false;
}
JSP page:
<%# page import="db_Proccesing.Users_processing" %>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
boolean test = Users_processing.isUserAuth(request);
%>
<!DOCTYPE html>
<header>
<a class="header-logo"></a>
<div id="form_text" class="form">
<c:if test = "${test == true}">
<p>TRUE</p>
</c:if>
<c:if test = "${test == false}">
<p>FALSE</p>
</c:if>
</div>
</header>
So, doesn't printed TRUE and FALSE
I fix it, using:
<c:if test = "<%= !Users_processing.isUserAuth(request) %>">
Thank's all.

jsp if variable starts with

I need view if variable starts with keys "ef", like ef1, efabc, efanythink... and if yes, show error message, i past here mix of php and jsp, of course incorrect and with errors, i no understand jsp:
<c:if test="${empty channel.getChannelName()}">
<%
if (string_starts_with(${channelName}, 'ef')) { header("location:http://google.com"); }
or show this div of error
<div class="error"> This Channel url Portected!</div>
Original file: http://pastebin.com/ach8PXY9
<%# taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
<%# taglib uri = "http://java.sun.com/jsp/jstl/functions" prefix = "fn" %>
<c:if test='${fn:startsWith(channel.channelName, "ef")}'>
...
</c:if>
<c:if test='${not fn:startsWith(channel.channelName, "ef")}'>
...
</c:if>
OR you can use
'<c:choose> <c:when>'
Theres a JSTL method for that!
<c:choose>
<c:when test="${fn:startsWith(channel.getChannelName(), "ef")}">
<script type="text/javascript">window.location.replace("http://google.com/");</script></c:when>
<c:otherwise>
<div class="error"> This Channel url Portected!</div>
</c:otherwise>
</c:choose>
http://docs.oracle.com/javaee/5/jstl/1.1/docs/tlddocs/fn/tld-summary.html
also possible:
if (channelName != null && channelName.indexOf("ef") == 0) {
%><div class="error"> This Channel url Portected!</div><%
}

jsp error when using if-else with html

I have the following in my jsp page (assume that client is an object )
<%
if( client == null)
%>
NO client
<%
else
%>
<a href='page.jsp?aid=<%=client.getID()%>'> and his name is <%=client.getName()%>
thanks
You're missing the brackets:
<% if( client == null) { %>
NO client
<% } else { %>
<a href='page.jsp?aid=<%=client.getID()%>'> and his name is <%=client.getName()%>
<% } %>
That said, this is an example of bad JSP code. Consider using JSTL tags / expressions instead of scriptlets.
in jstl it would be something similar to
<c:choose>
<c:when test="${client is null}">
NO client
</c:when>
<c:otherwise>
<A href="<c:url value="page.jsp" >
<c:param name="aid" value="${client.ID}" />
</c:url>"
> and his name is <c:out value="${client.name}"/>
</c:otherwise>

Categories