Joget DX 8 Stable Released
The stable release for Joget DX 8 is now available, with a focus on UX and Governance.
...
The query should also support a syntax to inject dependency values when using AJAX.
...
To make it work as a Form Options Binder, we will need to implement org.joget.apps.form.model.FormLoadOptionsBinder interface. We would like to support AJAX Cascading Drop-Down List as well, so we need to implement org.joget.apps.form.model.FormAjaxOptionsBinder interface also.
...
Code Block | ||
---|---|---|
| ||
/** * JSON API for test connection button * @param request * @param response * @throws ServletException * @throws IOException */ public void webService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //Limit the API for admin usage only boolean isAdmin = WorkflowUtil.isCurrentUserInRole(WorkflowUserManager.ROLE_ADMIN); if (!isAdmin) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } String action = request.getParameter("action"); if ("testConnection".equals(action)) { String message = ""; Connection conn = null; try { AppDefinition appDef = AppUtil.getCurrentAppDefinition(); String jdbcDriver = AppUtil.processHashVariable(request.getParameter("jdbcDriver"), null, null, null, appDef); String jdbcUrl = AppUtil.processHashVariable(request.getParameter("jdbcUrl"), null, null, null, appDef); String jdbcUser = AppUtil.processHashVariable(request.getParameter("jdbcUser"), null, null, null, appDef); String jdbcPassword = AppUtil.processHashVariable(SecurityUtil.decrypt(request.getParameter("jdbcPassword")), null, null, null, appDef); Class.forName(jdbcDriver);Properties dsProps = new Properties(); dsProps.put("driverClassName", jdbcDriver); dsProps.put("url", jdbcUrl); dsProps.put("username", jdbcUser); dsProps.put("password", jdbcPassword); DataSource ds = BasicDataSourceFactory.createDataSource(dsProps); conn = DriverManagerds.getConnection(jdbcUrl, jdbcUser, jdbcPassword); message = AppPluginUtil.getMessage("form.jdbcOptionsBinder.connectionOk", getClassName(), MESSAGE_PATH); } catch (Exception e) { LogUtil.error(getClassName(), e, "Test Connection error"); message = AppPluginUtil.getMessage("form.jdbcOptionsBinder.connectionFail", getClassName(), MESSAGE_PATH) + "\n" + e.getMessage(); } finally { try { if (conn != null && !conn.isClosed()) { conn.close(); } } catch (Exception e) { LogUtil.error(DynamicDataSourceManager.class.getName(), e, ""); } } try { JSONObject jsonObject = new JSONObject(); jsonObject.accumulate("message", message); jsonObject.write(response.getWriter()); } catch (Exception e) { //ignore } } else { response.setStatus(HttpServletResponse.SC_NO_CONTENT); } } |
...
Our plugin is using javaxusing dbcp, javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse class, so we will need to add jsp-api and commons-dbcp library to our POM file.
Code Block | ||
---|---|---|
| ||
<!-- Change plugin specific dependencies here --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.3</version> </dependency> <!-- End change plugin specific dependencies here --> |
...
Then, let us upload the plugin jar to Manage Plugins. After uploading the jar file, double check that the plugin is uploaded and activated correctly.
Then, let us create an AJAX Cascading Drop-Down List in a form to test it. Let's create our test form as follows.
...
You can download the source code from jdbc_options_binder_src.zip.
To download the ready-to-use plugin jar, please find it in http://marketplace.joget.org/.
...