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

1 comment:

  1. Do not put the clothes on the folding table until you are sure. If the table is clean you can put clothes on it without worry or fear, and be careful to keep your laundry in bags until you get home.

    At Pest Control Company in Makkah, we have trained workers who are fully prepared to eliminate insects.افضل شركة مكافحة حشرات
    شركة مكافحة النمل الابيض براس تنوره
    شركة مكافحة حشرات براس تنوره

    ReplyDelete