CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-jboss-errai--errai-common

Common utilities and foundational infrastructure for the Errai GWT-based framework

Pending
Overview
Eval results
Files

framework-integration.mddocs/

Framework Integration

GWT integration utilities and callback framework for building interactive Errai applications with text selection controls and standardized callback interfaces.

Capabilities

Errai Common Entry Point

Main GWT entry point providing DOM utilities and framework initialization.

/**
 * Main GWT entry point and utility class for text selection handling
 */
public class ErraiCommon implements EntryPoint {
    /**
     * GWT entry point method called when module loads
     */
    public void onModuleLoad();
    
    /**
     * Enable or disable text selection on DOM elements
     * @param e - DOM element to modify
     * @param disable - true to disable text selection, false to enable
     */
    public static void disableTextSelection(Element e, boolean disable);
}

GWT Module Configuration:

<!-- In your .gwt.xml file -->
<module>
    <inherits name='com.google.gwt.user.User'/>
    <inherits name="com.google.gwt.json.JSON"/>
    <entry-point class='org.jboss.errai.common.client.ErraiCommon'/>
</module>

Usage Examples:

import org.jboss.errai.common.client.ErraiCommon;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.DOM;

// Disable text selection on a specific element
Element element = DOM.getElementById("myElement");
ErraiCommon.disableTextSelection(element, true);

// Re-enable text selection
ErraiCommon.disableTextSelection(element, false);

JavaScript Implementation Details:

The disableTextSelection method uses native JavaScript to control text selection:

  • When disable = true: Sets ondrag = function() { return false; } and onselectstart = function() { return false; }
  • When disable = false: Sets ondrag = null and onselectstart = null

Callback Framework

Standardized callback interface for asynchronous operations and user interactions.

/**
 * Interface for classes that can accept callback methods
 */
public interface AcceptsCallback {
    /** Standard OK message constant */
    public static final String MESSAGE_OK = "OK";
    
    /** Standard CANCEL message constant */  
    public static final String MESSAGE_CANCEL = "CANCEL";
    
    /**
     * Callback method invoked by callers
     * @param message - Message being returned (often MESSAGE_OK or MESSAGE_CANCEL)
     * @param data - Additional data (optional, can be null)
     */
    public void callback(Object message, Object data);
}

Usage Examples:

import org.jboss.errai.common.client.framework.AcceptsCallback;

// Implement callback interface
public class MyDialogHandler implements AcceptsCallback {
    public void callback(Object message, Object data) {
        if (AcceptsCallback.MESSAGE_OK.equals(message)) {
            // Handle OK action
            System.out.println("User clicked OK");
            if (data != null) {
                processData(data);
            }
        } else if (AcceptsCallback.MESSAGE_CANCEL.equals(message)) {
            // Handle cancel action
            System.out.println("User cancelled");
        } else {
            // Handle custom message
            System.out.println("Received message: " + message);
        }
    }
    
    private void processData(Object data) {
        // Process callback data
    }
}

// Use callback with async operation
public class AsyncService {
    public void performOperation(String input, AcceptsCallback callback) {
        // Simulate async operation
        Timer timer = new Timer() {
            @Override
            public void run() {
                try {
                    // Perform operation
                    String result = processInput(input);
                    callback.callback(AcceptsCallback.MESSAGE_OK, result);
                } catch (Exception e) {
                    callback.callback("ERROR", e.getMessage());
                }
            }
        };
        timer.schedule(1000); // Execute after 1 second
    }
    
    private String processInput(String input) {
        return "Processed: " + input;
    }
}

// Usage
AsyncService service = new AsyncService();
MyDialogHandler handler = new MyDialogHandler();
service.performOperation("test data", handler);

Dialog and UI Patterns

The callback framework is commonly used for dialog boxes and user confirmations:

import org.jboss.errai.common.client.framework.AcceptsCallback;

public class ConfirmDialog {
    public static void show(String message, AcceptsCallback callback) {
        // Create dialog UI
        DialogBox dialog = new DialogBox();
        dialog.setText("Confirm");
        
        VerticalPanel panel = new VerticalPanel();
        panel.add(new Label(message));
        
        HorizontalPanel buttonPanel = new HorizontalPanel();
        
        Button okButton = new Button("OK", new ClickHandler() {
            public void onClick(ClickEvent event) {
                dialog.hide();
                callback.callback(AcceptsCallback.MESSAGE_OK, null);
            }
        });
        
        Button cancelButton = new Button("Cancel", new ClickHandler() {
            public void onClick(ClickEvent event) {
                dialog.hide();
                callback.callback(AcceptsCallback.MESSAGE_CANCEL, null);
            }
        });
        
        buttonPanel.add(okButton);
        buttonPanel.add(cancelButton);
        panel.add(buttonPanel);
        
        dialog.setWidget(panel);
        dialog.center();
        dialog.show();
    }
}

