Panel Actions

This feature provides a way to extend the functionality of IzPack with your own code that will be run as part of an IzPack panel.

The custom code must be included as a dependency in the pom that builds the installer.

<dependencies>
    <dependency>
        <groupId>com.example</groupId>
        <artifactId>custom-components</artifactId>
        <version>${custom.components.version}</version>
    </dependency>
</dependencies>


The custom code has access to variables defined at the point when the panel is executed.

Panel Definition
<panel classname="UserInputPanel" id="mySpecial.panel">
    <actions>
        <action stage="postvalidate" classname="com.example.action.mySpecialAction"/>
    </actions>
</panel>

Attribute

Usage

Required

stage

This controls the timing of the execution  of the custom code

required

classname

This is the name of the class to be executed.

required


The class must implement PanelAction and override the executeAction and initialize methods.


The InstallData object is passed in as an argument. Its methods can be used to access the values of the currently defined installation variables.

This sample code extracts the count of creatures that are defined and prints 2 variables from each creature.

Sample Action Code
package com.example.action;

import com.izforge.izpack.data.PanelAction;
import com.izforge.izpack.api.data.InstallData;
import com.izforge.izpack.api.handler.AbstractUIHandler;
import com.izforge.izpack.api.data.PanelActionConfiguration;

public class PrintCustomFields implements PanelAction
{
@Override
public void executeAction(InstallData installData, AbstractUIHandler handler)
{
    int count = Integer.parseInt(installData.getVariable("creature.count"));
    System.out.println("============= Data Gathers Through Custom Creatures ============");
    System.out.println(count+" number of creatures were selected. This information was stored in creature.count");

    for (int i=1; i<=count; i++) {
        System.out.println("creature.type."+i+": " + installData.getVariable("creature.type."+i));
        System.out.println("creature.colour."+i+": " + installData.getVariable("creature.colour."+i));
    }
    System.out.println("=================================================================");
}

@Override
public void initialize(PanelActionConfiguration configuration)
{

}


In this example the  executeAction method of the "PrintCustomFields class will be called after the postvalidate stage of the UserInputPanel called "creature.panel". 

Add PrintCustomFields Action to UserInputPanel
<panel classname="UserInputPanel" id="creature.panel">
<!--Print out the variables saved by the custom field -->
    <actions>
        <action stage="postvalidate" classname="com.example.action.PrintCustomFields"/>
    </actions>
</panel>



This article was inspired by the work done by Miles Tjandrawidjaja and the code example is entirely based on his code.