Izpack: Validator doesn't work?

血红的双手。 提交于 2019-12-13 16:07:15

问题


I have a field description in my "UserInputSpec.xml" file.

<field type="radio" variable="selected.source" >
        <description align="left" txt="Please select TBPAPIIntegrator data source:" id="combo.text" />
        <spec>
            <choice txt="IMKB Server"      id="combo.item.imkb"     value="imkb"/>
            <choice txt="Exernal Database" id="combo.item.database" value="db"/>
        </spec>
        <validator class="com.j32bit.installer.validator.SelectSourceValidator" txt="Please select one source!" >
            <param name="selected.source" value="${selected.source}"/>
        </validator>
    </field>

and this my Validator class:

package com.j32bit.installer.validator;

import java.util.Map;
import com.izforge.izpack.panels.ProcessingClient;
import com.izforge.izpack.panels.Validator;

public class SelectSourceValidator implements Validator{

    @Override
    public boolean validate(ProcessingClient client) {

        Map<String, String> params = client.getValidatorParams();

        if( params.get("selected.source").equals("imkb")
                ||  params.get("selected.source").equals("db"))
            return true;

        return false;
    }
}

Also variable deceleration as below in "Installer.xml":

<variables>
    <variable name="selected.source" value="" />
</variables>

Radio buttons comes unselected. While buttons still unselected if I click "next" button installer continuous the next page and validation does not work.

Please help! Thanks in advance.


回答1:


It seems like declaring a variable in <dynamicvariables></dynamicvariables> or in <variables></variables> does not work at all. Instead you can just write a variable name to a field and it can be used and referenced in anywhere in installer.

I also removed validator from field declaration in UserInputPanelSpec.xml and moved it to panel declaration in Installer.xml.

Installer.xml:

<panels>
    <panel classname="UserInputPanel" id="select.source" >
        <validator classname="com.j32bit.installer.validator.SourceValidator"/>
    </panel>
</panels>

UserInputPanelSpec.xml:

<!-- SELECT SOURCE PANEL  -->
<panel id="select.source">
    <field type="radio" variable="selected.source" >
        <description align="left" txt="Please select TBPAPIIntegrator data source:" id="radio.text" />
            <spec>
                <choice txt="IMKB" id="radio.item.imkb" value="imkb" />
                <choice txt="Exernal Database" id="radio.item.db" value="db" />
            </spec>
    </field>
</panel>

Now it is working with no problem.




回答2:


For field, it can help if you include validator element inside the spec one:

<field type="radio" variable="selected.source" >
    <description align="left" txt="Please select TBPAPIIntegrator data source:" id="combo.text" />
    <spec>
        <choice txt="IMKB Server"      id="combo.item.imkb"     value="imkb"/>
        <choice txt="Exernal Database" id="combo.item.database" value="db"/>

        <validator class="com.j32bit.installer.validator.SelectSourceValidator" txt="Please select one source!" >
            <param name="selected.source" value="${selected.source}"/>
        </validator>
    </spec>
</field>


来源:https://stackoverflow.com/questions/7598073/izpack-validator-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!