[英]Values repeated in jsf <ui:repeat>
I have repeated values on my form. 我的表格上有重复的价值观。 I am using <ui:repeat>
tag. 我正在使用<ui:repeat>
标签。
My code: 我的代码:
<h:panelGroup id="alvs">
<ui:repeat value="#{encuestaController.newEncuesta.preguntas}" var="preg">
<h:outputLabel for="preg" value="add question:" style="font-weight:blue" />
<p:inputText id="preg" value="#{preg.pregunta}" />
<h:outputLabel for="value2" value="The question is option:" style="font-weight:bold" />
<p:selectBooleanButton id="value2" value="#{preg.opcional}" onLabel="Si" offLabel="No" onIcon="ui-icon-check" offIcon="ui-icon-close" style="width:60px">
<p:ajax update="f1:growl2"/>
</p:selectBooleanButton>
<h3 style="margin-top:2px">Question Type</h3>
<p:selectOneMenu value="#{preg.tipo}">
<f:selectItem itemValue="1" itemLabel="one option" />
<f:selectItem itemValue="2" itemLabel="many option" />
</p:selectOneMenu>
<h:panelGroup id="aux">
<ui:repeat value="#{preguntaController.newPregunta.opciones}" var="opc">
<h:panelGroup id="pn11" rendered="#{preg.tipo eq 1}">
uno<p:inputText value="#{opc.descripcion}"/>
</h:panelGroup>
<h:panelGroup id="pn12" rendered="#{preg.tipo eq 2}" >
dos<p:inputText value="#{opc.descripcion}"/>
</h:panelGroup>
</ui:repeat>
</h:panelGroup>
</ui:repeat>
</h:panelGroup>
<p:commandButton class="btn-floating btn-large waves-effect waves-light red" actionListener="#{preguntaController.addOcion}" update="f1:growl2" value="Add" >
<f:ajax execute="pn11 pn12" render="alvs" />
</p:commandButton>
The problem is when I want to add a new option(opciones) in the question(pregunta) with <p:commandButton/>
问题是我想在问题(pregunta)中使用<p:commandButton/>
添加新选项(opciones)
This adds the same options for the previous question as for the new one. 这为前一个问题添加了与新问题相同的选项。
Maybe, the error is ajax? 也许,错误是ajax? <f:ajax execute="pn11 pn12" render="alvs" />
Help me!!! 帮我!!!
As i see it, the problem is regarding the fact that you are producing multiple options using the ui:repeat, but you are declaring the same id for each of the panelGroups inside. 正如我所看到的,问题在于你使用ui:repeat生成多个选项,但是你为每个panelGroups声明了相同的id。 Add some custom prefix or sufix to each of the ids based on some unique value from the var="opt" (like an id): 根据var =“opt”中的一些唯一值(如id)为每个id添加一些自定义前缀或sufix:
<ui:repeat value="#{preguntaController.newPregunta.opciones}" var="opc">
<h:panelGroup id="pn11#{opc.id}" rendered="#{preg.tipo eq 1}">
uno<p:inputText value="#{opc.descripcion}"/>
</h:panelGroup>
<h:panelGroup id="pn12#{opc.id}" rendered="#{preg.tipo eq 2}" >
dos<p:inputText value="#{opc.descripcion}"/>
</h:panelGroup>
</ui:repeat>
Otherwise you will keep overriding the previous panelGroup's. 否则你将继续覆盖前面的panelGroup。
Also you would need to use a broader scope of execution for your ajax request. 此外,您还需要为ajax请求使用更广泛的执行范围。 I would use the first panelGroup outside of the ui:repeat: 我会使用ui之外的第一个panelGroup:repeat:
<f:ajax execute="aux" render="alvs" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.