Portlet jsp + jquery datatable +servlet implementation - java

I have created a liferay portlet using mvc (jsp ) and i'm using JQuery for datatable.
I have succeeded to bring a list and display it on a table using Jquery.
Now, I'm trying to make it editable to use CRUD functions.
The problem that i'm using java not php and i couldn't assign a servlet function (doget).i didn't understand it well (how to use it) and they set the url of this class to jquery.
If i'm not wrong this would be configured in web.xml (servlet mapping). So i wonder how to properly configured and use it?
Also, i don't know jquery but it seems that the buttons needs to be manually included. is there any method to include them directly? (with jquery looks and pop up).
Servlet comes in 2.4 version i had troubles changing it to 3.0 using eclipse.
Best Regards

If you use web.xml and servlets, you are out of liferay and the implementation for user login, themeDisplay, permissions and other features. This way is dificult and improductive.
Better choice is override the method "serveResource" of your portlet, in this method you have all control like in servlets and you can use other features of liferay.
In this question you have an example and more information:
respond to http request with json object in portlet

Related

Role based menu in Java EE

I am using Spring MVC for my web application. My views are JSP based. What is the best practice to show role based menus?
Should I make a check on the JSP page for a role?
Should I build the menu in a Java class and pass it to a JSP page to show up?
Anything else?
Use a framework like Spring Security instead of implementing the complete security infrastructure on your own. Like all other Spring modules, you would simply configure the framework declaratively using XML (for defining roles etc.) and so it's quite flexible.
Spring Security comes with its own tag library that you would then use to secure your HTML elements. For example, to make a menu item available for Admin roles only just wrap it in an appropriate <sec:authorize> tag.
References:
Spring Source is a good place to begin with. Have a look at this video as well from their YouTube channel. Getting Started with Spring Security 3.1
Make different role based menu pages and include them in you main content page at runtime.

Spring MVC equivalent of .Net MVC LinkExtensions.ActionLink Method

I am coming from a ASP.Net MVC world where Microsoft provides the LinkExtensions.ActionLink method in Razor (their version of JSP) to generate anchor element (a element) to a specific controller/action.
The concept is pretty simple: the Razor (JSP) code references the controller and action, the ActionLink function does the hard work of generating the correct URI to get to that controller/action.
Is there anything like this in Spring MVC?
Unfortunately, Spring doesn't support this at the moment, although there is a feature request for it. The best you can do right know is use <spring:url> and hardcode the path to the controller and action. <spring:url> will give you a context-root-relative URL.
Part of the difficulty in implementing this is that Spring gives you the power to arbitrarily define your mappings (i.e. with #RequestMapping). So if you're not using ControllerClassNameHandlerMapping it can be an issue.

How to obtain Liferay session in custom servlet?

I wrote custom servlet in Liferay and want to know which user page calls it and know other parameters like theme. But the request's attributes and session fields are all nulls.
How to make custom servlet to receive request as if portlet does?
Thanks
P.S. I don't want to use this solution https://www.everit.biz/web/guest/blog/-/blogs/getting-current-liferay-user-in-a-standalone-webapp?_33_redirect=/web/guest/blog
which reads cookies manually. I want to do such as Liferay does, i.e. by using it's API. Is it possible?
Update 1.
I have a portlet and a servlet in one WAR. I can know who am I (logged in user) from within portlet JSP like this:
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
themeDisplay.getUser()
Now I want to do the same from a servlet. Is it possible?
I am working in eclips which deploys automatically.
You either have to mimic what Liferay does in the portlet request handling (not recommended) or, alternatively, put your servlet code into a portlet - this can be the "resource handling" of a portlet - here you get full access to the http request and can do everything yourself with regards to data types transmitted in the stream.
I'd rather recommend this as it will be significantly easier to upgrade. Portlet Resource Handler are very similar to servlets from a logical point of view. There might be other (more advisable) options, but this is what comes to my mind for this type of problem.

Content of the ServletResponseObject or servletresponsewrapper

I have a simple web application running in Tomcat. There is a servlet which is forwarding the request and response to a jsp page which in turn prints something to the browser.
Now I have an aspect which captures the response. In this case a HttpServletResponse. Now what I want to do is that I want to capture the reponse and add some content in it to be displayed in the browser through JSP page.
I dont want to add the content in the jsp page rather I want to add some content without changing my jsp or servlet, using runtime weaving functionality of aspectJ.
I have not been able to figure out any solution yet.Please help me with this.Thanks.
We don't do that with the response. Request object is a better candidate for that. You must understand that JSP is a server-side technology, therefore your request used to be alive in the JSP page.
Moreover, I would suggest you to look at Servlet Filters, those are meant for this kinda scenarios.

Websphere Portlet migration, missing parameter in DispatchAction

I'm migrating an old portlet application from WPS5 to WPS6. The application is using IBM legacy container. According to the migration guide, I only renew some portal library and some tag reference. The application is still using IBM legacy container and the modified Struts Portlet.
When I create a link like by:
<html:link page="/page1.do?method=display">Go to Page 1</html:link>
The link render such url:
/wps/.../...[hash-like chars]_spf_strutsAction=!2fpage1.do!3fmethod%3ddisplay#[hash-like chars]
I'm using DispatchAction, which would look up parameter 'method' for dispatch. However, click on the above link cannot pass the 'method' parameter to dispatchAction. Further investigation on the request parameter found out this key-value pair:
name: spf_strutsAction
value: !2fpage1.do!3fmethod=display
So it's quite obviously that request.getParameter('method') returns null because the parameter is buried under request.getParameter('spf_strutsAction') and thus the action cannot be dispatched.
Of course I can force the dispatch action by reading the buried parameter. But the problem is that there are many other parameter other than 'method'.
I think that the portal server should provides its implementation of PortletRequest. Is that the PortletRequest.getParameter() is somehow incorrect? Or is it the Portlet Struts Problem? How can I put those parameters back inside the request object?
Some ideas:
You could use the portlet tags to generate the links.
Check out the "newer" struts jars that come with IBM Portal 6.0
Consider using a better portlet web framework, such as Spring Portlet MVC, which is jsr168 compliant. IBM will not be supporting it's old portlet model in the future.

Categories