Wednesday, June 19, 2019

Servlet Implementation in Domino

In this article, I am going to show you how to implement the servlet in Domino. The implementation is using DesignerFacesServlet, not the tradition HttpServlet. The DesignerFacesServlet allows us to use the XPages scope variable.

1. Import servlet library into the database. The servlet library can find in <NOTES>\framework\shared\eclipse\plugins\com.ibm.domino.xsp.adapter_<VERSION>.

2. Create Servlet factory to map the URL “https://server/database/xsp/myservlet” to “test.servlet.HelloWorldServlet”.
package test.servlet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import com.ibm.designer.runtime.domino.adapter.ComponentModule;
import com.ibm.designer.runtime.domino.adapter.IServletFactory;
import com.ibm.designer.runtime.domino.adapter.ServletMatch;
public class ServletFactory implements IServletFactory {
      private static final Map<String, String> servletClasses = new HashMap<String, String>();
      private static final Map<String, String> servletNames = new HashMap<String, String>();
      private ComponentModule module;
    public void init(ComponentModule module) {
           System.out.println("TestFactory:init");
           servletClasses.put("myservlet""test.servlet.HelloWorldServlet");
           servletNames.put("myservlet""Hello World");
           this.module = module;
    }
    public ServletMatch getServletMatch(String contextPath, String paththrows ServletException {
        try {
                  String servletPath = "";
                  // iterate the servletNames map
                  Iterator<Map.Entry<String, String>> it = servletNames.entrySet().iterator();
                  while (it.hasNext()) {
                        Map.Entry<String, String> pairs = it.next();
                        if (path.contains("/" + pairs.getKey())) {
                              String pathInfo = path;
                              return new ServletMatch(getWidgetServlet(pairs.getKey()), servletPathpathInfo);
                        }
                  }
        } catch (Throwable t) {
            t.printStackTrace();
        }       
        return null;
    }
    public Servlet getWidgetServlet(String keythrows ServletException {
 return module.createServlet(servletClasses.get(key), servletNames.get(key), null);
    }
}
3. Enable servlet factory services.
3.1 Open the database in Package Explorer.
3.2 Go to folder “Code/Java/META-INF/services/ and create a text file name “com.ibm.xsp.adapter.servletFactory”.
3.3 In the text file, fill “test.servlet.ServletFactory” to enable the servlet factory.

4. Create the HelloWorld Servlet.
package test.servlet;
import com.ibm.xsp.webapp.DesignerFacesServlet;
import java.io.*;
import javax.faces.context.FacesContext;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorldServlet extends DesignerFacesServlet {
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponsethrows ServletException, IOException {
        // Set up handy environment variables
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        HttpServletResponse res = (HttpServletResponse) servletResponse;
        ServletOutputStream out = res.getOutputStream();
        FacesContext facesContext = this.getFacesContext(reqres);
        try {
            res.setContentType("text/plain");
            System.out.println("User hit the service.");
        } catch(Exception e) {
            e.printStackTrace(new PrintStream(out));
        } finally {
                  facesContext.responseComplete();
                  facesContext.release();
                  out.close();
        }
    }
}
5. Test the servlet by entering URL https://server/database/xsp/myservlet.




6. The implement is easy by creating three files.


Download Sample Database

References:
https://edm00se.io/xpages-servlets/servlet-implementation/
https://www.ibm.com/developerworks/cn/lotus/xpage-servlet/index.html

Thursday, March 7, 2019

AngularJS Review

1. AngularJS is a javascript framework. The latest upgrade version called Angular, which is a typescript framework.

2. AngularJS application consists of
- view, which is the HTML.
- model, which is the data available for the current view.
- controller, which is the javascript function or business logic.
- routes, which is the href mapping.

3. Javascript commonly place at the end of the body. However, it is recommended that the AngularJS library load at the <head>. The library has been loaded first then the angular.module can only be compiled.

4. Value attribute on an input text field is ignored when there is ng-model. Example: <input type="text" ng-model="name" value="Simon"> // value Simon is ignore!

5. I think if you wish to build a single page application, React, or Angular is better than AngularJS. AngularJS long term support will not have new functionality. It is just matters of time when this framework would obsolete.

References:
https://angularjs.org/
https://www.w3schools.com/angular/angular_intro.asp

Tuesday, June 12, 2018

Targeting the right audience in Facebook


  1. 3 types of Audience 
    • Core Audience – Target ads based on Facebook Data. 
    • Custom Audience – Using data from the website, email list, mobile apps, or other sources. 
    • Lookalike Audience – Surface new audience by combining custom Audience with Facebook targeting.
  2. To protect privacy, Facebook doesn’t show data of fewer than 1000 person on Audience Overlap page. 
  3. The marketer can use Audience Insight to analysis the target audience and create a different ad for a different audience. 
  4. 3 types of audiences can be analysis: 
    • Everyone on Facebook. 
    • People connected to your page. 
    • A custom Audience. 
  5. 4 characteristic you can see from Audience Insight: 
    • Demographic (age, gender, lifestyles, relationship, education level, job role) 
    • Pages likes (Pages that the audience like) 
    • Location (country, city, language) 
    • Activity (comments, post liked, post shares, promotion redeemed, ads clicked, a device used). 
  6. The marketer can use Audience Insight to save the Audience, then use the saved audience to create an Ad. The audience must contain minimum of 1000 people. 
  7. Pixer is a tool used to collect data from the website, mobile apps, or other sources. Pixel event is to track conversion. 
  8. Facebook creative hub format is a tool to learn types of Ad marketer can create in facebook. https://www.facebook.com/ads/creativehub/formats/ 
    • Single video 
    • Slideshow
    • 360 video 
    • Canvas 
    • Carousel 
    • Single image 
  9. Across Border is using an existing audience to find the same audience in another country.
  10. Tools to see sample facebook ads - https://adespresso.com/ads-examples/