Search This Blog

Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Monday, April 27, 2015

JAVASCRIPT/ JQuery Page Redirection

 

JAVASCRIPT/ JQuery Page Redirection

 

1. window.location.href="http://www.yahoo.com";

2. window.history.back(-1);                                     //  back

3. window.navigate("top.jsp");                                  // old-IE-only

4. self.location="top.htm";

5. top.location="error.jsp";

6. window.location = window.location.host;

7. $(location).attr('href',"http://www.yahoo.com");            //jQuery

8. $(window).attr("location","http://www.yahoo.com");        //jQuery

9. window.location.replace("http://www.yahoo.com");

10. window.location.assign("http://www.yahoo.org");

11. document.location.href = '/path';

12. window.history.go(-1);                                     //  back

13. $(location).prop('href',"http://www.yahoo.com");          //  jquery 

14.setTimeout(function(){
              window.location.href="<%=url%>"; // redirect after 5 seconds
   }, 5000);
 

Friday, October 18, 2013

To make JSP compatible with IE8 or IE 9

Add the following code to the javascript block.

#if ($browserSniffer.getMajorVersion($request) < 9)
  <meta http-equiv="X-UA-Compatible" content="IE=8" />
#else
  <meta http-equiv="X-UA-Compatible" content="IE=9" />
#end

this will make the jsp compatible with IE 8 or IE 9

Happy Coding !!

 

Wednesday, July 24, 2013

Form re submission of/on Page Reload Errror

The property 'action-url-redirect' must be added to the liferay-portlet.xml file. This will not allow the form to be re submitted once the page is refreshed after a form submission is already done.




By default the property is false and thus the form resubmission occurs

Friday, July 19, 2013

Running liferay script on control Panel Script console

Liferay has a script console at the Control Panel. It is accessible to the Liferay administrator. In the Script console Liferay API code , and other various code can be run seamlessly.

The script console is located at

ContolPanel --> Server --> Server Administration. 






 Here are few examples of codes run in the console and screenshot of the output. Most of the  codes were run here by selecting the Language as "Groovy".

Example 1.  Get list of users

Language : Groovy
code:

import com.liferay.portal.service.UserLocalServiceUtil;

userCount = UserLocalServiceUtil.getUsersCount();
users = UserLocalServiceUtil.getUsers(0, userCount);
count=0;
for (user in users) {
    count++;
    println(count+". User: " + user.getFullName());

}





































Example 2.  Get list of roles supported be the portal.


Language : Groovy
code:

import com.liferay.portal.service.RoleLocalServiceUtil;

roleCount =RoleLocalServiceUtil.getRolesCount();
roles=RoleLocalServiceUtil.getRoles(0,roleCount );

for(role in roles){
    println("Role Name: " + role.getName());
}




Example 3.  Get number of users in the portal . (using Javascript as language default script)
Language : Javascript
code:

number = Packages.com.liferay.portal.service.UserLocalServiceUtil.getUsersCount();

out.println(number);



Tuesday, July 16, 2013

How to get the current logged in user in liferay

There are more than one way to do this. Let's look at some of the options available.
  1. User user = (User) request.getAttribute(WebKeys.USER);
    The User class is the Liferay's model User class.

  2. ThemeDisplay td  = (ThemeDisplay) request.getAttribute( WebKeys.THEME_DISPLAY );
    User user = td.getUser();


    This ' ThemeDisplay 'class can be used to get various information about the portal page,user and theme. Classes ThemeDisplay, User and WebKeys are available in portal-service.jar

  3. User currentUser = PortalUtil.getUser( request );

    The 'PortalUtil' has various utility functions , which come handy during Liferay Programming. This is also a part of the Portal-service.jar.

  4. LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
    User currentUser=liferayFacesContext.getUser();


    The class 'PortalFacesContext' has been renamed to 'LiferayFacesContext'.This class exists in order to assist with migrating old JSF 1.2 based projects from the legacy PortletFaces-Tools project to the new LiferayFaces project.

    Hope It helps you in your portal programming. Happy Coding :)


Friday, July 16, 2010

Add Javascript to Ice Faces or Facelets

There are several ways to add JavaScript code to an ice faces page. One of which is explained here.The "Direct to Dom" (akaD2D) rendering of icefaces makes it difficult to add javascript or any other code to it.

Q. Where to add the code? .
Ans. The answer is to put the < script type="text/javascript"> just code after the < ice:root> between < html> < head> .add the javascript in the similar way as you add it in jsp/html. then close the tag and at the end before closing the root (i.e < /ice:root> ) add the < /html> tag.

Q. How to call an icefaces componet?
Ans. Use the formname:componentid format to use it in the javascript function.

Q. How to use the body onload thing without using body tag.
Ans. The answer lies in using the window event.

Here is an example which makes everything clear


< jsp:root version="2.0" f="http://java.sun.com/jsf/core" h="http://java.sun.com/jsf/html" ice="http://www.icesoft.com/icefaces/component" jsp="http://java.sun.com/JSP/Page">
< f:view>
< script type="text/javascript>
function setFocusOnLogin(){ document.getElementById("icefaces_formaname:icefaces_component_id").focus(); }//its used to call the icefaces component's focus event
window.attachEvent("onload", setFocusOnLogin);//like body onload , its called on page load < /script>
< ice:portlet>
< ice:form id="icefaces_formaname">
< ice:inputtext id="icefaces_component_id" size="10">
< /ice:inputtext>
< /ice:form>
< /ice:portlet>
< /f:view>
< /jsp:root>

Hope you get it. For any concerns feel free to post a comment.

My Blog List