【问题标题】:Faces validation not lost CSS style when fill out the field required填写必填字段时,人脸验证不会丢失 CSS 样式
【发布时间】:2016-02-13 04:27:35
【问题描述】:

我想在以下问题上得到一些帮助,现在我非常感谢您的帮助和关注。

我在 JSF 2 / Primefaces 5.1 中有一个表单,其中一个组件在选择中更新另一个组件,这两个组件都是必需的。

我的问题发生在验证之后,是在我填写了一个字段之后,当这种情况发生时,组件会自动填充另一个字段,但是验证样式在第二个组件中继续存在。

请参阅 SS,以便更好地理解:

提交前:

停止必填字段

填写字段并重新提交:

我怎样才能改变这种行为并使样式保持在第二个字段中,我尝试了很多方法,但我没有想法,除了验证 css 外,其他一切都很好

我的代码:

<h:form id="stepInsertFormId" acceptcharset="UTF-8">
        <p:panelGrid id="stepInsertPanelId" styleClass="formPanelGridPage" cellpadding="7" >
            <p:row>
                <p:column styleClass="adrGridLabel"> 
                    <p:outputLabel for="stageCodeInsertSelectId" 
                                   value="#{myMsg['common.stage']}" 
                                   title="#{myMsg['common.stage.title']}"
                                   styleClass="myGridLabel" />
                </p:column>
                <p:column styleClass="adrGridInput" style="vertical-align: bottom;">
                    <p:selectOneMenu id="stageCodeInsertSelectId"
                                     value="#{Step.stepInsert.selectedStage}"
                                     var="stage"
                                     converter="basedEntityConverter"
                                     label="#{myMsg['common.stageCode.title']}"
                                     filter="true"
                                     required="true"
                                     filterMatchMode="startsWith" >
                        <f:selectItem itemLabel="#{myMsg['common.select']}" itemValue="" />
                        <f:selectItems value="#{Step.stages}" 
                                       var="stageInsert" 
                                       itemLabel="#{stageInsert.id.stageCode}" 
                                       itemValue="#{stageInsert}" />
                        <p:column>
                                <h:outputText value="#{stage.id.stageCode}" />
                        </p:column>
                        <p:column>
                            <h:outputText value="#{stage.description}" />
                         </p:column>
                        <p:ajax event="change" process="@this" 
                                               update="stepInsertPanelId, :myMessagesId" 
                                               listener="#{Step.doReloadStepsInsert}" />
                    </p:selectOneMenu>               
                    <p:spacer width="5px" height="1px"/>
                    <p:selectOneMenu id="stageDescriptionInsertSelectId"
                                         value="#{Step.stepInsert.selectedStage}"
                                         var="stage"
                                         converter="basedEntityConverter"
                                         filter="true"
                                         required="true"
                                         filterMatchMode="startsWith" 
                                         style="width:260px"
                                         label="#{myMsg['common.stageDescription.title']}">
                            <f:selectItem itemLabel="#{myMsg['common.select']}" itemValue="" />           
                            <f:selectItems value="#{Step.stages}" 
                                           var="stageInsert" 
                                           itemLabel="#{stageInsert.description}" 
                                           itemValue="#{stageInsert}" />
                            <p:column>
                                <h:outputText value="#{stage.id.stageCode}" />
                            </p:column>
                            <p:column>
                                <h:outputText value="#{stage.description}" />
                             </p:column>
                            <p:ajax event="change" process="@this" 
                                                   update="stepInsertPanelId" 
                                                   listener="#{Step.doReloadStepsInsert}" />
                    </p:selectOneMenu>
                </p:column>

【问题讨论】:

  • 第三张截图是通过h:form按钮还是ajax提交之后?选择选项process="@this stageDescriptionInsertSelectId" 时,您可以尝试在第一个菜单值旁边处理第二个菜单值。
  • 第三个是在ajax提交之后。是时候我在第一个字段中选择一个项目并且该字段执行 ajax 来填充第二个字段。我尝试了这个解决方案,但没有成功。我已经尝试更新 de IDS 字段和表单
  • 您是否查看了右侧“相关”标题下的帖子(如果您在普通电脑上查看此帖子)?

标签: css jsf jsf-2 primefaces


【解决方案1】:

问题与更新阶段的生命周期有关,ajax在升级第二个字段的那一刻失去了对ids的引用,这个行为已经提供并且有一个标签resetValue Primefaces,解决此问题:

这是最终的解决方案:

<p:ajax event="change" process="@this" 
                                                       update="stageCodeInsertLabelId, stageCodeInsertSelectId
                                                                                     , stageDescriptionInsertSelectId
                                                                                     , :myMessagesId"
                                                       resetValues="true"
                                                       listener="#{Step.doReloadStepsInsert}" />

默认值为假。

这篇文章帮助我理解并解决了这个问题行为

How can I populate a text field using PrimeFaces AJAX after validation errors occur?

【讨论】:

  • 不客气……那么你的问题实际上是重复的吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-23
  • 2013-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多