efw Dialog Example

Overview

This example demonstrates the complete implementation of dialog functionality in the efw framework, including the usage of various dialog types (alert, confirm, wait, preview, and custom dialogs). The efw framework provides a concise API for creating and managing various user interaction dialogs.

Core Files

  1. Main Page: helloDialog.jsp
  2. Custom Dialog Component: helloDialog_myDialog.jsp
  3. Dialog Initialization Event Handler: helloDialog_init.js

Function Implementation

1. Dialog Types

Alert Dialog

efw.dialog.alert("I am here");

Confirm Dialog

efw.dialog.confirm(
    "Testing alert functionality.",
    {
        "Yes": function(){ alert("Clicked 'Yes'."); },
        "No": function(){ alert("Clicked 'No'."); }
    },
    "Alert Test",
    function(){ alert("Test completed"); }
);

Wait Dialog

efw.dialog.wait(
    "Please wait 5 seconds.",
    5,
    "Wait Test",
    function(){ alert("Test completed"); }
);

Preview Dialog

efw.dialog.preview("a.jpg", "a.jpg");

Custom Dialog

function testDialog(){
    myDialog.p1 = 'hello world! ' + new Date();
    myDialog.dialog('open');
}

2. Custom Dialog Workflow

  1. Dialog Initialization:
    • Define dialog structure and initialization logic in helloDialog_myDialog.jsp
    • Create dialogs using jQuery UI dialog component
  2. Opening Dialog:
    • Set parameters and open dialog in testDialog() function
    • Pass parameters through myDialog.p1
  3. Initialization Event:
    • Trigger open event when dialog opens
    • Call Efw("helloDialog_init", { msg: myDialog.p1 })
    • Pass parameters to initialization event handler
  4. Initialization Processing:
    • helloDialog_init.js receives parameters
    • Update dialog content using Result object
    • Display message in dialog’s .msg element

Technical Highlights

1. Modular Design

2. Parameter Passing Mechanism

3. Chain Operation API

return (new Result())
    .runat("#myDialog")
    .withdata({".msg": params["msg"]});

4. Event-Driven Architecture

5. Debug Support

params.debug(); // Output parameter information

6. Flexible Dialog Configuration

Usage Scenarios

This example applies to:

Through this example, developers can learn how to use various dialogs in the efw framework, as well as how to create and manage custom dialogs.