是否可以有一个带有验证的表单并使用 rich:modalPanel 进行数据输入?
Richfaces 3.3.3、Jsf 1.2:
我有一个 a4j:form
,它使用一些简单的验证,主要是 required="true"
以确保表单不会在没有某些验证的情况下提交必要的数据。
我还有一些复杂的数据要添加(可选)到表单中,所以我认为最好的方法是使用一个显示 rich:modalPanel
的 a4j: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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您以一种形式进行操作,那么您应该将其分成两种:一种是您的主形式,另一种是模式面板内的形式。因此,您将能够独立于主表单提交模式面板,并且模式面板中的提交按钮将如下所示:
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:
当使用
a:commandButton
或a: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
ora: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 reRenderh:selectManyListBox
.this should work. if not please post your
a:form
and modalPanel code full to check.