在选择单选按钮时弹出警报框,并显示错误

alert box pops up with the error during the selection of a radio button

提问人:liliangarcia 提问时间:6/20/2019 最后编辑:liliangarcia 更新时间:6/21/2019 访问量:100

问:

我们正在实现禁用或启用文本框的功能,该 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.版本 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'}" />      
ajax jsf xhtml

评论

0赞 Kukeltje 6/20/2019
请将其设置为最小的可重现示例。另请参阅 stackoverflow.com/tags/jsf/info] 并提供版本信息
0赞 liliangarcia 6/20/2019
在这里,你有一个最小的可重复的例子。jsf.version 2.0 template.xhtml <h:form id=“new” enctype=“multipart/form-data”> <ui:include src=“/jsf/formgender.xhtml” /> </h:form>
0赞 liliangarcia 6/20/2019
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 '男'}“ />
0赞 Kukeltje 6/20/2019
请通过问题下方的编辑按钮编辑问题:stackoverflow.com/posts/56674386/edit
0赞 Kukeltje 6/21/2019
拜托,这不是一个最小的可重现示例。请参阅我在第一条评论中发布的第二个链接。关于模板的一些事情。而且在更多方面,它不是一个最小的可重复的例子

答:

0赞 Exorcismus 6/21/2019 #1

尝试将两个输入添加到 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>

评论

0赞 liliangarcia 6/24/2019
您好@Exorcismus感谢您的回答。有些它仍然不起作用。
0赞 Exorcismus 6/24/2019
@liliangarcia bean 中的值会更新?
0赞 liliangarcia 6/25/2019
可能是 div 标签导致了这个问题,我运行了没有 div 标签的代码。它运行良好。