【问题标题】:alert box pops up with the error during the selection of a radio button选择单选按钮时弹出错误提示框
【发布时间】:2019-11-02 14:09:36
【问题描述】:

我们正在实现文本框禁用或启用 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


【解决方案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>

【讨论】:

  • 你好@Exorcismus 谢谢你的回答。一些它仍然无法正常工作。
  • @liliangarcia 值是否在 bean 中更新?
  • 可能是 div 标签导致了问题,我在没有 div 标签的情况下运行了代码。它运行良好。
猜你喜欢
  • 2012-10-01
  • 1970-01-01
  • 2014-08-19
  • 2013-12-14
  • 2015-09-15
  • 1970-01-01
  • 2016-05-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多