是否可以有一个带有验证的表单并使用 rich:modalPanel 进行数据输入?

发布于 2025-01-04 23:18:52 字数 3145 浏览 2 评论 0原文

Richfaces 3.3.3、Jsf 1.2:

我有一个 a4j:form,它使用一些简单的验证,主要是 required="true" 以确保表单不会在没有某些验证的情况下提交必要的数据。

我还有一些复杂的数据要添加(可选)到表单中,所以我认为最好的方法是使用一个显示 rich:modalPanela4j:commandButton > 用户可以在其中创建复杂的数据集。

创建的数据也会显示在 h:selectManyListbox 中,当 modalPanel 关闭时,该数据会重新渲染。

至少这是计划。我有以下问题:

  • 这反过来似乎会阻止 modalPanel 中选定的数据出现在支持 Bean 中
  • reRender 可以工作,但前提是我通过 immediate="true" 阻止验证 -如果我这样做, 删除立即标记,数据会更新,但前提是没有验证错误

让它按我想要的方式工作的最佳方法是什么?还有其他更好的方法吗?

更新:

失败的验证位于表单的某些不同部分,而不是在通过 modalPanel 输入的数据中,该数据显示在列表框中

代码:

modalPanel:

<rich:modalPanel id="addTrimming" domElementAttachment="parent" width="150" height="130">
    <f:facet name="header">
        <h:panelGroup>
            <h:outputText value="Define Filter" />
        </h:panelGroup>
    </f:facet>
    <f:facet name="controls">
        <h:panelGroup>
            <h:graphicImage value="/images/close.gif" styleClass="hidelink" id="hidelinkAddTrimming"/>
            <rich:componentControl for="addTrimming" attachTo="hidelinkAddTrimming" operation="hide" event="onclick"/>
        </h:panelGroup>
    </f:facet>

    <h:panelGrid id="trimsettings" columns="3">
        <h:outputText value="Target:" style="font-weight:bold"/>
        <h:inputText id="target" label="XML Filename" required="true" value="#{xmlCreator.trimTarget}">
        </h:inputText>
        <h:outputText value=""/>

        <h:outputText value="Mode:"/>
        <h:selectOneMenu value="#{xmlCreator.trimMode}">
            <f:selectItem itemLabel="Quality" itemValue="quality"/> 
            <f:selectItem itemLabel="after Primer" itemValue="afterPrimer"/> 
            <f:selectItem itemLabel="fixed" itemValue="fixed"/>
            <f:selectItem itemLabel="Median length" itemValue="median"/>
            <f:selectItem itemLabel="Motif" itemValue="motif"/>
        </h:selectOneMenu>
        <h:outputText value=""/>

    </h:panelGrid>

    <h:panelGroup>
        <a4j:commandButton value="OK" action="#{xmlCreator.createTrimming}" onclick="from:submit()">
            <a4j:support event="oncomplete" ajaxSingle="true" immediate="true" reRender="trimsPanel"/>
        </a4j:commandButton>
    </h:panelGroup>
</rich:modalPanel>

相关表单部分:

<h:outputText value="Trimming:"/>
<a4j:outputPanel id="trimsPanel">
    <h:selectManyListbox id="trims" value="#{xmlCreator.selectedTrimmings}">
        <f:selectItems value="#{si:toSelectTrimmingList(xmlCreator.trimmings)}"/>
    </h:selectManyListbox>
</a4j:outputPanel>
<a4j:commandButton id="addTrimButton" immediate="true" value=" + Trimming">
    <rich:componentControl for="addTrimming" attachTo="addTrimButton" operation="show" event="onclick"/>
</a4j:commandButton>

Richfaces 3.3.3, Jsf 1.2:

I have a a4j:form that uses some simple validation, mainly required="true" to ensure the form does not get submitted without some necessary data.

I also have some complex data to add (optionally) to the form, so I thought the best way to do this is to have a a4j:commandButton that displays a rich:modalPanel where the user can create the complex data set.

The created data is also displayed in a h:selectManyListbox that is reRendered when the modalPanel is closed.

