i'm trying to run my first portlet according to this tutorial:
Liferay Developers Guide
I'm using Liferay's 6.0.6 version and this is my code.
<%# taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%# taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%# page import="javax.portlet.PortletPreferences" %>
<portlet:defineObjects />
<liferay-theme:defineObjects />
<%
PortletPreferences prefs = renderRequest.getPreferences();
String greeting = (String)prefs.getValue(
"greeting", "Hello! Welcome to our portal.");
%>
<p><%= greeting %></p>
<portlet:renderURL var="editGreetingURL">
<portlet:param name="jspPage" value="/edit.jsp" />
</portlet:renderURL>
<p>Edit greeting</p>
When i try to run i get error message:
org.apache.jasper.JasperException: An exception occurred processing JSP page /view.jsp at line 8
5: <portlet:defineObjects />
6: <liferay-theme:defineObjects />
7: <%
8: PortletPreferences prefs = renderRequest.getPreferences();
9: String greeting = (String)prefs.getValue("greeting", "Hello! Welcome to our portal!");
10: %>
11: <p><%= greeting %></p>
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
com.liferay.portal.kernel.servlet.PortalClassLoaderFilter.doFilter(PortalClassLoaderFilter.java:53)
com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:110)
com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
com.liferay.portal.kernel.servlet.PortalClassLoaderFilter.doFilter(PortalClassLoaderFilter.java:53)
com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
com.liferay.portal.kernel.servlet.PortalClassLoaderFilter.doFilter(PortalClassLoaderFilter.java:53)
com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
com.liferay.portal.kernel.servlet.PortalClassLoaderFilter.doFilter(PortalClassLoaderFilter.java:53)
com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
com.liferay.portal.kernel.servlet.PortalClassLoaderFilter.doFilter(PortalClassLoaderFilter.java:53)
Have anyone have any idea of what i'm doing wrong?
Delete the contents of tmp and work folders inside tomcat and try again!
Related
I have the following jsp page that has the following lib imports:
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%# taglib uri="/WEB-INF/alfresco.tld" prefix="a"%>
<%# taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<%# taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%# taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%# page buffer="32kb" contentType="text/html;charset=UTF-8"%>
<%# page isELIgnored="false"%>
<%# page import="org.alfresco.web.app.Application"%>
<%# page import="org.alfresco.web.ui.common.PanelGenerator"%>
when i click on Finish button i should have it disabled and the action function should be automatically fired like the following :
<td align="center">
<a4j:commandButton
id="finish-button" styleClass="wizardButton"
value="#{msg.finish_button}"
action="#{creationReclamationBean.terminerReclamation}"
onclick="this.disabled=true;"/>
</td>
The content of the function is the following :
public String terminerReclamation() throws SQLException {
if (!journeeServiceMetier.estJourOuvre(reclamationVO
.getReclamationEtape3VO().getDateReclamation())) {
Utils.addErrorMessage("La date de la demande "
+ reclamationVO.getReclamationEtape3VO()
.getDateReclamation()
+ " ne correspond pas à un jour ouvré ");
return null;
} else if (ireclamationServiceV4.ReclamationExiste(reclamationVO
.getOrdinal(), reclamationVO.getReclamationEtape3VO()
.getDateReclamation(), reclamationVO.getReclamationEtape3VO()
.getActivite().toString(), reclamationVO
.getReclamationEtape3VO().getProduitSelection().toString(),
reclamationVO.getReclamationEtape3VO()
.getOperationselectionne().toString(), reclamationVO
.getEtape1vo().getSiegeSelection(), reclamationVO
.getEtape1vo().getRacine())
&& !reclamationVO.isModeModif()) {
Utils.addErrorMessage("Cette réclamation existe déjà");
return null;
}
when i am debugging the code, the debugging process enters in the "else" conditional statement and the line below is executed but the message doesn't appear in my page.
previously when i used the following component :
<h:commandButton
id="finish-button" styleClass="wizardButton"
value="#{msg.finish_button}"
action="#{creationReclamationBean.terminerReclamation}"
onclick="this.disabled=true;"
/>
instead of a4j:commandButton the error message is displayed normally but the button is not disabled at all.
Can anyone of you give me a help
Thanks
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
Im trying to customize the login portlet for my purpose using this portlet login sample.
But when i login with test#liferay.com with a wrong password it shows "web page is not available"
SignInPortlet.java
public class SignInPortlet extends MVCPortlet {
#Override
public void processAction(
ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
String className = "com.liferay.portlet.login.action.LoginAction";
PortletConfig portletConfig = getPortletConfig();
NoRedirectActionResponse noRedirectActionResponse =
new NoRedirectActionResponse(actionResponse);
try {
PortletActionInvoker.processAction(
className, portletConfig, actionRequest,
noRedirectActionResponse);
}
catch (Exception e) {
_log.error(e, e);
}
String login = ParamUtil.getString(actionRequest, "login");
String password = ParamUtil.getString(actionRequest, "password");
String rememberMe = ParamUtil.getString(actionRequest, "rememberMe");
if (Validator.isNull(noRedirectActionResponse.getRedirectLocation())) {
actionResponse.setRenderParameter("login", login);
actionResponse.setRenderParameter("rememberMe", rememberMe);
}
else {
String redirect =
PortalUtil.getPathMain() + "/portal/login?login=" + login +
"&password=" + password + "&rememberMe=" + rememberMe;
actionResponse.sendRedirect(redirect);
}
}
private static Log _log = LogFactoryUtil.getLog(SignInPortlet.class);
}
View.jsp
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%# taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%# taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%# taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%# page import="com.liferay.portal.CookieNotSupportedException" %>
<%# page import="com.liferay.portal.NoSuchUserException" %>
<%# page import="com.liferay.portal.PasswordExpiredException" %>
<%# page import="com.liferay.portal.UserEmailAddressException" %>
<%# page import="com.liferay.portal.UserLockoutException" %>
<%# page import="com.liferay.portal.UserPasswordException" %>
<%# page import="com.liferay.portal.UserScreenNameException" %>
<%# page import="com.liferay.portal.kernel.language.LanguageUtil" %>
<%# page import="com.liferay.portal.kernel.util.ClassResolverUtil" %>
<%# page import="com.liferay.portal.kernel.util.Constants" %>
<%# page import="com.liferay.portal.kernel.util.GetterUtil" %>
<%# page import="com.liferay.portal.kernel.util.HtmlUtil" %>
<%# page import="com.liferay.portal.kernel.util.MethodKey" %>
<%# page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%# page import="com.liferay.portal.kernel.util.PortalClassInvoker" %>
<%# page import="com.liferay.portal.kernel.util.PropsUtil" %>
<%# page import="com.liferay.portal.model.Company" %>
<%# page import="com.liferay.portal.security.auth.AuthException" %>
<%# page import="javax.portlet.WindowState" %>
<portlet:defineObjects />
<liferay-theme:defineObjects />
<c:choose>
<c:when test="<%= themeDisplay.isSignedIn() %>">
<%
String signedInAs = user.getFullName();
if (themeDisplay.isShowMyAccountIcon()) {
signedInAs = "" + signedInAs + "";
}
%>
<%= LanguageUtil.format(pageContext, "you-are-signed-in-as-x", signedInAs, false) %>
</c:when>
<c:otherwise>
<%
MethodKey methodKey = new MethodKey(ClassResolverUtil.resolveByPortalClassLoader("com.liferay.portlet.login.util.LoginUtil"), "getLogin", HttpServletRequest.class, String.class, Company.class);
String login = GetterUtil.getString((String)PortalClassInvoker.invoke(false, methodKey, request, "login", company));
boolean rememberMe = ParamUtil.getBoolean(request, "rememberMe");
%>
<portlet:actionURL var="loginURL" />
<aui:form action="<%= loginURL %>" method="post" name="fm">
<aui:input name="saveLastPath" type="hidden" value="<%= false %>" />
<aui:input name="<%= Constants.CMD %>" type="hidden" value="<%= Constants.UPDATE %>" />
<aui:input name="rememberMe" type="hidden" value="<%= rememberMe %>" />
<liferay-ui:error exception="<%= AuthException.class %>" message="authentication-failed" />
<liferay-ui:error exception="<%= CookieNotSupportedException.class %>" message="authentication-failed-please-enable-browser-cookies" />
<liferay-ui:error exception="<%= NoSuchUserException.class %>" message="please-enter-a-valid-login" />
<liferay-ui:error exception="<%= PasswordExpiredException.class %>" message="your-password-has-expired" />
<liferay-ui:error exception="<%= UserEmailAddressException.class %>" message="please-enter-a-valid-login" />
<liferay-ui:error exception="<%= UserLockoutException.class %>" message="this-account-has-been-locked" />
<liferay-ui:error exception="<%= UserPasswordException.class %>" message="please-enter-a-valid-password" />
<liferay-ui:error exception="<%= UserScreenNameException.class %>" message="please-enter-a-valid-screen-name" />
<table class="lfr-table">
<tr>
<td>
<aui:input name="login" style="width: 120px;" type="text" value="<%= HtmlUtil.escape(login) %>" />
</td>
</tr>
<tr>
<td>
<aui:input name="password" style="width: 120px;" type="password" value="" />
<span id="<portlet:namespace />passwordCapsLockSpan" style="display: none;"><liferay-ui:message key="caps-lock-is-on" /></span>
</td>
</tr>
<c:if test='<%= company.isAutoLogin() && !GetterUtil.getBoolean(PropsUtil.get("session.disabled")) %>'>
<tr>
<td>
<aui:input checked="<%= rememberMe %>" name="rememberMe" type="checkbox" />
</td>
</tr>
</c:if>
</table>
<br />
<input type="submit" value="<liferay-ui:message key="sign-in" />" />
</aui:form>
<c:if test="<%= renderRequest.getWindowState().equals(WindowState.MAXIMIZED) %>">
<aui:script>
Liferay.Util.focusFormField(document.<portlet:namespace />fm.<portlet:namespace />login);
</aui:script>
</c:if>
<aui:script use="aui-base">
A.one('#<portlet:namespace />password').on(
'keypress',
function(event) {
Liferay.Util.showCapsLock(event, '<portlet:namespace />passwordCapsLockSpan');
}
);
</aui:script>
</c:otherwise>
</c:choose>
Does any one know how to solve this?
I changed the portlet code like this .Now it is ok
public class SignInPortlet extends MVCPortlet {
#Override
public void processAction(
ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
String className = "com.liferay.portlet.login.action.LoginAction";
PortletConfig portletConfig = getPortletConfig();
NoRedirectActionResponse noRedirectActionResponse =
new NoRedirectActionResponse(actionResponse);
try {
PortletActionInvoker.processAction(
className, portletConfig, actionRequest,
noRedirectActionResponse);
}
catch (Exception e) {
_log.error(e, e);
}
String login = ParamUtil.getString(actionRequest, "login");
String password = ParamUtil.getString(actionRequest, "password");
String rememberMe = ParamUtil.getString(actionRequest, "rememberMe");
Object object = SessionErrors.get( actionRequest, AuthException.class.getName() );
if (( object != null ) || Validator.isNull(noRedirectActionResponse.getRedirectLocation())) {
actionResponse.setRenderParameter("login", login);
actionResponse.setRenderParameter("rememberMe", rememberMe);
}
else {
String redirect =
PortalUtil.getPathMain() + "/portal/login?login=" + login +
"&password=" + password + "&rememberMe=" + rememberMe;
actionResponse.sendRedirect(redirect);
}
}
private static Log _log = LogFactoryUtil.getLog(SignInPortlet.class);
}
I have requirement that:
After submitting the request, Liferay displays the message
Your request processed successfully
Instead of that I have to add custom messages and display them like course created
successfully, course deleted successfully, course modified successfully etc..
Is it possible? Is there any way to display the success or failure message?
<%#page import ="javax.portlet.PortletURL" %>
<%# page import="javax.portlet.RenderResponse" %>
<%# page import="javax.portlet.ActionRequest" %>
<%# page import="com.liferay.portal.kernel.util.Validator" %>
<%
PortletURL searchCourseURL=renderResponse.createActionURL();
searchCourseURL.setParameter(ActionRequest.ACTION_NAME,"findCourses");
%>
<script type="text/javascript" src="/html/js/jquery/jquery.js"></script>
<form action="<%=searchCourseURL%>" method="post">
<div class="label1">Enter Course Name</div><input type="text" id="cname" name="cname" value=" "/>
<input type="submit" name="submit" value="Submit"/>
</form>
In the above example, after submitting the request it displays like request process successfully instead I have to display the message:
search is completed
Success messages
In the JSP:
<liferay-ui:success key="key" message="message" />
<liferay-ui:success key="key1" message="message1" />
In Language.properties file
message=search is completed...
message1=search is completed...
In Controller
SessionMessages.add(request, "key");
SessionMessages.add(request, "key1");
Error (failure) messages
In the JSP:
<liferay-ui:error key="error-key" message="error-message" />
<liferay-ui:error key="error-key1" message="error-message1" />
In Language.properties file:
error-message=search couldn't be completed...
error-message1=search couldn't be completed...
In Controller:
SessionErrors.add(request, "error-key");
SessionErrors.add(request, "error-key1");
I'm developing a liferay portlet. This is not my first time doing that, but a get a simple error that I can't understand why I'm getting this error. When I click submit button I get this error
The requested resource was not found. "http://localhost:8081/addProduct"
It's more than hours I'm trying to solve it and I know that I have made a silly mistake. Can any body help me solve this problem? Any help is appreciated in advance. Here is my jsp code:
<%# taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%# taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%# page import="javax.portlet.PortletURL" %>
<portlet:defineObjects />
This is the <b>ServiceBuilderTest</b> portlet.
<portlet:actionURL var="addProduct" name="addProductAction"/>
<aui:form method="post" action="addProduct">
<aui:fieldset>
<aui:input name="productName" label="Product Name"></aui:input>
<aui:input name="userID" label="User ID"></aui:input>
<aui:input name="companyID" label="company ID"></aui:input>
<aui:input name="groupID" label="Group ID"></aui:input>
<aui:input name="serialNumber" label="Serial Number"></aui:input>
<aui:button type="submit" value="Submit"></aui:button>
</aui:fieldset>
</aui:form>
And this is my portlet class code:
public class ServiceBuilderPortlet extends MVCPortlet{
public void addProductAction(ActionRequest actionReauest, ActionResponse actionResponse) throws SystemException, PortalException
{
String productName = actionReauest.getParameter("productName");
String userID = actionReauest.getParameter("userID");
String companyID = actionReauest.getParameter("companyID");
String groupID = actionReauest.getParameter("groupID");
String serialNumber = actionReauest.getParameter("serialNumber");
PRProduct product = PRProductLocalServiceUtil.addProduct(Long.parseLong(companyID), Long.parseLong(groupID), productName,
serialNumber, Long.parseLong(userID));
}
}
make it
<portlet:actionURL var="addProduct" name="addProductAction"/>
<aui:form method="post" action="<%=addProduct%>">
...
actually, I'd see it as best practice to not name the action "addProductAction", but just "addProduct", so the changes would be as such (including one line of java, the rest looks good (visually, not tried/tested):
<portlet:actionURL var="addProduct" name="addProduct"/>
<aui:form method="post" action="<%=addProduct%>">
....
and
public class ServiceBuilderPortlet extends MVCPortlet{
public void addProduct(ActionRequest request, ActionResponse response) throws SystemException, PortalException {
// ...
}
}