作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在带有 editable=true 的 p:selectOneMenu
上使用带有单元格编辑和验证器的 p:dataTable
。如果所选的 p:selectOneMenu 值或输入的值无效,我希望单元格编辑状态保持在编辑模式(第二个屏幕截图),并在输入周围显示红色框,就像我使用常规表单一样(第三个屏幕截图)。当验证失败时,会显示咆哮和消息,但下拉列表周围的红色框不会持续存在,恐怕用户可能不会注意到(第一个屏幕截图)。我不知道如何进行 ajax 更新以显示红色框,但将单元格保持在编辑模式,以便下拉菜单和红色框仍然可见。
<p:dataTable id="table" value="#{bean.data}" var="lineItem" editable="true" editMode="cell">
<p:column headerText="* Account">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{lineItem.account}" />
</f:facet>
<f:facet name="input">
<p:selectOneMenu id="so" value="#{lineItem.account}" editable="true" dynamic="true" converter="omnifaces.SelectItemsConverter" title="Type an account or select a stored favorite" validator="com.gdeb.rozycki.app.acountValidator" >
<f:selectItem noSelectionOption="true" itemLabel="---Favorites" itemValue="null" />
<f:selectItems value="#{bean.favorites}" var="fav" itemLabel="#{fav.acctNum}" itemValue="#{fav}" />
<p:ajax disabled="#{facesContext.validationFailed}" update="table growl messages" listener="#{bean.updateAccountInline(lineItem)}" />
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
此屏幕截图我尝试将帐户更改为使用空间保存的存储收藏夹,但我们不再需要空间了。 (是的,我现在有验证,当用户保存他们最喜欢的帐号时不允许有空格,但我们将实现其他验证)当验证失败时,仅显示标题和咆哮消息。如第二个屏幕截图所示,在他们再次单击下拉菜单之前,红线是不可见的。
最佳答案
ajax
调用在其 update
属性中具有数据表 ID table
。我删除了那个 ClientID 并删除了 disabled="#{facesContext.validationFailed}"
我认为 cellEdit
函数会自动更新实现 cellEdit 的组件 ClientId。因此无需在我的 ajax 标记中也明确指定。
而且我还猜测 ajax 标记总是运行更新,但监听器仅在成功时运行。
我可能不完全理解为什么,但这对我有用:
<p:ajax update="growl messages" listener="#{bean.updateAccountInline(lineItem)}" />
关于jsf - Primefaces 单元格编辑在验证失败时留在编辑模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63453466/
我是一名优秀的程序员,十分优秀!