WaveMaker Learn

WaveMaker Learn

  • Docs
  • Widgets
  • How-to
  • Releases
  • Login
  • Start free trial

›- Java services

How-to-documents

  • How-to Wiki

App Development

  • How-tos: App Development

- App solution

  • Creating a Registration Page
  • Support for Password Encryption
  • Error Handling in WaveMaker App
  • Leaving Page with Unsaved Changes

- UI design

  • Passing Parameters to Pages
  • Passing Parameters to Partial Page
  • Use Static Variable to pass data between pages
  • Incorporating Additional Icons
  • Change Icon Color on Condition
  • Changing Default Favicon
  • Changing App Logo
  • Changing Page Title
  • Customise App Style
  • Customize an Existing Theme
  • Customizing Theme

- Localization

  • Localization in WaveMaker Apps
  • Setting Language and Date Format
  • Localization Using Select Locale
  • Localization of Error Messages

- Security

  • SAML Integration - OneLogin
  • SAML Integration - ADFS
  • Custom Security using Google OAuth Prefab
  • Multiple Security Provider Implementation
  • Customizing Post Authentication Handlers

- Databases

  • Queries with Dynamic Where Clause
  • Connect To Azure SQL Server
  • Download JDBC Driver jar
  • How to fetch more than the default number(100) of records from database?

- Web services

  • Using App Environment Properties
  • Using POST method to send data to a REST API
  • How to Intercept Request and Response of all API Calls in One Place

- Java services

  • Sending eMail using Java Service
  • Implementing Forgot Password feature using Java Service
  • Accessing REST APIs from Java Service
  • Scheduling a Java Service
  • Pre-Post Processing for Database Service APIs

- Variables

  • Using Filter Conditions on Variable
  • Using Live Variable APIs
  • Using Notification Actions
  • Using Navigation Action
  • Using Variables for Queries and Procedure
  • Using Service Variable in a Form
  • Using Filter Criteria for a Data and Live Widgets
  • Using Filter Criteria for a Database CRUD Variable

- JavaScript

  • Using JavaScript in Binding
  • Using JavaScript from External URL
  • Using JavaScript to loop a command

- Developer-side

  • Synchronizing WaveMaker Apps with IDEs Beta
  • Integrating Amazon Cognito for User Authentication
  • Integrating Sample Jasper Report in WaveMaker Application
  • How to generate PDF File using Jasper Reports
  • Upgrading an App from WaveMaker 9.x to WaveMaker 10.0
  • App Migration from WaveMaker 9x to 10x

Mobile Development

  • How-tos: Mobile Development

- Mobile gesture

  • Setting Swipe Gestures on a List Widget
  • Working with Pull to Refresh

- Mobile widgets

  • Using Search Widget within the Navbar

- Mobile UI design

  • Setting Splashscreen Images and App Icons
  • Using Cordova Plugins

Widgets

  • How-tos: Widgets

- Cards

  • Capturing Card Items

- DataTable

  • Customising Data Table Row Action
  • Using Widgets to represent Data Table Columns
  • View Master-Detail Data Records using Data Table
  • Add Master-Detail records using Data Table
  • Export Data from Data Table
  • Dynamic Data Tables
  • Data Table Column bound to Query
  • Custom Styling Data Table Columns & Rows

- List

  • Creating an Employee List grouped by City
  • Creating an Employee List grouped by Birth Month and City
  • OnRender Event
  • Including a Data Table within a List
  • Building an Editable List
  • Building Cascading Lists
  • Accessing List Items
  • Localization of Data Table Column Headings

- Forms

  • Using Live Form
  • Using Wizard for Cumulative Data Entry in a Form
  • Building Tabbed Live Form
  • How Tos: Live Form
  • Linking Live Form with another Widget for Input
  • Handling Related Fields in a Live Form
  • Adding Master-Detail records in the same transaction
  • Using Cascading Select & Autocomplete for Live Form Fields
  • Using Cascading Select within Live Form
  • Using cascading Filter to populate Live Form
  • Using Wizard for Master-Detail Live Form
  • Using Wizard for Progressive Data Entry in a Live Form
  • Using Wizard for Cumulative Data Entry in a Live Form

- Calendar

  • Calendar Usage - Create an Event
  • Calender Usage - Google Calendar Integration

- CheckboxSet

  • CheckboxSet to Filter List data

- FileUpload

  • File Upload Widget Operations
  • Upload File & Save in Database
  • File Upload & Blob Data
  • File Upload - Custom Directory
  • Accessing File Upload from Java Code
  • Upload Files from Live Form & Form

- Radioset

  • Radioset to Filter a List

