Izpack:验证器不起作用?

发布于 2024-12-07 08:40:41 字数 1650 浏览 0 评论 0原文

我的“UserInputSpec.xml”文件中有一个字段描述。

<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>

这是我的 Validator 类:

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;
    }
}

“Installer.xml”中的变量减速度也如下:

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

单选按钮未选中。虽然按钮仍未选择,但如果我单击“下一步”按钮,安装程序会继续下一页,并且验证不起作用。

在此处输入图像描述

在此输入图像描述

请帮忙! 提前致谢。

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.

enter image description here

enter image description here

Please help!
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天赋异禀 2024-12-14 08:40:41

似乎在 中声明变量根本不起作用。相反,您只需将变量名称写入字段,就可以在安装程序的任何位置使用和引用它。

我还从 UserInputPanelSpec.xml 中的字段声明中删除了验证器,并将其移至 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>

现在可以正常工作了。

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.

眼泪都笑了 2024-12-14 08:40:41

对于字段,如果您在规范中包含验证器元素会有所帮助:

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文