Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: More cleaning up

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 has access to variables defined at the point when the panel is executed.

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

...

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

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

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