That's the plan, at least. I have the following problems:

  • reRender works, but only if I prevent validation via immediate="true" - which in turn seems to prevent the selected data from the modalPanel to be present in the backing Bean
  • if I remove the immediate tag, the data gets updated, but only if there are no validation errors

What is the best way to get this to work the way I want? Is there another, better way?

UPDATE:

The Validation that fails is in some different part of the form, not in the data entered via the modalPanel, which is displayed in the Listbox

CODE:

modalPanel:

<rich:modalPanel id="addTrimming" domElementAttachment="parent" width="150" height="130">
    <f:facet name="header">
        <h:panelGroup>
            <h:outputText value="Define Filter" />
        </h:panelGroup>
    </f:facet>
    <f:facet name="controls">
        <h:panelGroup>
            <h:graphicImage value="/images/close.gif" styleClass="hidelink" id="hidelinkAddTrimming"/>
            <rich:componentControl for="addTrimming" attachTo="hidelinkAddTrimming" operation="hide" event="onclick"/>
        </h:panelGroup>
    </f:facet>

    <h:panelGrid id="trimsettings" columns="3">
        <h:outputText value="Target:" style="font-weight:bold"/>
        <h:inputText id="target" label="XML Filename" required="true" value="#{xmlCreator.trimTarget}">
        </h:inputText>
        <h:outputText value=""/>

        <h:outputText value="Mode:"/>
        <h:selectOneMenu value="#{xmlCreator.trimMode}">
            <f:selectItem itemLabel="Quality" itemValue="quality"/> 
            <f:selectItem itemLabel="after Primer" itemValue="afterPrimer"/> 
            <f:selectItem itemLabel="fixed" itemValue="fixed"/>
            <f:selectItem itemLabel="Median length" itemValue="median"/>
            <f:selectItem itemLabel="Motif" itemValue="motif"/>
        </h:selectOneMenu>
        <h:outputText value=""/>

    </h:panelGrid>

    <h:panelGroup>
        <a4j:commandButton value="OK" action="#{xmlCreator.createTrimming}" onclick="from:submit()">
            <a4j:support event="oncomplete" ajaxSingle="true" immediate="true" reRender="trimsPanel"/>
        </a4j:commandButton>
    </h:panelGroup>
</rich:modalPanel>

relevant form part:

<h:outputText value="Trimming:"/>
<a4j:outputPanel id="trimsPanel">
    <h:selectManyListbox id="trims" value="#{xmlCreator.selectedTrimmings}">
        <f:selectItems value="#{si:toSelectTrimmingList(xmlCreator.trimmings)}"/>
    </h:selectManyListbox>
</a4j:outputPanel>
<a4j:commandButton id="addTrimButton" immediate="true" value=" + Trimming">
    <rich:componentControl for="addTrimming" attachTo="addTrimButton" operation="show" event="onclick"/>
</a4j:commandButton>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

策马西风 2025-01-11 23:18:52

如果您以一种形式进行操作,那么您应该将其分成两种:一种是您的主形式,另一种是模式面板内的形式。因此,您将能够独立于主表单提交模式面板,并且模式面板中的提交按钮将如下所示:

<a4j:commandButton value="OK" action="#{xmlCreator.createTrimming}" reRender="trimsPanel"/>

If you do it in one form than you should separate it into two: one will be your main form and another will be form inside modal panel. Thus you'll be able to submit modal panel independently of main form and your submit button in modal panel will look like this:

<a4j:commandButton value="OK" action="#{xmlCreator.createTrimming}" reRender="trimsPanel"/>
半枫 2025-01-11 23:18:52

当使用 a:commandButtona:commandLink 关闭面板时,您应该使用 process 立即将 modalpanel 的数据发送到 bean。
为此,模态面板数据必须按预期有效,因此您将获得有效的新数据并将其添加到 h:selectManyListBox 的 bean 值并重新渲染 h:selectManyListBox

这应该有效。如果没有,请发布您的 a:form 和 modalPanel 完整代码进行检查。

you should use process with immediate to send modalpanel's data to bean when closing panel with a a:commandButton or a:commandLink.
for this, modal panel data has to be valid as expected, so you will get valid new data and add it to h:selectManyListBox 's bean value and reRender h:selectManyListBox.

this should work. if not please post your a:form and modalPanel code full to check.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文