イベント時に ajax update を使用して動的フォームを作成したいと考えています。したがって、動的 ID は重要です。ただし、id 属性を Bean 値にバインドすると、Empty Id 例外が発生します。html の使用を提案するスタックオーバーフローの質問の 1 つを見ました。だから私はスパンを使いました。
xhtml コードは次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<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" template="../../templates/ui.xhtml">
<ui:define name="content">
<h:form id="testform">
<ui:repeat value="#{repeat.questions}" var="question">
<p:panelGrid columns="2">
<p:outputLabel value="#{question.label}"/>
<span id="#{question.questionCode}">
<p:inputText value="#{repeat.values[question.questionCode]}"
rendered="#{question.type == 'TEXT'}">
<p:ajax event="blur" update="#{question.dependentQuestionCode}"
disabled="#{empty question.dependentQuestionCode}"/>
</p:inputText>
<p:password value="#{repeat.values[question.questionCode]}"
rendered="#{question.type == 'SECRET'}">
</p:password>
<p:inputTextarea value="#{repeat.values[question.questionCode]}"
rendered="#{question.type == 'TEXTAREA'}">
</p:inputTextarea>
<p:selectOneRadio value="#{repeat.values[question.questionCode]}"
rendered="#{question.type == 'RADIO'}" layout="grid" columns="1">
<f:selectItems value="#{question.options}"/>
</p:selectOneRadio>
<p:selectOneMenu value="#{repeat.values[question.questionCode]}"
rendered="#{question.type == 'SELECTONE'}">
<f:selectItems value="#{question.options}"/>
</p:selectOneMenu>
<p:selectManyMenu value="#{repeat.values[question.questionCode]}"
rendered="#{question.type == 'SELECTMANY'}">
<f:selectItems value="#{question.options}"/>
</p:selectManyMenu>
<p:selectBooleanCheckbox
value="#{repeat.values[question.questionCode]}"
rendered="#{question.type == 'CHECKONE'}"/>
<p:selectManyCheckbox value="#{repeat.values[question.questionCode]}"
rendered="#{question.type == 'CHECKMANY'}">
<f:selectItems value="#{question.options}"/>
</p:selectManyCheckbox>
</span>
</p:panelGrid>
</ui:repeat>
<p:commandButton value="Submit" actionListener="#{repeat.submit}"/>
</h:form>
</ui:define>
</ui:composition>
ただし、表示がおかしい。各反復でスパンを閉じました。スパン終了タグの前にスパンが不当に閉じられたのはなぜですか?