Jsf 2 推杆<;span>;内部a<;p:panelGrid>;原因“;“奇怪”;显示
我想使用ajax事件更新创建动态表单。因此,动态id很重要。但是,将id属性绑定到bean值会导致空id异常。我看到一个建议使用html的stackoverflow问题。所以我用了span xhtml代码如下所示:Jsf 2 推杆<;span>;内部a<;p:panelGrid>;原因“;“奇怪”;显示,jsf-2,primefaces,panelgrid,Jsf 2,Primefaces,Panelgrid,我想使用ajax事件更新创建动态表单。因此,动态id很重要。但是,将id属性绑定到bean值会导致空id异常。我看到一个建议使用html的stackoverflow问题。所以我用了span xhtml代码如下所示: <?xml version="1.0" encoding="UTF-8"?> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun
<?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>
然而,这种显示很奇怪。它在每次迭代中都关闭了跨度。为什么在span close tag之前span不合理地关闭?
该
只将真正的JSF组件子级划分为列,而不是普通的HTML元素
将该
(或者更好的是,
)作为
的直接子级
...
我尝试用更新=“@(.#{question.dependentQuestionCode})”更新
,但它无法更新依赖div。但是,当我尝试其中一个更新=“:testform:#{question.dependentQuestionCode}”时,
或更新=“@(form)”
它可以更新。但是,用父窗体中的确切id来更新依赖div不是一个好方法,因为我无法知道它将使用的窗体id。更新整个表单也是一个非常糟糕的选择。有没有相对更新组件的方法?
不是JSF组件。请参考真正的JSF组件。例如,
。实际上,我来这里是因为需要动态id来更新特定组件。选择类(primefaces中的styleClass)也解决了我以前的动态id问题。另一方面,它让我想到了另一个问题。如果我静态输入update=“@(.q5)”
它会更新,但是如果我输入update=“@(.#{question.dependentQuestionCode})”
ajax会挂起几秒钟并抛出异常错误:语法错误,无法识别的表达式:。
对于许多问题,非常抱歉,但是我找不到在幕后调试ajax更新js代码的方法。顺便说一句,正如你建议的那样,我更改了
部分(实际上删除了并向panelGrid添加了一个styleClass):
<ui:repeat value="#{bean.questions}" var="question">
<div id="#{question.code}">
<p:panelGrid>
...
</p:panelGrid>
</div>
</ui:repeat>