Question

IzPack TargetPanel lets one select one target directory. However I need to allow users to choose two (one for apps, one for data). How to do that?

Was it helpful?

Solution

You can create a UserInputPanel and get the path as a variable from the user. Then you can use variable substitution anywhere you want. You'll have to add a userInputSpec.xml file and define your own panels (as many as you want). To get a directory, use <field type="dir" ... >

Example userInputSpec.xml from an application of mine. I include mongoDB with the installer and use this to get some settings.

<userInput>
    <panel order="0">      
        <createForPack name="MongoDB" />
        <!-- Other settings like port, ip, username, password-->
        <field type="staticText" align="left" txt="Select the catalogue where data will be stored." id="staticText.registry.db.data.text" />
        <field type="dir" align="left" variable="mongo.data.dir">
            <spec txt="Data directory" size="25" set="$INSTALL_PATH\data" mustExist="false" create="true" />
        </field>
    </panel>    
    <panel order="1">
        <!-- definition of a second panel -->
    </panel>
</userInput>

You also need to include the userInputSpec.xml as a resource in your main installation file and add a UserInputPanel element for each panel that you define in userInputSpec.xml

Like this (in the <installation> element:

<resources>
    <!-- other resources -->
    <res id="userInputSpec.xml"  src="userInputSpec.xml" />             
</resources>


 <panels>
    <panel classname="HelloPanel"/>             
    <panel classname="InfoPanel"/>
    <panel classname="LicencePanel"/>
    <panel classname="TargetPanel"/>
    <panel classname="TreePacksPanel"/>
    <panel classname="UserInputPanel"/>
    <panel classname="UserInputPanel"/>
    <panel classname="InstallPanel"/>
    <panel classname="ShortcutPanel"/>
    <panel classname="FinishPanel"/>
</panels>

notice the double occurence of I have two panels defined in my userInputSpec

Make sure that your UserInputPanels appear before InstallPanel because you have to get the variables from the user before copying your files.

This is just an example from my app. See the official documentation to get the idea of what the elements and attributes I used mean. There are many features connected with user input.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top