- Rating

  • Building Rating Widget using Static Data
  • Building Rating Widget using Static Variable
  • Build Rating Widget using Model Variable
  • Building an Interactive Rating Widget

- Select

  • Configuring Select Widget from a Static List of Values
  • Configuring Select Widget from a Variable
  • Configuring Select Widget using Display and Data Fields
  • Configuring Select Widget from Database Fields
  • Configuring Cascading Select

- Charts

  • Charts - Displaying User Selection in another Widget
  • Charts - Handling Dynamic Data
  • Charts - Custom Data

- Live filter

  • Applying Live Filter to a Data Table or a Chart
  • Building a Multiple Selection Live Filter
  • Building a Range Live Filter

- Container

  • Setting partial page content for Accordion within a List
  • Setting partial page content for Panel within a List using JavaScript

- Tree

  • Tree Use Case - from Static Variable
  • Tree Use Case - from Java Service
  • Tree Use Case - Dynamic Tree

- Nav

  • Nav - Basic Usage

- Dropdown

  • Restricting menu item display based on user role
  • Implementing Localization for Dropdown Menu

Prefabs

  • How-tos: Prefabs
  • Create Prefab using Third Party UI Widgets
  • Create Prefab Using D3 & NVD3 Charts
  • Create Prefab Using D3 Library (DataMaps)
  • Create Prefab using JQuery Plugin
Edit

Implementing Forgot Password feature using Java Service


Learn how to implement the forgot password feature using Java Service and send an email with default password.

Scenario

  1. On the Login screen, when a user chooses "Forgot Password", the user should be prompted to enter their email address.
  2. The default password should be sent to the user's email address.
  3. The password in the database should get updated with the default password which was sent to the user.

Files Imported to Java Service

The following files were imported into the Java Service:

import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.wavemaker.runtime.security.SecurityService;
import com.wavemaker.runtime.service.annotations.ExposeToClient;
import com.wavemaker.runtime.service.annotations.HideFromClient;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

Java Service Method

We will be using the following Java Service Method:

@ExposeToClient
public class Forgetpassword {
private static final Logger logger=LoggerFactory.getLogger(Forgetpassword.class);
public String sendEmail(String toEmailAddress) {
            String userName = "";
            String password = "";
            String emailSubject = "Default Password";
            String emailMessage = getPassword();
            try {
            // Use javamail api, set parameters from registration.properties file
            // set the session properties
            Properties props = System.getProperties();
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtp.host", "smtp.gmail.com");
            props.put("mail.smtp.port", "587");
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.starttls.required", "true");
            Session session = Session.getDefaultInstance(props, null);
            // Create email message
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(userName));
            String\[\] recipientList = toEmailAddress.split(",");
            InternetAddress\[\] recipientAddress = new InternetAddress\[recipientList.length\];
            int counter = 0;
            for (String recipient: recipientList) {
                recipientAddress\[counter\] = new InternetAddress(recipient.trim());
                counter++;
            }
            message.setRecipients(Message.RecipientType.TO, recipientAddress);
            message.setSubject(emailSubject);
            message.setContent(emailMessage, "text/html");
            // Send smtp message
            Transport tr = session.getTransport("smtp");
            tr.connect("smtp.gmail.com", 587, userName, password);
            message.saveChanges();
            tr.sendMessage(message, message.getAllRecipients());
            tr.close();
            return emailMessage;
            } catch (MessagingException e) {
                return "Error in method sendEmailNotification: " + e;
            }
        }

public String getPassword()
    {
        String temp = Long.toHexString(Double.doubleToLongBits(Math.random()));
        return temp;
    }

}

Update Query

update LOGIN set PASSWORD = :pwd where USER\_NAME = :name;

JavaScript Function


Page.ForgotPasswordonSuccess = function (variable, data) {
    Page.Variables.UpdatePWD.setInput("name", Page.Widgets.form1.formWidgets.text1.datavalue);
    Page.Variables.UpdatePWD.setInput("pwd", data);
    Page.Variables.UpdatePWD.update();
};

See Also

How to send emails using Java Service
How to access REST APIs from Java Service
How to schedule a Java Service
How to accomplish Pre-Post Processing for a DB Service APIs

Last updated on 11/20/2019 by Swetha Kundaram
← Sending eMail using Java ServiceAccessing REST APIs from Java Service →
  • Files Imported to Java Service
  • Java Service Method
  • Update Query
  • JavaScript Function
  • See Also
WaveMaker
  • PRICING
  • PARTNERS
  • CUSTOMERS
  • ABOUT US
  • CONTACT US
Terms of Use | Copyright © 2013-2019 WaveMaker, Inc. All rights reserved.