jsf - Primefaces - 验证失败时切换所有就地

标签 jsf jsf-2 primefaces

我使用的是 JSF 2.1 和 primefaces 3.5。假设我有以下代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">
<h:head>
  <title>Web application</title>
</h:head>
<h:body>
    <h1>Editor</h1>
    <h:form>
    <p:wizard>
        <p:tab title="Edit">
            <h2>Edit:</h2>
            <p:dataTable value="#{editorBean.applications}" var="app">
                <p:column headerText="Id">
                    <p:inplace emptyLabel="Value not assigned" editor="true" effectSpeed="fast">
                        <p:inputText value="#{app.id}" />
                    </p:inplace>
                </p:column>
                <p:column headerText="Name">
                    <p:inplace emptyLabel="Value not assigned" editor="true" effectSpeed="fast">
                        <p:inputText value="#{app.name}" required="true" />
                    </p:inplace>
                </p:column>
            </p:dataTable>
        </p:tab>
        <p:tab title="Summary">
            <h2>Summary:</h2>
            <p:dataTable value="#{editorBean.applications}" var="app">
                <p:column headerText="Id">#{app.id}</p:column>
                <p:column headerText="Name">#{app.name}</p:column>
            </p:dataTable>
        </p:tab>
    </p:wizard>
    </h:form>
</h:body>
</html>

当我在向导中按下一步,验证失败(应用程序名称为空)时,页面上包含的所有 inplaces 都会切换到编辑器模式。 我认为不应切换它们,因为当您接受此输入的编辑器时会执行每个输入的验证。

screenshot

看起来很糟糕,尤其是我有很多地方。

我想在验证失败时禁用每个就地编辑器的切换。有谁知道如何解决这个问题?

最佳答案

那是因为 p:inplace 组件不是为此目的而制作的。在像 inplace 这样的数据表中使用时,很少有其他组件会产生问题,但对于您的要求,这可能很有用:

<p:column headerText="Year" style="width:25%">
        <p:cellEditor>
            <f:facet name="output"><h:outputText value="#{car.year}" /></f:facet>
            <f:facet name="input"><p:inputText value="#{car.year}" style="width:96%"     label="Year"/></f:facet>
        </p:cellEditor>
</p:column>

您可以从 primefaces showcase 查看完整示例.

关于jsf - Primefaces - 验证失败时切换所有就地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15580522/

相关文章:

java - 选择下拉菜单项时显示 `form`?

java - NullPointer 与 Primefaces GMap OverlaySelect 事件

jquery - 如何在jquery中引用JSF组件Id?

validation - 如何验证 Primefaces 数据表中的 List<Object> - JSF

jsf-2 - p :selectBooleanCheckbox and the label attached to it

forms - 如何在 <ui :repeat var> in id attribute of a JSF component 中使用 EL

tomcat - MyFaces tomcat7 :run goal cannot start ProtocolHandler "http-bio-8080"

java - 没有 bean 有资格注入(inject)到注入(inject)点 [JSR-299 §5.2.1]

jsf-2 - JSF 2.0 从另一个 Bean 访问应用程序范围 bean

css - 在 PrimeFaces 选项卡组件中更改背景颜色时出现问题