Friday, April 12, 2013

AJAX in Liferay Portlets Example

A working example for Liferay Portal with AJAX using AUI

3 components here. init.jsp, view.jsp and the portlet, in this case I call it AjaxTestPortlet and it extends GenericPortlet. init.jsp contains the basic setup stuff like "page" and "taglib" imports for liferay jsps.

Here is the code for the view.jsp

<%@ include file="init.jsp" %>

<portlet:resourceURL var="testLink" id="test22" />


<h1>Ajax Test</h1>
<div id="<portlet:namespace />testDiv">
    <label for="<portlet:namespace />name">Enter Name</label>
    <div>
        <input id="<portlet:namespace />name" name="usernameField" type="text" maxlength="255" value=""/>   
    </div>

    <label for="<portlet:namespace />age">Enter Age</label>
    <div>
        <input id="<portlet:namespace />age" name="incidentField" type="text" maxlength="255" value=""/>    
    </div>
</div>

<button onClick="javascript:<portlet:namespace />ajaxTest()">Test Ajax</button>

<script type="text/javascript">
    function <portlet:namespace />ajaxTest()
    {
        var url = '<%= testLink.toString() %>';
        AUI().use( function(A){
           
            var name1 = document.getElementById("<portlet:namespace />name").value;
            var age1 = document.getElementById("<portlet:namespace />age").value;
           
            A.io.request(url, {
                data: {
                    name: name1,
                    age: age1
                },
                dataType: 'json',
                on: {
                    failure: function(){
                    },

                    success: function(event, id, obj)
                    {
                        console.log("Ajax Test worked!!!!" + name1 + " and " + age1);
                        alert("Ajax Test Worked!!!!!" + name1 + " and " + age1);
                    }
                }
            });
        });
    }

</script>

And here is the code for the AjaxTestPortlet

 import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class AjaxTestPortlet extends GenericPortlet {

    private static Log log = LogFactory.getLog(AjaxTestPortlet.class);

    protected static String viewJSP = "";

    public void init() throws PortletException {
        viewJSP = getInitParameter("view-jsp");
    }

    public void processAction(ActionRequest aReq, ActionResponse aResp) throws IOException,    PortletException {

    }

    public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
            throws IOException, PortletException {

        include(viewJSP, renderRequest, renderResponse);
    }

    protected void include(String path, RenderRequest renderRequest, RenderResponse renderResponse)
            throws IOException, PortletException {
        PortletRequestDispatcher portletRequestDispatcher = getPortletContext()
                .getRequestDispatcher(path);
        if (portletRequestDispatcher == null) {
            log.error(path + " is not a valid include!");
        } else {
            portletRequestDispatcher.include(renderRequest, renderResponse);
        }
    }

}

Tuesday, April 2, 2013

HTML5 Summary


Playing with HTML5 Tags

small tag - Created April 2nd, 2013 by Sean Gildea

Figure Tag

Captions for images
About image
AdvertisedOn.com



Content Editable

Try editing the text in the unordered list below
  • Break mechanical cab driver.
  • Drive to abandoned factory
  • Watch video of self 


Email Inputs, Autofocus, Placeholders and Required

Try submitting anything but a validly formed email.


HTML5 Local Storage

Go ahead and edit the text in the Unordered List and then refresh the browser


HTML5 Form features

Try submitting anything but a validly formed email.


Range Input

Total Recall Awesomness Gauge

Javascript Reference


Javascript Reference


Upon button click, loading a new page in the same window ( try below )





<script type="text/javascript">
    openWindow = function (url) {
        document.location.assign(url);
    }
</script>

<button class="blueX" onclick="javascript:openWindow('http://www.google.com')"><span class="button_text">Go To Google</span></button>

Function Expressions

var add = function add(a, b) {
         return a + b;
}

Function Declarations

function foo() {
        console.log("hello");
} 

Callback Functions (jsfiddle)
var addNumbers = function (callback) {
       var i = 5;
       var num = callback(5);
       alert("num = " + num);

}

var callback = function(num) {
       return num * num;
}

addNumbers(callback);
 

Anonymous Callback Function ( using prior example )

addNumbers( function (num) {
      return num * num;
});

test


Spring Project DD

Spring Project Design Document

  • Online Movie Database
person ( id, first_name, middle_name, last_name, birthdate, bio )
person_roles( id, person_id, role_id
role( id, type, description )
photos ( title, person(s), date, description, credit, id )
film ( id, film_genre_id, director_id, writer_id, 
film_genre ( id, type ) 
film_rating ( id, film_id, person_id )



Use Cases:

display a performer, their roles