Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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>

Code Block
<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.

...

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

Code Block
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". 

Code Block
<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.