Wicket-Bootstrap

repository·wicket-10.x-bootstrap-5.x·Indexed 43 days ago

https://github.com/martin-g/wicket-bootstrap

Provides Bootstrap-styled components and themes for Apache Wicket applications. Includes a core library, extensions, themes, and a LESS compiler. Features include a Bootstrap Confirmation extension with customizable buttons and events, as well as support for singleton and popout modes.

Tokens
2.6K
Snippets
7
Records
8
Agent score
55%

What's inside Wicket-Bootstrap

  1. Install Wicket-Bootstrap

    wicket-10.x-bootstrap-5.x

    To use Wicket-Bootstrap components in your Apache Wicket application, you must install the Bootstrap settings class. The recommended location for this is within your Application#init() method.

    Standard Installation

    Use the default settings by calling Bootstrap.install(this).

    Custom Installation

    If you need to customize the Bootstrap configuration, create a BootstrapSettings object, configure it, and pass it to the install method.

    // best place to do this is in Application#init()
    Bootstrap.install(this);
    
    // if you want to customize bootstrap:
    BootstrapSettings settings = new BootstrapSettings();
    settings.setXXX(...);
    Bootstrap.install(this, settings);
  2. Add Wicket-Bootstrap dependencies via Maven

    wicket-10.x-bootstrap-5.x

    Wicket-Bootstrap is available in the Maven Central repository. Depending on your needs, you can include the core library, extensions, themes, or the LESS compiler.

    Note: Replace 6.y.z with the version compatible with your Wicket and Bootstrap setup (refer to the version compatibility table in the project documentation).

    <!-- Core library -->
    <dependency>
        <groupId>de.agilecoders.wicket</groupId>
        <artifactId>wicket-bootstrap-core</artifactId>
        <version>6.y.z</version>
    </dependency>
    
    <!-- All extensions -->
    <dependency>
        <groupId>de.agilecoders.wicket</groupId>
        <artifactId>wicket-bootstrap-extensions</artifactId>
        <version>6.y.z</version>
    </dependency>
    
    <!-- All themes -->
    <dependency>
        <groupId>de.agilecoders.wicket</groupId>
        <artifactId>wicket-bootstrap-themes</artifactId>
        <version>6.y.z</version>
    </dependency>
    
    <!-- Less compiler -->
    <dependency>
        <groupId>de.agilecoders.wicket</groupId>
        <artifactId>wicket-bootstrap-less</artifactId>
        <version>6.y.z</version>
    </dependency>
    
    <!-- Samples -->
    <dependency>
        <groupId>de.agilecoders.wicket</groupId>
        <artifactId>wicket-bootstrap-samples</artifactId>
        <version>6.y.z</version>
    </dependency>
  3. Upgrade from 0.9.4 to 0.9.5

    wicket-10.x-bootstrap-5.x

    When upgrading from version 0.9.4 to 0.9.5, you must update the namespace for the Bootswatch theme provider. Use the following search and replace mapping:

    • From: de.agilecoders.wicket.themes.settings.bootswatch.BootswatchThemeProvider
    • To: de.agilecoders.wicket.themes.markup.html.bootswatch.BootswatchThemeProvider
    de.agilecoders.wicket.themes.settings.bootswatch.BootswatchThemeProvider -> de.agilecoders.wicket.themes.markup.html.bootswatch.BootswatchThemeProvider
  4. Configure singleton and popout modes

    wicket-10.x-bootstrap-5.x

    The extension supports two advanced modes for managing multiple confirmation dialogs:

    1. singleton: true: Ensures that only one confirmation dialog is open at a time. When a new one is opened, all other existing confirmation popovers are automatically hidden. This requires a rootSelector to be defined.
    2. popout: true: Allows the confirmation dialog to behave like a popout. When clicking outside the dialog area, it will automatically close. This also requires a rootSelector.

    Requirement: When using singleton or popout, you must provide a rootSelector option to avoid errors in jQuery 3+ environments.

    // Example of singleton mode
    $('#my-element').confirmation({
      singleton: true,
      rootSelector: 'body'
    });
  5. Configure Bootstrap Confirmation options

    wicket-10.x-bootstrap-5.x

    The Bootstrap Confirmation extension (built on top of Bootstrap Popover) allows you to intercept click events to show a confirmation dialog. You can configure the dialog via a JavaScript configuration object or via data-bs- data attributes on the element.

    Note: Data attributes starting with data-btn (e.g., data-btn-ok-label) are prioritized during configuration.

    // Example configuration object
    const config = {
      title: 'Are you sure?',
      content: 'This action cannot be undone.',
      placement: 'top',
      btnOkLabel: 'Yes, delete it',
      btnOkClass: 'btn btn-danger',
      btnCancelLabel: 'No, keep it',
      onConfirm: function() {
        console.log('Confirmed!');
      },
      onCancel: function() {
        console.log('Canceled!');
      }
    };
    
    // Usage with jQuery
    $('#my-element').confirmation(config);
  6. Upgrade from 0.8.x to 0.9.x

    wicket-10.x-bootstrap-5.x

    When upgrading from version 0.8.x to 0.9.x, several component and utility namespaces have changed. You should perform a search and replace in your project using the following mappings:

    Old Namespace (0.8.x)New Namespace (0.9.x)
    de.agilecoders.wicket.markup.html.bootstrap.form.ControlGroupde.agilecoders.wicket.core.markup.html.bootstrap.form.FormGroup
    de.agilecoders.wicket.markup.html.bootstrap.components.TooltipBehaviorde.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipBehavior
    de.agilecoders.wicket.markup.html.bootstrap.components.TooltipConfigde.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipBehavior
    de.agilecoders.wicket.markup.html.bootstrap.dialog.Modalde.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal
    de.agilecoders.wicket.settingsde.agilecoders.wicket.core.settings
    de.agilecoders.wicket.markup.html.bootstrap.tabsde.agilecoders.wicket.core.markup.html.bootstrap.tabs
    de.agilecoders.wicket.markup.html.bootstrap.form.BootstrapFormde.agilecoders.wicket.core.markup.html.bootstrap.form.BootstrapForm
    de.agilecoders.wicket.util.JQueryde.agilecoders.wicket.jquery.JQuery
    de.agilecoders.wicket.markup.html.bootstrap.buttonde.agilecoders.wicket.core.markup.html.bootstrap.button
    de.agilecoders.wicket.markup.html.bootstrap.extensions.formde.agilecoders.wicket.extensions.markup.html.bootstrap.form
    de.agilecoders.wicket.markup.html.bootstrap.commonde.agilecoders.wicket.jquery
    de.agilecoders.wicket.util.Jsonde.agilecoders.wicket.jquery.util.Json
    de.agilecoders.wicket.core.Bootstrapde.agilecoders.wicket.Bootstrap
  7. Customize confirmation buttons

    wicket-10.x-bootstrap-5.x

    By default, the extension provides an 'OK' and a 'Cancel' button. You can customize their labels, classes, and icons, or provide a completely custom set of buttons using the buttons array.

    Standard Button Customization:

    • btnOkLabel / btnOkIconContent / btnOkClass / btnOkIconClass
    • btnCancelLabel / btnCancelIconContent / btnCancelClass / btnCancelIconClass

    Custom Buttons Array: If the buttons option is provided, the default buttons are replaced. Each button object can include:

    • label: The text content.
    • class: CSS classes.
    • iconClass: Class for an <i> element.
    • iconContent: Text content for the icon.
    • onClick: A callback function.
    • cancel: Boolean; if true, triggers the onCancel logic and canceled.bs.confirmation event.
    // Custom buttons example
    $('#my-element').confirmation({
      buttons: [
        {
          label: 'Option A',
          class: 'btn btn-success',
          onClick: function() { console.log('A clicked'); }
        },
        {
          label: 'Option B',
          class: 'btn btn-warning',
          onClick: function() { console.log('B clicked'); }
        },
        {
          label: 'Cancel',
          class: 'btn btn-light',
          cancel: true
        }
      ]
    });
  8. Use Bootstrap Confirmation events

    wicket-10.x-bootstrap-5.x

    The confirmation dialog emits several custom events that you can listen to using jQuery. These events are useful for triggering application logic after a user interacts with the dialog.

    Available Events:

    • shown.bs.confirmation: Fired when the confirmation popover is shown.
    • click.bs.confirmation: Fired when a button inside the popover is clicked.
    • confirmed.bs.confirmation: Fired when the 'OK' (or primary) button is clicked.
    • canceled.bs.confirmation: Fired when the 'Cancel' (or secondary) button is clicked.
    • keyup.bs.confirmation: Fired on keyup events (used for keyboard navigation).
    $('#my-element')
      .on('confirmed.bs.confirmation', function() {
        console.log('User confirmed the action');
      })
      .on('canceled.bs.confirmation', function() {
        console.log('User canceled the action');
      });