I am using Liferay DXP SP7. I'm trying to get Liferay's SessionErrors and SessionMessages to add success & error messages to a page containing a custom portlet via an overridden Liferay MVCAction class
- com.liferay.dynamic.data.lists.form.web.internal.portlet.action.AddRecordMVCActionCommand. I'm using the technique explained here to override this internal class because we need to augment some of the Liferay forms functionality by adding things like the ability to edit a form after it's been submitted. This is working just fine. The issue I am running into is that I can't seem to get Liferay's SessionMessages and SessionErrors functionality to work. All I want to do is display error or success messages to the user to let them know if a form save worked. My forms are displayed by a custom portlet that retrieves forms via ajax call to Liferay's DDLFormPortlet (which actually calls my custom AddRecordMVCActionCommand). In the custom AddRecordMVCActionCommand I add success or error messages using SessionMessages.add(actionRequest, "formSaveSuccess"); or SessionErrors.add(actionRequest, "formSaveError");. I have my Language.properties file in src/main/resources/content with the follownig content:
form-save-success=Report saved successfully.
form-save-error=An unexpected error occurred while trying to save the report, please try again.
My JSP page has the following required imports & tags:
<%# taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%# include file="/init.jsp" %>
<liferay-ui:success key="formSaveSuccess" message="form-save-success" />
<liferay-ui:error key="formSaveError" message="form-save-error" />
I have followed the instructions found in Liferay's documentation here to add my languages keys, set up the JSP & add the messages to the session in my MVCAction class. I have read and re-read these instructions several times and everything appears to be set up correctly. I get no error messages in the log, yet my success & error messages never show up. Any help that someone could provide would be very helpful.
Related
I have an iframe inside a jsp which is for processing payment using a third party payment provider.
When I get the response from payment provider, I use another jsp file just for breaking out of iframe (using javascript, as I could not find anything to do this in jsp, and probably there is no such way to do it in jsp AFAIK).
Now, the problem for me is the error scenario. When I receive some error from the payment provider, I want to display that on top of the page where I am redirecting to after breaking from iframe.
We use flash attributes for dispalying the error messages while doing redirect from spring mvc using redirect:.
But I am not sure how to do that when using a browser redirect.
One solution (Post/Redirect/Get pattern) I could think of is to append the error respone in the url which I am using in the redirect from breaking out of iframe.
But this would require changes to our jstl tag files and that will be different from the design of our existing code.
Can anyone point me to some better solution for this?
I ended up using session variable.
So just added a session variable in controller, and before the view was passed on from the last controller, copied the session variable into the redirect flash attributes and then it worked. I know this may not sound good enough, but that's how I had to make it work.
I am working on a jsp/servlet web application. I currently use a switch statement within my servlet to select the appropriate error message for each form field (according to the input) and then set that message as a request attribute.
I now want to internationalize the web page (have it available in another language). I was thinking to do this by having a separate directory for the other language and placing the jsps in the other language in that directory. Then a filter will redirect to the appropriate directory via a session attribute.
The problem is that my custom error messages are currently written in the servlet. I was not planning to reroute to different servlets according to the language (ie: same servlet will run for all languages).
The only way that I can think of to do this would be to write each of the custom error messages on the jsp and then have the servlet set a request attribute that identifies the error type.
This solution would require adding a lot of text to the jsps (some fields have 10 different error messages and different messages depending on user type).
Any suggestions of a better approach for making the form error messages multi lingual are welcome.
Also, if there are any general suggestions on a better way to internationalize my site altogether that is also welcome.
Thank you,
.
I have to create a little webshop for a school-project, but entered in to a problem during the process by updating/refreshing the Servlets.
Description:
I created an index.html file which includes two servlets via iframes, the left side for Navigation-Servlet and on the right the Controller-Servlet does something to show a welcome page (or shows off the categories etc.) - works all fine.
But now I have to implement a login with an small administration.
By clicking in the navigation on Administration, it leads to another Servlet called Administration-Servlet, in the right iframe (actually not over the Controller-Servlet).
There comes up a login mask, where the user put in his username and password. If the login was correct, it leads then to the administration content (not finished by now).
The upcoming problem is now that I somehow have to update/refresh the Navigation iframe too, when the login was successful because there must be the Logout-Button and some entries have to be hidden.
By which "technique" or pattern I can solve this problem? Maybe a little code example would be helpful. :)
Best greets.
Instead of using Iframes to put together the different parts of your site, use dynamic include in your servlets. This will allow you to build the response page server side and therefore dynamically change what is included in a page. When you log in you send the authentication request to the servlet which will then dynamically construct the new response from multiple JSP files.
<jsp:include page="..." />
Another solution is to use a scripting language like Apache Velocity Template scripts to build your responses dynamically. Allowing you to include or exclude information depending on parameters or session context.
I am making a Java application for Liferay. A simple bookstore. Uploading and displaying the app in Liferay works, but when i try to access other pages then the index page itself I get an error.
This is how my application looks like at the moment. If i for instance click on "All books" in the navigation to the left. I get an error.
This is the error I get, as explained earlier. It says "The requested resource was not found."
""
Any help on what to do, would be greatly appreciated :)
Your first screenshot shows /web/student-life, while the second one shows a URL that looks like a servlet URL, not a portlet URL: /book?action=allBooks.
Note that - in the portal world - you'll lose control over the URLs and you'll need the portal to generate them to you. This typically means that they'll be a lot more ugly than the one you're seeing. You can gain back control (through "friendly URLs" in Liferay) but I'd consider this a second (or third) thought if you're just beginning developing portlets.
Create your action URL with <portlet:actionURL .../> and - for the time being - stay on the same page. Once everything works you can extend this to multiple pages.
I have spring mvc application using apache tiles.Main file is template.jsp which includes header.jsp, then got place for potential messages and footer.jsp included.
Is there a way to check within jsp page ( using JSTL ) on which page I'm inside header.jsp code ?
Normal way of getting page URL are not good because
${pageContext.request.servletPath}
Always get's me the page I supposed to be so , template:
/WEB-INF/tiles/template.jsp
Is there a way to do it somehow , without adding anything to model from within spring?
(Because this is one of way to do this )
You can access the page URL (as it would appear in the browser) using the following EL in your JSP:
${requestScope['javax.servlet.forward.request_uri']}