gpt4 book ai didi

javascript - 如何将 javascript 验证应用于 jsf primefaces 中所有动态生成的输入文本区域

转载 作者:行者123 更新时间:2023-11-28 04:45:39 24 4
gpt4 key购买 nike

我想将 javascript 验证应用于 jsf prime faces 中动态生成的输入文本区域,但我遇到的问题是,当生成许多动态字段时,验证仅应用于最后一个字段,但我想要它对于所有领域。我该如何解决这个问题?

该数据表位于表单内

<tr>
<td colspan="2">
<p:dataTable
value="#{reconTemplate.stepsList}" var="sItem"
rowIndexVar="rowIndex" id="multipleTable"
emptyMessage="#{msg['label.req.add.step']}"
styleClass="message_text_alert"
style="padding-top:20px; width:100% !important;"
scrollable="true" scrollHeight="400">
<f:facet name="header">#{msg['label.modify.step.des']}</f:facet>

<p:column
style="width:100% !important; border-bottom:1px solid #ccc !important;padding-left: 10px !important">
<p:outputLabel value="#{rowIndex+1} #{msg['label.step']}">
</p:outputLabel>

<p:inputText id="statusAll" type="text" styleClass="inputAttr"
widgetVar="stepTemplateWidget" immediate="true"
autocomplete="on" onkeyup="stepValidation()"
value="#{sItem.stepName}"
placeholder="#{msg['recon.templateStepPlaceholder']}"
style="width:460px; margin-left:5px !important;">
</p:inputText>

<p:commandLink value="#{msg['label.remove.step']}"
action="#{reconTemplate.removeSteps(sItem)}"
update=":formAll:multipleTable,:formAll:deleteButton"
ajax="true" styleClass="remove_bt" />

<p:dataTable value="#{sItem.childStepsList}" var="sChildItem"
rowIndexVar="rowIndexChild" id="childTable"
emptyMessage="#{msg['label.add.child.step']}"
styleClass="message_text_alert"
style="padding-left:20px !important;">

<p:column>
<p:outputLabel value="#{rowIndex+1}.#{rowIndexChild+1}"
styleClass="fl_left rec_label_input">
</p:outputLabel>
<p:selectOneMenu id="statusAll" filter="true"
filterMatchMode="contains" value="#{sChildItem.subStepName}"
styleClass="inputAttr"
style="width:430px; margin-left:5px !important; float:left !important;">
<f:selectItem itemValue=""
itemLabel="#{msg['recon.agentStepPlaceholder']}"
noSelectionOption="true" />
<f:selectItems value="#{sChildItem.allFieldChildSingle}" />
<!-- <p:ajax event="valueChange" listener="#{sChildItem.update}" update=""></p:ajax> -->
</p:selectOneMenu>
<!-- <h:outputText value="#{sChildItem.myChildValue}"/> -->
<p:commandLink value="#{msg['label.remove.agent.rule']}"
action="#{sItem.removeChildSteps(sChildItem)}"
update=":formAll:multipleTable:childTable" ajax="true"
styleClass="remove_bt fl_left"
style="margin-left:5px !important;" />
</p:column>
</p:dataTable>
<p:commandLink value="#{msg['label.add.agent.rule']}"
action="#{sItem.addChildSteps}" ajax="true"
actionListener="#{reconTemplate.setCurrentRowEdit(sItem)}"
styleClass="link_bt add_bt"
update=":formAll:multipleTable:childTable" rendered="true"
style="margin:0px 0px 0px 22px !important" />
</p:column>
</p:dataTable>
</td>
</tr>

最佳答案

每行的 widgetVars 应该是全局(在页面上)唯一的。在迭代组件中指定 widgetVar 时,您应该在每次迭代时生成不同的 widgetVar。请参阅this answer以另一个问题为例。

那么你的stepValidation应该接受widgetVar作为参数,否则它不知道应该使用哪一行的小部件。

最后你的 inputText 中将会有这样的内容:

widgetVar="stepTemplateWidget#{rowIndex}"
...
onkeyup="stepValidation('stepTemplateWidget#{rowIndex}')"

关于javascript - 如何将 javascript 验证应用于 jsf primefaces 中所有动态生成的输入文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43388755/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com