我想根据h:selectOneMenu所选值显示div图层。我 cr
eated this code:
<h:selectOneMenu id="zone" value="#{download.zone}" style="width: 212px;">
<f:selectItem id="select" itemLabel="Select download mirror" itemValue="Select download mirror" />
<f:selectItem id="USA" itemLabel="USA" itemValue="USA" />
<f:selectItem id="Canada" itemLabel="Canada" itemValue="Canada" />
</h:selectOneMenu>
...
private String zone;
public String getZone()
{
return zone;
}
public void setZone(String zone)
{
this.zone = zone;
}
这是我想要根据值显示的div 图层:
<div id="usa_release_server" style="padding-top: 20px;" class="text" rendered="#{download.zone == 'USA'}">
<h6>USA release server</h6>
</div>
但是当在h:selectOneMenu中选择值时,没有任何反应。你知道我错过了什么吗?
rendered
不是有效的HTML属性,它必须在JSF标记上使用。在这里,您可以使用带有layout="block"
的<h:panelGroup>
组件来渲染<div>
,并添加一个ajax组件以在更改<h:selectOneMenu>
对其进行更新:
<h:form>
<h:panelGroup layout="block" id="usa_release_server"
style="padding-top: 20px;" styleClass="text"
rendered="#{download.zone eq 'USA'}">
<h6>USA release server</h6>
</h:panelGroup>
<h:selectOneMenu id="zone" value="#{download.zone}"
style="width: 212px;">
<f:selectItem id="select" itemLabel="Select download mirror"
itemValue="Select download mirror" />
<f:selectItem id="USA" itemLabel="USA" itemValue="USA" />
<f:selectItem id="Canada" itemLabel="Canada" itemValue="Canada" />
<f:ajax event="change" render="@form" />
</h:selectOneMenu>
</h:form>