// Usage
ConfirmDialog.show("Are you sure you want to delete this item?", new AcceptsCallback() {
    public void callback(Object message, Object data) {
        if (AcceptsCallback.MESSAGE_OK.equals(message)) {
            deleteItem();
        }
        // Cancel requires no action
    }
});

Form Validation Patterns

Callback interface can be used for form validation workflows:

import org.jboss.errai.common.client.framework.AcceptsCallback;

public class FormValidator {
    public void validateForm(Map<String, String> formData, AcceptsCallback callback) {
        List<String> errors = new ArrayList<>();
        
        // Validate required fields
        if (formData.get("name") == null || formData.get("name").trim().isEmpty()) {
            errors.add("Name is required");
        }
        
        if (formData.get("email") == null || !isValidEmail(formData.get("email"))) {
            errors.add("Valid email is required");
        }
        
        // Return results via callback
        if (errors.isEmpty()) {
            callback.callback(AcceptsCallback.MESSAGE_OK, formData);
        } else {
            callback.callback("VALIDATION_ERROR", errors);
        }
    }
    
    private boolean isValidEmail(String email) {
        return email != null && email.contains("@");
    }
}

// Usage
FormValidator validator = new FormValidator();
Map<String, String> formData = new HashMap<>();
formData.put("name", "John Doe");
formData.put("email", "john@example.com");

validator.validateForm(formData, new AcceptsCallback() {
    public void callback(Object message, Object data) {
        if (AcceptsCallback.MESSAGE_OK.equals(message)) {
            // Form is valid, submit data
            submitForm((Map<String, String>) data);
        } else if ("VALIDATION_ERROR".equals(message)) {
            // Show validation errors
            List<String> errors = (List<String>) data;
            showErrors(errors);
        }
    }
});

GWT Integration Requirements

Dependencies

<dependencies>
    <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt-user</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

Module Inheritance

<!-- In your .gwt.xml file -->
<module>
    <inherits name='com.google.gwt.user.User'/>
    <inherits name="com.google.gwt.json.JSON"/>
    <inherits name="org.jboss.errai.common.ErraiCommon"/>
</module>

Required Imports

// GWT core imports
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Element;
import com.google.gwt.json.client.JSONObject;

// Errai Common imports
import org.jboss.errai.common.client.ErraiCommon;
import org.jboss.errai.common.client.framework.AcceptsCallback;

Best Practices

Callback Error Handling

public class RobustCallbackHandler implements AcceptsCallback {
    public void callback(Object message, Object data) {
        try {
            if (AcceptsCallback.MESSAGE_OK.equals(message)) {
                handleSuccess(data);
            } else if (AcceptsCallback.MESSAGE_CANCEL.equals(message)) {
                handleCancel();
            } else if (message instanceof String) {
                handleError((String) message, data);
            } else {
                handleUnknownMessage(message, data);
            }
        } catch (Exception e) {
            // Log error and provide fallback
            GWT.log("Callback error: " + e.getMessage(), e);
            handleError("CALLBACK_ERROR", e);
        }
    }
    
    private void handleSuccess(Object data) { /* ... */ }
    private void handleCancel() { /* ... */ }
    private void handleError(String error, Object data) { /* ... */ }
    private void handleUnknownMessage(Object message, Object data) { /* ... */ }
}

Text Selection Management

public class TextSelectionManager {
    private Set<Element> disabledElements = new HashSet<>();
    
    public void disableTextSelection(Element element) {
        if (!disabledElements.contains(element)) {
            ErraiCommon.disableTextSelection(element, true);
            disabledElements.add(element);
        }
    }
    
    public void enableTextSelection(Element element) {
        if (disabledElements.contains(element)) {
            ErraiCommon.disableTextSelection(element, false);
            disabledElements.remove(element);
        }
    }
    
    public void enableAllTextSelection() {
        for (Element element : new HashSet<>(disabledElements)) {
            enableTextSelection(element);
        }
    }
}

Install with Tessl CLI

npx tessl i tessl/maven-org-jboss-errai--errai-common

docs

framework-integration.md

index.md

json-processing.md

marshalling.md

type-conversion.md

tile.json