gpt4 book ai didi

java - ZK Radiogroup 返回错误的 getSelectedIndex()

转载 作者:行者123 更新时间:2023-12-02 10:22:43 27 4
gpt4 key购买 nike

我使用的是 ZK 8.5.2.1,并且有带有 Radiogroup 的弹出窗口。 zul:

<zk xmlns="http://www.zkoss.org/2005/zul" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">
<popup use="com.myproject.webapp.docbrowse.filter.FiltrationModePopup" width="330px">
<vlayout sclass="content">
<hlayout>
<label sclass="title" value="List form setup"/>
</hlayout>
<radiogroup id="rgScrollerMode" sclass="scrollermode-radio">
<grid>
<rows>
<row sclass="radio-border">
<radio label="Standart"/>
</row>
<row sclass="radio-border">
<radio label="Archive / Select year"/>
<hlayout id="archivePanel" use="com.myproject.webapp.docbrowse.ArchivePanel"/>
</row>
<row sclass="radio-border">
<radio label="Trash"/>
</row>
</rows>
</grid>
</radiogroup>
. . .
<div align="right">
<button id="okButton" label="Accept" sclass="acceptButton"/>
<button id="cancelButton" label="Cancel" sclass="cancelButton"/>
</div>
</vlayout>
</popup>
</zk>

FiltrationModePopup:

public class FiltrationModePopup extends Popup implements AfterCompose, IdSpace {
public static final String STANDARD_MODE = "/icons/toolbar/table_mode.png";
private static final String ARCHIVE_MODE = "/icons/toolbar/archive_mode.png";
private static final String RECYCLEBIN_MODE = "/icons/toolbar/recycle_mode.png";
private Radiogroup rgScrollerMode;
//. . . other properties

@Override
public void afterCompose() {
. . .
rgScrollerMode = (Radiogroup) getFellow("rgScrollerMode");
final Button okButton = (Button) getFellow("okButton");
okButton.addEventListener(Events.ON_CLICK, new SerializableEventListener<Event>() {
@Override
public void onEvent(Event event) {
filtrationModeSaver.save(FiltrationModePopup.this);
final FiltrationSettings filtrationSettings = createFiltrationSettingsFromPopup();
EventUtils.postEvent(new FiltersChangeEvent(FiltrationModePopup.this, filtrationSettings));
EventUtils.postEvent(new RefreshScrollerEvent(FiltrationModePopup.this));

close();
}
});
addForward(Events.ON_OK, okButton, Events.ON_CLICK);
EventUtils.registerHandler(this);
}

private FiltrationSettings createFiltrationSettingsFromPopup() {
return new FiltrationSettings(getScrollerMode(), getArchiveValue());
}

public ScrollerMode getScrollerMode() {
switch (rgScrollerMode.getSelectedIndex()) {
case 1:
return ScrollerMode.ARCHIVE;
case 2:
return ScrollerMode.RECYCLEBIN;
default:
return ScrollerMode.STANDARD;
}
}
// . . . Other code
}

因此,当屏幕上显示弹出窗口并且我选择某些单选项目并按“接受”按钮时 - selectedIndex 并不总是正确的。有时它是-1,有时它是旧选择的值,有时它是正确的。怎么了?

最佳答案

我简化了您的代码,它总是获得正确的选定索引。

    public class FiltrationModePopup extends Popup implements AfterCompose, IdSpace {
private Radiogroup rgScrollerMode;

@Override
public void afterCompose() {
rgScrollerMode = (Radiogroup) getFellow("rgScrollerMode");
final Button okButton = (Button) getFellow("okButton");
okButton.addEventListener(Events.ON_CLICK, new SerializableEventListener<Event>() {
@Override
public void onEvent(Event event) {
System.out.println(rgScrollerMode.getSelectedIndex());
close();
}
});
addForward(Events.ON_OK, okButton, Events.ON_CLICK);
}
}

您需要跟踪调用 getSelectedIndex() 之前发生的情况。您可以将onClick监听器中的代码注释掉,然后逐行添加代码,找出根本原因。

关于java - ZK Radiogroup 返回错误的 getSelectedIndex(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54213285/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com