Beanshell is a Java scripting language that’s designed to run Java code with little or no changes. Beanshell doesn’t support the use of Java Generics.
Liferay has a great feature to run java code from the UI. Consider you want to check some java API then beanshell is very handy to use. Because for using beanshell you no need to develop anything. You can just run your liferay API directly.
To use beanshell go to your control panel. Access the beanshell as shown in below screen shot
Beanshell UI |
Below are the implicit objects that we can use in beanshell
4. Get the version of your Liferay
- portletConfig
- portletContext
- actionRequest
- actionResponse
- out
Now lets run some Liferay API from the beanshell
1. Display the total number of users:
import com.liferay.portal.model.User;
import com.liferay.portal.service.UserLocalServiceUtil;
import java.util.List;
int userCount = UserLocalServiceUtil.getUsersCount();
out.println(userCount);
2. Find the company ID
import com.liferay.portal.util.PortalUtil;
long companyId = PortalUtil.getCompanyId(actionRequest );
out.println("The comapny Id is : "+companyId);
3. Get current user object
import com.liferay.portal.util.PortalUtil;
import com.liferay.portal.model.User;
User user = PortalUtil.getUser(actionRequest );
out.println("First Name :"+user.getFirstName());
out.println("Last Name :"+user.getLastName());
out.println("Full Name :"+user.getFullName());
4. Get the version of your Liferay
import com.liferay.portal.kernel.util.ReleaseInfo;
String version = ReleaseInfo.getVersion();
out.println("The Liferay Version :"+version);
5. Get theme
import com.liferay.portal.theme.ThemeDisplay ;
import com.liferay.portal.util.WebKeys;
import com.liferay.portal.model.Theme;
ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
Theme theme = themeDisplay.getTheme();
out.println("Current Theme: "+theme.getName());
5. Get theme
import com.liferay.portal.theme.ThemeDisplay ;
import com.liferay.portal.util.WebKeys;
import com.liferay.portal.model.Theme;
ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
Theme theme = themeDisplay.getTheme();
out.println("Current Theme: "+theme.getName());
Here in this session I have given only basics of using beanshell. However you can use this feature according to your requirements. For example consider you have 10,000 users in your portal and now you want update each user with a particular role. In this case you can use this feature instead of doing it manually.
Limitation:
This feature can be used only for Liferay API as well as liferay default services. You will not be able to test your own custom services which are developed as plugin portlet.
Limitation:
This feature can be used only for Liferay API as well as liferay default services. You will not be able to test your own custom services which are developed as plugin portlet.
Your posts is really helpful for me.Thanks for your wonderful post. I am very happy to read your post. It is really very helpful for us and I have gathered some important information from this blog. liferay training in hyderabad
ReplyDeleteThanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog.
ReplyDeleteIt is very nicely explained. Your article adds best knowledge to our Java Online Training from India.
or learn thru Java Online Training from India Students.
yurtdışı kargo
ReplyDeleteresimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
0Z8
Hollanda yurtdışı kargo
ReplyDeleteİrlanda yurtdışı kargo
İspanya yurtdışı kargo
İtalya yurtdışı kargo
Letonya yurtdışı kargo
HSSM
Litvanya yurtdışı kargo
ReplyDeleteLüksemburg yurtdışı kargo
Macaristan yurtdışı kargo
Malta yurtdışı kargo
Polonya yurtdışı kargo
1Z2H
Portekiz yurtdışı kargo
ReplyDeleteRomanya yurtdışı kargo
Slovakya yurtdışı kargo
Slovenya yurtdışı kargo
İngiltere yurtdışı kargo
7GZG
Yunanistan yurtdışı kargo
ReplyDeleteAfganistan yurtdışı kargo
Amerika Birleşik Devletleri yurtdışı kargo
Amerika Samoası yurtdışı kargo
Angola yurtdışı kargo
LLX
شركة تسليك مجاري في العين Pa7cqk6mHT
ReplyDelete