Saturday, August 22, 2009

Why Use JSP for GWT RPC Server-side Service

Continued from GWT RPC - How Server-side JSP Service Works


Because, you can produce json response this way.

<%@ page
contentType="text/html; charset=utf-8"
language="java"
extends="com.blessedgeek.gwt.gdata.server.TableMgrJspBeanable"
....
%>
<%
MrBean mrBean = SessionSilo.initSessionBean(session.getId());
TableEntry entry = mrBean.getTableEntry();
Data data = entry.getData();
%>{
 "id":"<%=entry.getId()%>",
 "title":"<%=entry.getTitle().getPlainText()%>",
 "summary":"<%=entry.getSummary().getPlainText()%>",
 "worksheet":"<%=entry.getWorksheet().getName()%>",
 "header":"<%=entry.getHeader().getRow()%>",
 "insertionMode":"<%=data.getInsertionMode().name()%>",
 "startRow":"<%=data.getStartIndex()%>",
 "numRows":"<%=data.getNumberOfRows()%>",
 "columns":"<%
 int i=0;
 for (Column col : data.getColumns())
 {
  %><%=i>0?";":""%><%=col.getIndex()%>:<%=col.getName()%><%
  i++;
 }%>"
}

Because, that is why programmers prefer to use PHP, Perl or Scala to produce dynamic web pages rather than using a non-JSP servlet.

Because this is ugly and unfriendly, ugly to copy n'pasting (excerpted from http://code.google.com/p/javarunaround/source/browse/trunk/src/org/oosterveld/runaround/Display.java):
if (user != null){
  if (user.is_facebook_user()){
    html += "<div id=\"header-profilepic\">";
    html += user.getProfilePic(true);
    html += "</div>\n";
  }

  html += "<div id=\"header-account\">";
  html += "<b>Welcome, " + user.getName() + "</b>";
  html += "<div class=\"account_links\">";
  html += "<a href=\"account.jsp\">Account Settings</a> | ";
  
  if (user.is_facebook_user()){
    html += "<a href=\"#\" onclick=\"FB.Connect.logout(
    function()
    {
      refresh_page();
    }
    )\">" +
    "Logout of Facebook" +
    //.'<img src="images/fbconnect_logout.png">'
    "</a>";
  }
  else{
    html += "<a href=\"logout.jsp\">Logout</a>";
  }
  html += "<br /></div>";
  html += "</div>\n";
}
else{
  html += "<div class=\"account\">";
  html += "Hello Guest | ";
  html += "<a href=\"./register.jsp\">Register for an account</a>";
  html += "</div>\n";
}

html += "</div></div>\n"; // header & header_content
html += "<div class=\"body_content\">\n";


Because, you can use my text custom tag (http://h2g2java.blessedgeek.com/2009/07/jsp-text-custom-tag.html) to subject large blocks of unbroken text to conditional output.


Continue next Using memcache for Session Beans in GAE

No comments:

Post a Comment