Server side support for Java

Server side support for Java

channellisterchannellister Posts: 1Questions: 0Answers: 0
edited May 2018 in General

Since there is no server side support for Java, I have create a framework that allows me to define a CRUD_VIEW in my controller class. It is based on JOOQ and SparkJava. It lets me define my controller class like this.

class AdminPackages extends AppCntlrBase {

  static final String resource_name = "packages";
  static final String table_name = resource_name +"Table";
  static final String root_url_path = "/admin/"+resource_name;
  static final String ajax_url_path = root_url_path + "_ajax";


  static CrudViewAjax CRUD_VIEW = new CrudViewAjax( table_name, PACKAGE, ajax_url_path)
          .fields(
            new CvDbField(PACKAGE.NAME, "Name")
                .forRead().forIndex().forCreateAndEdit().forWrite()
                .srvValidators( isRequired() ),

            new CvDbField(PACKAGE.PRICE, "Price")
              .forRead().forIndex().forCreateAndEdit().forWrite()
              .srvValidators( isRequired() ),

            new CvDbField(PACKAGE.MAX_LISTS, "Maximum Lists")
              .forRead().forIndex().forCreateAndEdit().forWrite()
              .srvValidators( isRequired() ),

            new CvDbField(PACKAGE.MAX_PRODUCTS, "Maximum Products")
              .forRead().forIndex().forCreateAndEdit().forWrite()
              .srvValidators( isRequired() ),

            new CvDbField(PACKAGE.MAX_CHANNELS, "Maximum Channels")
              .forRead().forIndex().forCreateAndEdit().forWrite()
              .srvValidators( isRequired() ),

            new CvDbField(PACKAGE.DESCRIPTION, "Description")
              .forRead().forIndex().forCreateAndEdit().forWrite()
              .srvValidators( isRequired() ),

            new CvDbField(PACKAGE.CREATED_AT, "Created At")
                .withDisplayFormatter(displayTimestampFormatter("error"))
                .forRead().forIndex(),

            new CvDbField(PACKAGE.MODIFIED_AT, "Modified At")
                .withDisplayFormatter(displayTimestampFormatter("error"))
                .forRead().forIndex()
          );


  // *******************************************************************
  // *******************************************************************

  public static void registerPaths( Service http ) {
    http.get(root_url_path, AdminPackages::index );
    http.get(ajax_url_path, csrfProtectedRoute( dbContextRoute( AdminPackages::ajaxRead )));
    http.post(ajax_url_path, csrfProtectedRoute( dbContextRoute( AdminPackages::ajaxCreateUpdateDelete )));
  }


  public static Object index(Request request, Response response) {
    ViewModel model = new ViewModel(request, response);

    model.put("packages_table_tag", CRUD_VIEW.renderAjaxTableTag(model));
    model.put("packages_table_tag_data", CRUD_VIEW.renderAjaxTableDataTag(model));
    return model.viewHtml("admin/package/index");
  }


  public static Object ajaxRead(Request request, Response response, DSLContext db)  {
    return CRUD_VIEW.ajaxGetViewIndexData(request, response, db, null);
  }

  public static Object ajaxCreateUpdateDelete(Request request, Response response, DSLContext db) {
    return CRUD_VIEW.ajaxCUDHandler(request, response, db, null);
  }

}

It has saved me a tremendous amount tot time. I can quickly product CRUD support for any DB table.
I'm posting for feedback or suggestions of use.

Replies

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin

    This is fantastic - thanks very much for sharing this with us.

    ALlan

This discussion has been closed.