- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
深入研究 RadioRenderer
源代码,我注意到以下内容:
方法
@Override
protected void renderOption(FacesContext context,
UIComponent component,
Converter converter,
SelectItem curItem,
Object currentSelections,
Object[] submittedValues,
boolean alignVertical,
int itemNumber,
OptionComponentInfo optionInfo) throws IOException
RadioRenderer
类中的覆盖是从标准 public void encodeEnd(FacesContext context, UIComponent component)
Renderer 方法调用的。但是有如下一段代码:
Iterator<SelectItem> items =
RenderKitUtils.getSelectItems(context, component);
//some code
while (items.hasNext()) {
SelectItem curItem = items.next();
idx++;
// If we come across a group of options, render them as a nested
// table.
if (curItem instanceof SelectItemGroup) {
// do some
else {
// do another
}
}
因此,我通过示例进行了尝试:
<h:selectOneRadio>
<f:selectItem />
<f:selectItems value="#{myBean.vals}" />
<f:selectItems value="#{myBean.valss}" />
</h:selectOneRadio>
并且 selectItem
和 selectItems
es 被视为不是 SelectItemGroup
的实例。对于 selectItem
这非常清楚,但我预计 selectItems
会映射到 SelectItemGroup
实例。
你不能澄清一下吗?
最佳答案
它不能以声明方式创建。它只能以编程方式创建。 <f:selectItems>
还支持 List<SelectItem>
与 javax.faces.model.SelectItem
SelectItemGroup
的实例是一个子类。以下是其 javadoc 的相关摘录:
SelectItemGroup is a subclass of
SelectItem
that identifies a set of options that will be made available as a subordinate "submenu" or "options list", depending upon the requirements of theUISelectMany
orUISelectOne
renderer that is actually used. In general, the value property of this instance will be ignored, and the label property of this instance will be used to label the submenu.
以下是如何创建它们的基本示例:
private List<SelectItem> availableItems; // +getter
@PostConstruct
public void init() {
availableItems = new ArrayList<>();
SelectItemGroup group1 = new SelectItemGroup("Group 1");
group1.setSelectItems(new SelectItem[] {
new SelectItem("Group 1 Value 1", "Group 1 Label 1"),
new SelectItem("Group 1 Value 2", "Group 1 Label 2"),
new SelectItem("Group 1 Value 3", "Group 1 Label 3")
});
availableItems.add(group1);
SelectItemGroup group2 = new SelectItemGroup("Group 2");
group2.setSelectItems(new SelectItem[] {
new SelectItem("Group 2 Value 1", "Group 2 Label 1"),
new SelectItem("Group 2 Value 2", "Group 2 Label 2"),
new SelectItem("Group 2 Value 3", "Group 2 Label 3")
});
availableItems.add(group2);
}
<f:selectItems value="#{bean.availableItems}" />
内部 <h:selectOneRadio>
它将呈现为嵌套表(恕我直言,这是一个糟糕的呈现,他们最好将组标签呈现为 <thead>
,但除此之外)。当你设置 layout
时它最明显至 pageDirection
, 否则所有内容都将显示在一行中 ( lineDirection
)。
<h:selectOneRadio layout="pageDirection">
<f:selectItems value="#{bean.availableItems}" />
</h:selectOneRadio>
在 <h:selectOneMenu>
里面它将呈现为一棵树,选项值嵌套在 <optgroup>
中(这实际上是 SelectItemGroup
的主要用例):
<h:selectOneMenu>
<f:selectItems value="#{bean.availableItems}" />
</h:selectOneMenu>
<h:selectManyListbox>
也支持它( <h:selectOneListbox>
具有完全相同的渲染,但仅支持单选):
<h:selectManyListbox>
<f:selectItems value="#{bean.availableItems}" />
</h:selectManyListbox>
<h:selectManyCheckbox>
具有与 <h:selectOneRadio>
相同的(语义上尴尬的)嵌套表格呈现:
<h:selectManyCheckbox layout="pageDirection">
<f:selectItems value="#{bean.availableItems}" />
</h:selectManyCheckbox>
<h:selectManyMenu>
根本没有用,所以我将跳过它。
关于jsf - 了解 SelectItemGroup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31905878/
深入研究 RadioRenderer 源代码,我注意到以下内容: 方法 @Override protected void renderOption(FacesContext context,
深入研究 RadioRenderer 源代码,我注意到以下内容: 方法 @Override protected void renderOption(FacesContext context,
我尝试过使用这样的分组选择: heroGroupList 是这样的: SelectItem[] heroArr = new SelectItem[] { new Sel
我是一名优秀的程序员,十分优秀!