看着the source code of the MenuRenderer class,从com.sun.faces.renderkit.html_basic包后,目前还不清楚它是否是在说明书或者不是一个bug。
为了呈现h:selectOneMenu组件以及h:selectManyMenu组件,将调用renderSelect方法。关于尺寸属性:
- 如果未指定(selectOneMenu的情况),则设置默认值。
- 如果指定,
the "size" attribute will be rendered as one of the "pass thru" attributes
。
这里是源代码:
protected void [More ...] renderSelect(FacesContext context,
UIComponent component) throws IOException {
[...]
// Determine how many option(s) we need to render, and update
// the component's "size" attribute accordingly; The "size"
// attribute will be rendered as one of the "pass thru" attributes
[...]
// If "size" is *not* set explicitly, we have to default it correctly
Integer size = (Integer) component.getAttributes().get("size");
if (size == null || size == Integer.MIN_VALUE) {
size = count;
}
writeDefaultSize(writer, size);
RenderKitUtils.renderPassThruAttributes(context,
writer,
component,
ATTRIBUTES,
getNonOnChangeBehaviors(component));
[...]
}
混乱在于writeDefaultSize方法。它始终将默认大小为1,即使要呈现由ITEMCOUNT参数给出的选项数量:
protected void [More ...] writeDefaultSize(ResponseWriter writer, int itemCount)
throws IOException {
// if size is not specified default to 1.
writer.writeAttribute("size", "1", "size");
}
所以大小是在JSF规范描述的既不正常,请也不是在描述代码的评论。这可能不是一个错误,但它有点令人困惑。
我正面临这个问题。使用size属性时,Bootstrap没有应用正确的样式。 –