阿贾克斯渲染不工作的SelectBooleanCheckbox [英] Ajax render not working on SelectBooleanCheckbox
问题描述
我有一个JSF表单,并在其上我有一个selectBooleanCheckbox。如果复选框的值是真实的我想要显示它旁边的组合框。但不知何故,这是行不通的。
下面是我的code:
< H:的outputText值=条件/>
&所述; H:selectBooleanCheckbox的id =provisioningTargetCollector
值=#{targetSource.provisioningTargetCollector}
禁用=#{SP:hasRight(FacesContext中,ManageApplication')}
只读=#{藻:hasRight(FacesContext中,'ManageApplication')}>
< F:AJAX渲染=targetCollectorsGroup/>
< / H:selectBooleanCheckbox>
< H:的outputText值=配置目标收藏家/>
&所述; H:panelGroup中的id =targetCollectorsGroup>
&所述; A4J:outputPanel的id =targetCollectors>
< H:selectOneMenu用于ID =收藏家
值=#{targetSource.selectedTargetCollector}
渲染=#{空targetSource.object.id}
禁用=#{SP:hasRight(FacesContext中,ManageApplication')}
只读=#{藻:hasRight(FacesContext中,'ManageApplication')}>
< F:选择信息itemValue =itemLabel =#{msgs.select_provisioning_target_collector}/>
< F:selectItems的值=#{targetSource.targetCollectors}/>
< / H:selectOneMenu用于>
< H:selectOneMenu用于ID =fixedTargetCollector值=#{空targetSource.selectedTargetCollector无:targetSource.selectedTargetCollector?}
渲染=#{非空targetSource.object.id}
禁用=真正的
只读=真正的>
< F:选择信息itemValue =#{空targetSource.selectedTargetCollector无:targetSource.selectedTargetCollector?}
itemLabel =:/>中#{空targetSource.selectedTargetCollector msgs.none targetSource.selectedTargetCollector}?
< / H:selectOneMenu用于>
< / A4J:outputPanel>
< /小时:panelGroup中>
Bean类方法:
私人布尔_provisioningTargetCollector;
公共布尔isProvisioningTargetCollector(){
返回_provisioningTargetCollector;
}
公共无效setProvisioningTargetCollector(布尔provisioningTargetCollector){
_provisioningTargetCollector = provisioningTargetCollector;
}
请注意:从萤火虫复制
这是POST请求:
AJAX:EVENTS_COUNT 1
editForm editForm
editForm:收集
editForm:collectorType
editForm:dsCorrelationRul ...
editForm:dsCreationRule
editForm:dsDescription
editForm:DSNAME
editForm:ID 2c90950048166abc0148177755040025
editForm:selectedTargetsF ...
editForm:类型的Active Directory - 直接
javax.faces.ViewState 1920301575480395177:8510885827764100150
javax.faces.behavior.even ...点击
javax.faces.partial.ajax真
javax.faces.partial.event点击
javax.faces.partial.execu ... editForm:provisioningTargetCollector editForm:provisioningTargetCollector
javax.faces.partial.rende ... editForm:targetCollectorsGroup
javax.faces.source editForm:provisioningTargetCollector
rfExt空
响应:
< XML版本=1.0编码=UTF-8&GT?;
&所述;部分响应>&其中;变更>&其中;更新的id =editForm:targetCollectorsGroup>&所述; [CDATA并[d跨度的id =!editForm:targetCollectorsGroup>&所述;跨度的id =editForm:targetCollectors ><选择一个id =editForm:收藏家NAME =editForm:收藏家大小=1> <期权价值=>选择供应目标收藏家...< /选项>
<期权价值=AD测试> AD测试< /选项>
<期权价值=ADWindow> ADWindow< /选项>
<期权价值=ADTestSth> ADTestSth< /选项>
&所述; /选择&GT;&所述; /跨度&GT;&所述; /跨度&GT;]]≥&所述; /更新&GT;&其中;更新id="javax.faces.ViewState"><![CDATA[1920301575480395177:8510885827764100150]]></update><extension id="org.richfaces.extension"><render>editForm:targetCollectorsGroup</render></extension></changes></partial-response>
直截了当的方式来实现你想要的功能,从字面上看,重新呈现的复选框的选择组合框筑底。为以下面的方式完成:
&LT; H:selectBooleanCheckbox绑定=#{}复选框&GT;
&LT; F:AJAX渲染=组/&GT;
&LT; / H:selectBooleanCheckbox&GT;
&LT; H:panelGroup中的id =组&GT;
&LT; H:selectOneMenu用于...渲染=#{checkbox.value}/&GT;
&LT; /小时:panelGroup中&GT;
请注意,code不需要在bean和 UIComponent
绑定到视图。
当然,你可以通过bean的属性做得一样好,如果你需要它在你的模型:
&LT; H:selectBooleanCheckbox值=#{bean.value}&GT;
&LT; F:AJAX渲染=组/&GT;
&LT; / H:selectBooleanCheckbox&GT;
&LT; H:panelGroup中的id =组&GT;
&LT; H:selectOneMenu用于...渲染=#{bean.value}/&GT;
&LT; /小时:panelGroup中&GT;
另外值得一提的是,此功能可以通过普通的JavaScript来实现,以及,通过切换显示
无之间的元素属性
和块
。但要注意,你必须保持JSF组件在回传,以确保对可能的恶意攻击的威胁相一致的状态。
I have a JSF form and on which I have a selectBooleanCheckbox. If the value of the checkbox is true I want to display the combo box next to it. But somehow it is not working.
Here is my code:
<h:outputText value="Condition"/>
<h:selectBooleanCheckbox id="provisioningTargetCollector"
value="#{targetSource.provisioningTargetCollector}"
disabled="#{!sp:hasRight(facesContext, 'ManageApplication')}"
readonly="#{!sp:hasRight(facesContext, 'ManageApplication')}">
<f:ajax render="targetCollectorsGroup" />
</h:selectBooleanCheckbox>
<h:outputText value="Provisioning Target Collector"/>
<h:panelGroup id="targetCollectorsGroup">
<a4j:outputPanel id="targetCollectors">
<h:selectOneMenu id="collector"
value="#{targetSource.selectedTargetCollector}"
rendered="#{empty targetSource.object.id}"
disabled="#{!sp:hasRight(facesContext, 'ManageApplication')}"
readonly="#{!sp:hasRight(facesContext, 'ManageApplication')}">
<f:selectItem itemValue="" itemLabel="#{msgs.select_provisioning_target_collector}"/>
<f:selectItems value="#{targetSource.targetCollectors}"/>
</h:selectOneMenu>
<h:selectOneMenu id="fixedTargetCollector" value="#{empty targetSource.selectedTargetCollector ? 'None' : targetSource.selectedTargetCollector}"
rendered="#{not empty targetSource.object.id}"
disabled="true"
readonly="true">
<f:selectItem itemValue="#{empty targetSource.selectedTargetCollector ? 'None' : targetSource.selectedTargetCollector}"
itemLabel="#{empty targetSource.selectedTargetCollector ? msgs.none : targetSource.selectedTargetCollector}"/>
</h:selectOneMenu>
</a4j:outputPanel>
</h:panelGroup>
Bean Class Methods:
private boolean _provisioningTargetCollector;
public boolean isProvisioningTargetCollector() {
return _provisioningTargetCollector;
}
public void setProvisioningTargetCollector(boolean provisioningTargetCollector) {
_provisioningTargetCollector = provisioningTargetCollector;
}
Note: Copied from FireBug
This is the POST Request:
AJAX:EVENTS_COUNT 1
editForm editForm
editForm:collector
editForm:collectorType
editForm:dsCorrelationRul...
editForm:dsCreationRule
editForm:dsDescription
editForm:dsName
editForm:id 2c90950048166abc0148177755040025
editForm:selectedTargetsF...
editForm:type Active Directory - Direct
javax.faces.ViewState 1920301575480395177:8510885827764100150
javax.faces.behavior.even... click
javax.faces.partial.ajax true
javax.faces.partial.event click
javax.faces.partial.execu... editForm:provisioningTargetCollector editForm:provisioningTargetCollector
javax.faces.partial.rende... editForm:targetCollectorsGroup
javax.faces.source editForm:provisioningTargetCollector
rfExt null
Response:
<?xml version='1.0' encoding='UTF-8'?>
<partial-response><changes><update id="editForm:targetCollectorsGroup"><![CDATA[<span id="editForm:targetCollectorsGroup"><span id="editForm:targetCollectors"><select id="editForm:collector" name="editForm:collector" size="1"> <option value="">Select a Provisioning Target Collector ...</option>
<option value="AD Test">AD Test</option>
<option value="ADWindow">ADWindow</option>
<option value="ADTestSth">ADTestSth</option>
</select></span></span>]]></update><update id="javax.faces.ViewState"><![CDATA[1920301575480395177:8510885827764100150]]></update><extension id="org.richfaces.extension"><render>editForm:targetCollectorsGroup</render></extension></changes></partial-response>
The straightforward way to achieve the functionality you desire is, literally, to rerender the combobox basing on the selection of the checkbox. That is done in a following way:
<h:selectBooleanCheckbox binding="#{checkbox}">
<f:ajax render="group" />
</h:selectBooleanCheckbox>
<h:panelGroup id="group">
<h:selectOneMenu ... rendered="#{checkbox.value}" />
</h:panelGroup>
Note that the code doesn't need any special fields in the bean and the UIComponent
is bound to the view.
Of course, you can do it via a bean property as well, if you need it in your model:
<h:selectBooleanCheckbox value="#{bean.value}">
<f:ajax render="group" />
</h:selectBooleanCheckbox>
<h:panelGroup id="group">
<h:selectOneMenu ... rendered="#{bean.value}" />
</h:panelGroup>
Also worth noting is that this functionality can be achieved by plain JavaScript as well, by toggling the display
attribute of an element between none
and block
. But be aware that you must keep the status of JSF components consistent across postbacks to secure against possible malicious attack threats.
这篇关于阿贾克斯渲染不工作的SelectBooleanCheckbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!