Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SmartGWT in portlet

    Hello,

    I succeed to use a SmartGWT application in a JSR-286 portlet deployed in a JBoss Portal 2.7 instance.

    This portlet simply displays a ListGrid with data fetched from a Grails backend application.
    I just saw two problems related to CSS:

    1. Using in others JQuery, JBoss Portal displays a login form that appeared under the grid; to resolve this I changed a JBoss JavaScript file that creates HTML elements with the z-index style property; now all works well.
    2. The second problem I saw is related to the CSS style for HTML HR element used in the ListGrid contectual menu; it seems that the CSS styles used by JBoss Portal hides the HR separator.

    I ask me if I can get other troubles with others UI controls; do other persons used Smarclient in a Portal environment? Or in situations where the GWT application is displayed in a part of an HTML page?

    Thank you!

    Bertrand.

    #2
    Hello,

    I've done a lot progress on having portlet JSR-286 with SmartGWT as view technology, and also found a solution to have multiple instances of the same portlet on one web page under JBoss Portal.

    But I ask me one thing about the loading of the GWT module; in case of multiple instances of the same portlet on the web page, I can have many "script" tag that load the same GWT module on the page.
    For example, I can have 2 or 3 times:

    <script language="javascript" src="portletCtx/com.lsy.clink.reports.Main/com.lsy.clink.reports.Main.nocache.js"></script>

    I tested this on several web browser, and I see that the GWT module in loaded just one time.
    So I search a confirmation to the fact there is some test on GWT module to authorize only one loading even there are multiple script tag for loading.

    Any thought about this?

    Cheers,

    Bertrand.

    Comment


      #3
      Not sure about an explicit check within GWT (that's more of a core GWT question than a SmartGWT question), but have you considered whther the browser is simplify caching the file and hence not downloading it again?

      If you could share some of the steps and ideally some sample code for your portlet approach, it would definitely benefit others who are working on SmartGWT-based portlets.

      Comment


        #4
        Hello,

        I am currently evaluation the portlet development for a liferay portal (Version 6.0.5) and I like the functionality of smartGWT (2.2 or 2.4) but unfortunately I cannot get my portlet up and running. Is there an example or tutorial out there
        (asking google without success) ? The portlet should be able to send a sql query to a database and display the result in a ListGrid.....

        Thanks
        Jörg

        Comment


          #5
          Hello,

          I've developed some portlet in liferay using SmartGWT, using a div-container as explained in

          http://www.liferay.com/web/guest/com...let+in+Liferay.

          To pass some information from the portlet to smartGWT (like actionURL, renderURL or resourceURL) I used a javascript Object in the portlet jsp:
          Code:
          <script type="text/javascript" language="javascript">
          function getParamsPortlet()
          {
                  
                  object=new Object();
                  
                  object.RUrl='<%=resUrl %>';
                  object.AUrl='<%=actUrl %>';
                  object.RendUrl='<%=rendUrl %>';
          };
          </script>
          and in smartGWT I get the object
          Code:
          public class Params extends JavaScriptObject {
                  protected Params() { }
                  public final native String getRUrl()  /*-{ return this.RUrl;  }-*/;
                  public final native String getRendUrl()  /*-{ return this.RendUrl;  }-*/;
                  public final native String getAUrl()  /*-{ return this.AUrl;  }-*/;
                  
          }
          Code:
          public class MySmartGWTModule implements EntryPoint {
                  
                  private native static Params getParams() /*-{
                          $wnd.getParams(); 
                          return $wnd.object;
                  }-*/;
          
                  /**
                   * This is the entry point method.
                   */
                  public void onModuleLoad() {
                          
                          final Params par=getParams();
          ...
                  }
          }
          Everything worked fine with liferay 6 and smartGWT 2.1 and I was able to use different smartGWT portlets in the same page, but when I upgrade the smartGWT library to the 2.4, my portlet works only if there is no other smartGWT portlet on the page.
          For example I put one smartGWT portlet in a page, the portlet loads and works fine; I put another smartGWT portlet in the same page and both are loaded and dispayed, but fetch operations don't work. I've got no errors in the developer console.
          Can anybody help me, please?

          Thanks

          Antonio

          Comment


            #6
            There's been no change that should have an effect like this.

            Double checking everything about your upgrade, including that all .js files being delivered to the browser are from the new version and not mixed.

            If that doesn't lead to a solution you will need to isolate it further (there's no a lot we can do with a report that fetch operations don't work).

            Comment


              #7
              Thank you for your anwer,

              I checked everything, I'm sure all files are from version 2.4.

              I'll try to explain better my problem:
              Every single portlet with a smartGWT module works well if it is alone in the page.

              Let's say I put two portlets in the page;
              Portlet n.1 has a textItem with a button and a listGrid. On button click, a request to a resourceURL is performed to fetch data for the listGrid;
              Portlet n.2 has just one button doing nothing.

              when I click on the button on portlet n.1 to fill the listGrid, I can see in firebug and in the developer console the request to my resourceURL and the response that I expect, but the listGrid continues to show "Loading data" and the page is blocked.

              With Chrome I have a js error: "Class.js:1335 Uncaught RangeError: Maximum call stack size exceeded",

              while in Opera I got

              "Uncaught exception: RangeError: Maximum recursion depth exceeded
              Error thrown at line 8, column 2956 in <anonymous function: $wnd.isc.RPCManager.fireReplyCallback>(b, c, d, e) in http://localhost:8080/Portlet/modulegwt/07A20FE63E416F169C25044AA5AF25A4.cache.html:
              (e!=null&&$wnd.isc.isA.Number(e)||$wnd.isc.isA.Boolean(e))&&(e=d.data=$wnd.SmartGWT.convertToJavaType(e));
              called from line 8, column 3062 in <anonymous function: $wnd.isc.RPCManager.fireReplyCallback>(b, c, d, e) in http://localhost:8080/Portlet/modulegwt/07A20FE63E416F169C25044AA5AF25A4.cache.html:
              return this.__fireReplyCallback(b,c,d,e)"

              Any idea?

              Antonio

              Comment


                #8
                You're still not putting us in a position to reproduce the error or really analyze it much - we don't know what DataSource type you're using or anything about the data being transferred.

                All we can say right now is that this looks like it could be due to badly formatted data, or, you may have custom code that is going into an infinite loop as it tries to process the response.

                Comment


                  #9
                  Ok, here is my code for both portlets and smartGWT modules:

                  portlet n.1
                  Code:
                  public class ZZZTest extends GenericPortlet {
                  
                          public void doView(RenderRequest request, RenderResponse response)
                                          throws PortletException, IOException {
                  
                                  String urlGWT=response.encodeURL(request.getContextPath()+"/zzzgwt/zzzgwt.nocache.js");
                                  request.setAttribute("urlGWT", urlGWT);
                                  String urlSmartGWT=response.encodeURL(request.getContextPath()+"/zzzgwt/sc/");
                                  request.setAttribute("urlSmartGWT", urlSmartGWT);
                                  
                                  PortletURL au=response.createActionURL();
                                  au.setParameter(ActionRequest.ACTION_NAME, "defName");
                                  String actUrl=au.toString();
                                  
                                  ResourceURL resUrl=response.createResourceURL();
                                  resUrl.setParameter("id", "defID");
                                  resUrl.setParameter("str", "defSTR");
                                  resUrl.setParameter("param1", "defParam1");
                                  String ru=resUrl.toString();
                          
                                  PortletURL reu=response.createRenderURL();
                                  String rendUrl=reu.toString();
                                  
                                  request.setAttribute("actUrl",actUrl);
                                  request.setAttribute("resUrl",ru);
                                  request.setAttribute("rendUrl",rendUrl);
                                  
                                  response.setContentType("text/html");
                                  
                              PortletRequestDispatcher dispatcher =getPortletContext().getRequestDispatcher("/WEB-INF/jsp/ZZZTest_view.jsp");
                              dispatcher.include(request, response);
                                  
                          }
                  
                          public void processAction(ActionRequest request, ActionResponse response)
                                          throws PortletException, IOException {
                  
                          }
                          public void serveResource(final ResourceRequest request, ResourceResponse response)
                          throws PortletException, IOException {
                                  System.out.println("SERVE RESOURCE");
                                  response.setContentType("text/html");
                                  PrintWriter writer = response.getWriter();
                                  String list = "<response>" + "<status>0</status>"
                                  + "<startRow>0</startRow>" 
                                  + "<endRow>2</endRow>" 
                                  + "<totalRows>2</totalRows>" 
                                  + "<data>";
                                  list = list + "<record>";
                                  list = list + "<name>name1</name>";
                                  list = list + "<description>description1</description>";
                                  list = list + "</record>";
                                  list = list + "<record>";
                                  list = list + "<name>name2</name>";
                                  list = list + "<description>description2</description>";
                                  list = list + "</record>";
                                  list = list + "</data>" + "</response>";
                                  writer.println(list);
                          }
                  
                  }
                  and the jsp
                  Code:
                  <%@page contentType="text/html"%>
                  <%@page pageEncoding="UTF-8"%>
                  
                  <%-- Uncomment below lines to add portlet taglibs to jsp--%>
                  <%@ page import="javax.portlet.*"%>
                  <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
                  
                  <portlet:defineObjects />
                  <%
                          String gwtSource=(String) request.getAttribute("urlGWT");
                          String urlSmartGWT=(String) request.getAttribute("urlSmartGWT");
                          
                          String resUrl=(String) request.getAttribute("resUrl");
                          String actUrl=(String) request.getAttribute("actUrl");
                          String rendUrl=(String) request.getAttribute("rendUrl");
                          %>
                  <script type="text/javascript" language="javascript">
                  function getParamsP()
                  {
                          
                          object=new Object();
                          
                          object.RUrl='<%=resUrl %>';
                          object.AUrl='<%=actUrl %>';
                          object.RendUrl='<%=rendUrl %>';
                          
                  };
                  </script>
                  
                  <script type="text/javascript" language="javascript">var
                  isomorphicDir='<%=urlSmartGWT %>'</script>
                  <div id='id-port'></div>
                  <script type="text/javascript" language="javascript" src='<%=gwtSource %
                  >'><![CDATA[<!-- -->]]></script>
                  in smartGWT

                  Code:
                  public class ParamsP extends JavaScriptObject {
                          protected ParamsP() { }
                          
                          public final native String getRUrl()  /*-{ return this.RUrl;  }-*/;
                          public final native String getRendUrl()  /*-{ return this.RendUrl;  }-*/;
                          public final native String getAUrl()  /*-{ return this.AUrl;  }-*/;
                  }
                  Code:
                  public class ZZZGWT implements EntryPoint {
                          
                          private native static ParamsP getParamsP() /*-{
                          $wnd.getParamsP(); 
                          return $wnd.object;
                          }-*/;
                          
                          /**
                           * This is the entry point method.
                           */
                          public void onModuleLoad() {
                                  final ParamsP par=getParamsP();
                                  VLayout layout=new VLayout();
                                  
                                  RestDataSource restDS=new RestDataSource();
                                  DataSourceTextField idField = new DataSourceTextField("id");  
                                  idField.setHidden(true);  
                                  idField.setPrimaryKey(true); 
                                  DataSourceTextField name=new DataSourceTextField("name", "name");
                                  DataSourceTextField description=new DataSourceTextField("description", "description");
                                  restDS.setFields(idField,name,description);
                                  
                                  final ListGrid lg=new ListGrid();
                                  ListGridField lgName=new ListGridField("name");
                                  ListGridField lgDescription=new ListGridField("description");
                                  lg.setFields(lgName,lgDescription);
                                  
                                  restDS.setDataURL(par.getRUrl());
                                  lg.setDataSource(restDS);
                                  
                                  IButton ok=new IButton("ok");
                                  ok.addClickHandler(new ClickHandler() {
                                          
                                          @Override
                                          public void onClick(ClickEvent event) {
                                                  lg.fetchData();
                                                  
                                          }
                                  });
                                  layout.addMember(lg);
                                  layout.addMember(ok);
                                  RootPanel.get("id-port").add(layout);
                                  
                          }
                  }
                  Portlet n.2

                  Code:
                  public class YYYTest extends GenericPortlet {
                  
                          public void doView(RenderRequest request, RenderResponse response)
                                          throws PortletException, IOException {
                  
                                  String urlGWT=response.encodeURL(request.getContextPath()+"/yyygwt/yyygwt.nocache.js");
                                  request.setAttribute("urlGWT", urlGWT);
                                  String urlSmartGWT=response.encodeURL(request.getContextPath()+"/yyygwt/sc/");
                                  request.setAttribute("urlSmartGWT", urlSmartGWT);
                                  
                                  response.setContentType("text/html");
                                  
                              PortletRequestDispatcher dispatcher =getPortletContext().getRequestDispatcher("/WEB-INF/jsp/YYYTest_view.jsp");
                              dispatcher.include(request, response);
                                  
                          }
                  
                  
                          public void processAction(ActionRequest request, ActionResponse response)
                                          throws PortletException, IOException {
                  
                          }
                  }
                  JSP:
                  Code:
                  <%@page contentType="text/html"%>
                  <%@page pageEncoding="UTF-8"%>
                  
                  <%-- Uncomment below lines to add portlet taglibs to jsp--%>
                  <%@ page import="javax.portlet.*"%>
                  <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
                  
                  <portlet:defineObjects />
                  <%
                          String gwtSource=(String) request.getAttribute("urlGWT");
                          String urlSmartGWT=(String) request.getAttribute("urlSmartGWT");
                  %>
                  
                  <script type="text/javascript" language="javascript">var
                  isomorphicDir='<%=urlSmartGWT %>'</script>
                  <div id='id-port2'></div>
                  <script type="text/javascript" language="javascript" src='<%=gwtSource %
                  >'><![CDATA[<!-- -->]]></script>
                  and the smartGWT module
                  Code:
                  /**
                   * Entry point classes define <code>onModuleLoad()</code>.
                   */
                  public class YYYGWT implements EntryPoint {
                          /**
                           * This is the entry point method.
                           */
                          public void onModuleLoad() {
                                  VLayout layout=new VLayout();
                                  IButton ok=new IButton("ok");
                                  ok.addClickHandler(new ClickHandler() {
                                          
                                          @Override
                                          public void onClick(ClickEvent event) {
                                                  SC.say("OK");
                                          }
                                  });
                                  layout.addMember(ok);
                                  RootPanel.get("id-port2").add(layout);
                          }
                  }
                  SmartGWT modules are created using the GWT plugin for eclipse, then I add the smartgwt.jar version 2.4 to the project and
                  <inherits name="com.smartgwt.SmartGwt" />
                  in the xml.

                  My platform : Liferay 6.0.4 Bundled with tomcat 6.0.26, Smartgwt 2.4, Google Web Toolkit SDK 2.1.1 and Gwt plugin for eclipse3.5 v1.4.2 , Eclipse 3.5.

                  I hope it's more accurate and that you can find some explanation to help me.

                  Thanks.

                  Antonio

                  Comment


                    #10
                    Hi,
                    did anybody sort out my problem? Is there some problem in my code?
                    Or maybe you need some more information?

                    Thank you.

                    Antonio

                    Comment


                      #11
                      Antonio,
                      We have tested with the approach (PortalDelegateServlet+iFrame Portlet) to integrate SmartGWT and LEP. I have not, however, tested with multiple instances on iFrame portlets pointing to different *.nocache.js.
                      For request handling we use GWT RPC, we do something like:

                      Code:
                      String compId = CookieKeys.getCookie(request, CookieKeys.COMPANY_ID);
                      Company lfeCo = CompanyServiceHttp.getCompanyById(lepUser,LPEPropsValues.COMPANY_ID);
                      String screenNameEncr = CookieKeys.getCookie(request,CookieKeys.SCREEN_NAME);
                      String passoword = CookieKeys.getCookie(request,CookieKeys.PASSWORD);
                      screenName = Encryptor.decrypt(lfeCo.getKeyObj(), screenNameEncr);
                      passoword = Encryptor.decrypt(lfeCo.getKeyObj(), passoword);
                      ...then we call:
                      Code:
                      *ServiceHttp.method()
                      business layer within SmartClient DMI objects.

                      In our platform we use GWT+GWTPlartform+SmartGWTPro.

                      I hope you get the gist of our approach.

                      Regards,
                      -Mdu

                      Comment


                        #12
                        Hello,
                        thank you for your answer,
                        I understand your code, it should work great, but my problem is that I've already developped many portlets and I can't change everything if I'm not sure that my code or my approach is wrong. I hope someone could explain to me why with smartGWT 2.1 everything was fine and with 2.4 it is not.

                        Antonio

                        Comment


                          #13
                          HI antoniodb,

                          First of all, your post has been very usefull to me.

                          Did you solve your problem?

                          Cheers.

                          Comment


                            #14
                            Did anyone find a solution for this problem? I'm having the same problem as described above and have now no idea, how to solve it.

                            Horst

                            Comment

                            Working...
                            X