Language Specific Custom 404 page in Liferay - liferay-6.2

I know the procedure for adding the custom 404 page. What I want is to fetch user language in 404 page and show the error message in his locale.

Sorry for Posting the question but the answer may be helpful for others. Just create a jsp and add this code there
<%# page import="com.liferay.portal.util.PortalUtil" %>
<%# page import="com.liferay.portal.NoSuchLayoutException" %>
<%# page import="com.liferay.portal.service.LayoutLocalServiceUtil" %>
<%# page import="com.liferay.portal.util.WebKeys" %>
<%# page import="com.liferay.portal.model.LayoutSet" %>
<%# page import="com.liferay.portal.model.User" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
User currentUser=null;
try {
currentUser = PortalUtil.getUser(request);
} catch (Exception e) {
e.printStackTrace();
}
%>

Related

Internalization fmt

I have the page jsp :
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="f" %>
<%# page session="true" %>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%# page session="true" %>
<%# page trimDirectiveWhitespaces="true" %>
<%
String locale = "fr_FR";
%>
<fmt:setLocale value="${locale }"/>
<fmt:bundle basename="com.stock.led.i18n.applicationresources"></fmt:bundle>
I have two properties files on package "com.stock.led.i18n.applicationresources" applicationresources_en_US and applicationresources_fr_FR. The applicationresources_en_US file is always used and the _fr_FR is set By fmt SetLocale, i dont understand why ??
After Research i found that the responsible is the header HTTP "Accept-Language" By testing 3 Browsers , the browser installed in French works perfect and the others on english Nope.
Why <fmt:setLocale value="${locale }"/> doesn't force the language and ignore the header HTTP "Accept-Language".

Why model.addAttribute and ${} is not matching and it shows just . on web?

I just started to learn jsp and spring. I deleted formattedDate (as a default) in HomeController.java and changed to model.addAttribute("answer", "yes") and on web, it only shows . and i don't understand why.
I tried to put definition like String answer = "yes" but it didnt work.
this is HoneController.java:
#Controller
public class HomeController {
#RequestMapping("/main")
public String home(Locale locale, Model model) {
model.addAttribute("answer", "yes");
return "home";
}
}
and here is home.jsp:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page session="false" pageEncoding="UTF-8" %>
<html>
<head>
<title>Home Page</title>
</head>
<body>
<h1>
hello
</h1>
<P> Is it happening? : ${answer}. </P>
</body>
</html>
There was no error messages

Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING error occurs when passing model attributes to the JSP page

I'm passing model attributes to the view from my spring controller but the jsp page is not displayed. In the console i'm getting following error :
net::ERR_INCOMPLETE_CHUNKED_ENCODING 200
The controller :
private final String POYNT_DETAILS_VIEW = "full_poynt_view";
#RequestMapping(value = "/businessDetails/{businessId}/poynt", method = RequestMethod.GET)
public String viewBusinessDetails(Model model, #PathVariable String businessId) throws IOException {
PoyntBusinessDetails poyntBusinessDetails = poyntApiClient.getPoyntBusinessDetails(businessId,poyntCloudBaseBusinessUrl);
model.addAttribute("poyntBusinessDetails", poyntBusinessDetails);
return POYNT_DETAILS_VIEW;
}
The view :
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%# taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%# taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<div style="padding: 5px">
<span class="main-text">Business Name</span>:
<span class="sub-text">${poyntBusinessDetails.legalName}</span>
</div>
The model class :
public class PoyntBusinessDetails {
private String legalName;
// getters and setters
}
Instead of
<span class="sub-text">${poyntBusinessDetails.legalName}</span>
Use
<span class="sub-text"><c:out value="${poyntBusinessDetails.legalName}"/></span>

Display a list by display:table tag in Spring + Hibernate MVC project

I am doing on a MVC project using netbean IDE and I have a problem with displaying my objects on table
This is my jsp page
<%#page import="java.util.List"%>
<%#page import="java.util.ArrayList"%>
<%#page import="model.Clothes"%>
<%#page import="org.hibernate.Session"%>
<%#page import="cfg.HibernateUtil"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%#taglib prefix="display" uri="http://displaytag.sf.net" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Clothes</title>
</head>
<body>
<div style="margin-left: 10%; ">
<%
Session session1 = HibernateUtil.getSessionFactory().getCurrentSession();
List<Clothes> clothes = new ArrayList<Clothes>();
session1.beginTransaction();
clothes = session1.createQuery("from Clothes").list();
session1.getTransaction();
System.out.println(clothes.size() + "aaaaaaaaa");
session1.close();
request.setAttribute("results", clothes);
%>
<display:table name="results" pagesize="10"/>
</div>
<jsp:include page="/index.htm" flush="true"/>
</body>
And the browser display an exception at line contains 'display' tag like this:"org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/clothes.jsp" Where did I do wrong, please help me, I am newbie in java web.
p/s: I add libs in my project, they are: displaytag-1.2, displaytag-export-poi-1.2, displaytag-portlet-1.2 and commons-lang-2.6.
I followed #JB Nizet instruction and it worked, just use the libs exactly the same that listed in this link: http://www.displaytag.org/1.2/displaytag/dependencies.html
However, in some PC, when using org.slf4j, your project can not work properly, just remove them from the project, it is OK!

how to implement optiontransferselect using ajax

I'm trying to implement optiontransferselect using ajax. I can not move the values from left side to right side.I've added <%# taglib uri="/struts-dojo-tags" prefix="sx"%> tags in my code and I've included <sx:head/> also, but it doesn't work. please help me out to solve the issue.
my.jsp
<%#taglib uri="/struts-tags" prefix="s" %>
<%# taglib uri="/struts-dojo-tags" prefix="sx"%>
<head>
<sx:head/>
</head>
<div class="width2 margin-bottom margin-top">
<div class="profile-text">
Preferred Location
</div>
<s:optiontransferselect
id="city"
name="cityNo"
list="cityList"
listKey="id"
listValue="cityName"
headerKey="0"
headerValue="City"
onfocus="getcitywithCountry(false);"
doubleList="prefererList"
doubleId="city"
doubleListKey="cityId.id"
doubleListValue="cityId.cityName"
doubleHeaderKey="0"
doubleHeaderValue="--selected locations--"
doubleName="selectedLocations" allowUpDownOnLeft="false" allowUpDownOnRight="false"/>
</div>
I don't see much wrong with your code. You need to remove <%# taglib uri="/struts-dojo-tags" prefix="sx"%> reference. Replace <sx:head/> with <s:head/>.

Resources