我们正在实现根据另一个输入组件(即单选按钮)的值禁用或启用jsf输入组件的功能。该功能有效,但弹出警告框并显示错误
malformedXML: During update: new:j_idt335 not found
当我单击收音机时,选择选项
单选按钮公头O单选按钮公头O
输入框文本字段男[_____]女[_____]
选择“男性”单选按钮后,“女性”输入框被禁用
选择“女性”单选按钮后,“男性”输入框被禁用
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
template="/src/template.xhtml">
<ui:define name="content">
<h:form id="new" enctype="multipart/form-data">
<h:panelGroup id="id2">
<p:growl id="growl" sticky="true" showDetail="true" />
<p:wizard id="newWizard" showNavBar="true" widgetVar="wiz" flowListener="#{SelectMB.handleFlow}">
<p:tab id="tab"
title="Form">
<ui:include src="/jsf/formgender.xhtml" />
</p:tab>
</p:wizard>
</h:panelGroup>
</h:form>
</ui:define>
formgender.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:pe="http://primefaces.org/ui/extensions"
>
<p:panel id="type" styleClass="panelNoBorder">
<p:fieldset toggleable="true" toggleSpeed="500"
legend="Info">
<div class="ui-g">
<div class="ui-g-1"><p:outputLabel value="genderType" /></div>
<div class="ui-g-3">
<p:row>
<h:selectOneRadio value="#{SelectMB.genderType}">
<f:selectItem itemValue="male"
itemLabel="male" />
<f:selectItem itemValue="female"
itemLabel="female" />
<f:ajax render="male" />
<f:ajax render="female" />
</h:selectOneRadio>
</p:row>
</div>
<div class="ui-g-1"><p:outputLabel value="male" /></div>
<div class="ui-g-3">
<p:row>
<p:inputText id="male" value="#{SelectMB.male}"
disabled="#{SelectMB.genderType eq 'female'}" />
</p:row>
</div>
</div>
<div class="ui-g">
<div class="ui-g-1"><p:outputLabel value="female" /></div>
<div class="ui-g-3">
<p:row>
<p:inputText id="female" value="#
{SelectMB.femaleList}" disabled="#{SelectMB.genderType eq 'male'}"
/>
</p:row>
</div>
</div>
</p:fieldset>
</p:panel>
SelectMB.java
private String genderType;
public String getgenderType() {
return genderType;
}
public void setgenderType(String genderType) {
this.genderType = genderType;
}
private String male;
private String femaleList;
public String getMale() {
return male;
}
public void setMale(String male) {
this.male = male;
}
public String getFemaleList() {
return femaleList;
}
public void setFemaleList(String femaleList) {
this.femaleList = femaleList;
}
该功能按预期工作。
错误消息:-
当我单击单选按钮时,功能会按预期运行,但警告框中会显示错误消息。
malformedXML: During update: new:j_idt335 not found
预期结果:-
如果选择了“一个”单选按钮,则应禁用另一个选项的文本输入字段。
最小的可复制示例。 jsf.version 2.0
template.xhtml
<h:form id="new" enctype="multipart/form-data">
<ui:include src="/jsf/formgender.xhtml" /> </h:form>
formgender.xhtml
<h:selectOneRadio value="#{SelectMB.genderType}">
<f:selectItem itemValue="male" itemLabel="male" />
<f:selectItem itemValue="female" itemLabel="female" />
<f:ajax render="male" /> <f:ajax render="female" />
</h:selectOneRadio>
<p:inputText id="male" value="#{SelectMB.male}" disabled="#{SelectMB.genderType eq 'female'}" />
<p:inputText id="female" value="#{SelectMB.femaleList}" disabled="#{SelectMB.genderType eq 'male'}" />
答案 0 :(得分:0)
尝试将两个输入都添加到div并按如下所示渲染该div
<h:selectOneRadio value="#{SelectMB.genderType}">
<f:selectItem itemValue="male" itemLabel="male" />
<f:selectItem itemValue="female" itemLabel="female" />
<f:ajax render="input_" />
</h:selectOneRadio>
<h:panelGrid layout="block" id="input_">
<p:inputText id="male" value="#{SelectMB.male}" disabled="#{SelectMB.genderType eq 'female'}" />
<p:inputText id="female" value="#{SelectMB.femaleList}" disabled="#{SelectMB.genderType eq 'male'}" />
</h:panelGrid>