[英]How do i hide the f:selectItem tag under h:selectOneRadio
For <f:selectItem>
there is no rendered
attribute. 对于<f:selectItem>
,没有rendered
属性。 How can I hide a particular <f:selectItem>
under <h:selectOneRadio>
? 如何在<h:selectOneRadio>
下隐藏特定的<f:selectItem>
<h:selectOneRadio>
?
<h:selectOneRadio id="radio1" styleClass="selectOneRadio" value="#{}" rendered="#{}">
<f:selectItem itemValue="ALL" itemLabel="#{ONE}" />
<f:selectItem itemValue="PRIVATE" itemLabel="#{TWO}" />
<f:selectItem itemValue="GROUP" itemLabel="#{THREE}" />
</h:selectOneRadio>
In above code I want to hide the second item. 在上面的代码中我想隐藏第二个项目。
The <f:selectItem>
is a tag handler (which evaluated during view build time), not a JSF component (which is evaluated during view render time). <f:selectItem>
是一个标记处理程序(在视图构建时评估),而不是JSF组件(在视图渲染时评估)。 You can only show/hide it with another tag handler, such as JSTL <c:if>
. 您只能使用其他标记处理程序显示/隐藏它,例如JSTL <c:if>
。
<h:selectOneRadio value="#{bean.selectedItem}">
<f:selectItem itemValue="ALL" itemLabel="#{ONE}" />
<c:if test="#{!bean.showPrivate}">
<f:selectItem itemValue="PRIVATE" itemLabel="#{TWO}" />
</c:if>
<f:selectItem itemValue="GROUP" itemLabel="#{THREE}" />
</h:selectOneRadio>
Only when #{bean}
is been prepared during view render time by an iterating JSF component such as <h:dataTable>
or <ui:repeat>
then the above won't work and you really have to do it in the backing bean code instead. 只有当在视图渲染时间内通过迭代的JSF组件(例如<h:dataTable>
或<ui:repeat>
准备了#{bean}
时,上面的代码才会起作用,你真的必须在支持bean代码中执行它代替。
You can use f:selectItems
. 您可以使用f:selectItems
。 For example: 例如:
<h:selectOneRadio id="radio1" styleClass="selectOneRadio" rendered="true" value="controller.value">
<f:selectItems value="#{controller.items}" />
</h:selectOneRadio >
This is class controller: 这是类控制器:
public clss Controller(){
private List<SelectItem> items = new ArrayList<SelectItem>();
public Collection<SelectItem> getItems(){
if (items.isEmpty()){
createItems();
}
return this.items;
}
public private createItems(){
if (condition){ //Here you can hidden the selectItem
this.items.add(new SelectItem(value,label));
}
}
}
you can try to surround it in 你可以试着把它包围起来
<h:panelGrid rendered="">
h:selectOneRadio
</h:panelGrid >
EDITED: 编辑:
or use 或使用
<h:panelGroup>
Edit 编辑
its not good idea but i think you can do it by code redundancy as follow 这不是一个好主意,但我认为你可以通过代码冗余来实现,如下所示
<h:panelGroup rendered="#{}">
<h:selectOneRadio id="radio1" styleClass="selectOneRadio" rendered="true">
<f:selectItem itemValue="ALL" itemLabel="one" />
<f:selectItem itemValue="PRIVATE" itemLabel="two" />
<f:selectItem itemValue="GROUP" itemLabel="THREE" />
</h:selectOneRadio>
</h:panelGroup>
<h:panelGroup rendered="#{!}">
<h:selectOneRadio id="radio11" styleClass="selectOneRadio" rendered="true">
<f:selectItem itemValue="ALL" itemLabel="one" />
<f:selectItem itemValue="PRIVATE" itemLabel="two" />
</h:selectOneRadio>
</h:panelGroup>
I am not able to understand the markup/source, but guessing from the heading, I will suggest 我无法理解标记/来源,但我会建议从标题中猜测
$("a.selectOneRadio f.selectItem").hide()
should do the job assuming 应该做的工作假设
1) selectOneRadio is the class name of the a tag.
2) selectItem is the class name of the f tag.
3) f is not a tag in HTML. So if `f` is also a class name, you would have to use `.f .selectItem`
If you can please provide some details in the question. 如果可以,请在问题中提供一些细节。
There is also a disabled
property on f:selectItem
elements, if that fulfills your needs. 如果满足您的需求, f:selectItem
元素上还有一个disabled
属性。 Otherwise you will have to add them manually as Michel Foucault suggested. 否则你将不得不像Michel Foucault建议的那样手动添加它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.