如何在弹出面板中提交值?

发布于 2024-11-29 21:09:41 字数 2619 浏览 0 评论 0原文

我一直在努力理解如何以正确的方式使用 rich:popupPanel 组件。有(至少我找不到)一些关于如何使用 rich:popupPanel 以及如何从中提交值的帖子。

更糟糕的是,面板接缝添加(检查 html 时)硬编码的“_content”到其组件 id 名称(到生成的 div)。我尝试使用 aj4:region 标签来部分渲染完整的表单。但这并没有起作用,导致没有任何内容发布到托管 bean。所以现在我只剩下一个选项,即面板在页面主面板之外有自己的表单。

我可以看到正在评估表单(弹出窗口)值,但没有执行保存这些值的 bean 函数(我看到命令按钮的 POST 请求)。我目前能想到的唯一原因是弹出面板使用另一个 bean 来保存页面上主窗体的值(它们都是会话范围的)。 我正在考虑忽略弹出面板,因为它很难完成这项工作。也许这是一个众所周知的秘密,因为很少有人发帖谈论它。如果使用 componentController 或仅使用 a4j:commanLink,其行为是相同的。

如何从 rich:popupPanel 提交值并调用支持 bean 函数来保存弹出表单值?

如果有人能阐明这一点,我将不胜感激,问候克里斯。

我在 Glassfish 3.1 上使用 Richfaces 4.0-final

<h:form id="main_form">
<!-- Command for popup -->
<a4j:commandLink actionListener="#{userController.prepareCreateSysRequest}" oncomplete="#{rich:component('popup_sys_user_req_form:popup_sys_user_req')}.show(); return false;" 
                                     execute="@this" value="Request New Sector/Category" />

    ...
<a4j:commandButton action="#{projectController.Create}" ...>
</h:form>

<h:form id="popup_sys_user_req_form">
    <rich:popupPanel id="popup_sys_user_req" modal="true" autosized="true" resizeable="false">
        <f:facet name="header">
            <h:outputText value="New Project Request" />
        </f:facet>
        <f:facet name="controls">
            <h:outputLink value="#"
                          onclick="#{rich:component('popup_sys_user_req')}.hide(); return false;">
                X
            </h:outputLink>
        </f:facet>
        <h:panelGrid columns="2">
            <h:outputLabel value="Request New:" />
            <h:selectOneMenu id="sys_req_type" value="#{userController.selectedSysRequestType}" required="true" requiredMessage="Request Type is required" title="Request Type">
                <f:selectItems value="#{userController.getSysRequestTypeItems()}">
                </f:selectItems>
            </h:selectOneMenu>
            <h:outputLabel value="Description:" />
            <h:inputTextarea id="user_req_desc" value="#{userController.selectedSysUserRequest.description}" required="true" requiredMessage="Decription is missing" />
        </h:panelGrid>
        <a4j:commandButton action="#{userController.CreateSysUserRequest}" onclick="#{rich:component('popup_sys_user_req')}.hide(); return false;" execute="@form" render="popup_sys_user_req_form" value="Send Request" />
    </rich:popupPanel>
</h:form>

I have bean struggling to understand how to use the rich:popupPanel component in the right way. There are (at least not that I could find) few post about how to use the rich:popupPanel and how to submit values from it.

To make matter worse the panel seams to add (when checking the html) a hard coded "_content" to its component id name (to the div generated). I have tried to use aj4:region tag to partial render the complete form. But that didn't seamed to work, cause nothing where posted to managed bean. So now I have one option left, where the panel has its own form, outside the main one on the page.

I can see that the evaluation of the form (popup) values is happening, but not the execution of the bean function that persist the values (I see the POST request of the command button). The only reason I can think of at the moment, is that the pop-up panel use another bean to persist the values that the main form on the page (both of them are session scoped).
I am thinking of omit the pop-up panel all together, since it seams so hard to make this work. Maybe its a well know secret, since it so few post about it. It behaves the same if if use componentController or only a a4j:commanLink.

How is it possible to submit values from a rich:popupPanel and invoke a backing bean function to persist the pop-up form values ?

Appreciate if someone can shed some light on this, greetings Chris.

I use Richfaces 4.0-final on Glassfish 3.1

<h:form id="main_form">
<!-- Command for popup -->
<a4j:commandLink actionListener="#{userController.prepareCreateSysRequest}" oncomplete="#{rich:component('popup_sys_user_req_form:popup_sys_user_req')}.show(); return false;" 
                                     execute="@this" value="Request New Sector/Category" />

    ...
<a4j:commandButton action="#{projectController.Create}" ...>
</h:form>

<h:form id="popup_sys_user_req_form">
    <rich:popupPanel id="popup_sys_user_req" modal="true" autosized="true" resizeable="false">
        <f:facet name="header">
            <h:outputText value="New Project Request" />
        </f:facet>
        <f:facet name="controls">
            <h:outputLink value="#"
                          onclick="#{rich:component('popup_sys_user_req')}.hide(); return false;">
                X
            </h:outputLink>
        </f:facet>
        <h:panelGrid columns="2">
            <h:outputLabel value="Request New:" />
            <h:selectOneMenu id="sys_req_type" value="#{userController.selectedSysRequestType}" required="true" requiredMessage="Request Type is required" title="Request Type">
                <f:selectItems value="#{userController.getSysRequestTypeItems()}">
                </f:selectItems>
            </h:selectOneMenu>
            <h:outputLabel value="Description:" />
            <h:inputTextarea id="user_req_desc" value="#{userController.selectedSysUserRequest.description}" required="true" requiredMessage="Decription is missing" />
        </h:panelGrid>
        <a4j:commandButton action="#{userController.CreateSysUserRequest}" onclick="#{rich:component('popup_sys_user_req')}.hide(); return false;" execute="@form" render="popup_sys_user_req_form" value="Send Request" />
    </rich:popupPanel>
</h:form>

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

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

发布评论

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

评论(2

驱逐舰岛风号 2024-12-06 21:09:41

对于我所做的事情,我曾经遇到过只有第一次才必须提交两次的问题。

为了解决这个问题,表单必须位于 popupPane 之外。并且 popupPanel 应该具有属性 domElementAttachment="form"。

例子。

        <h:form>
            <rich:popupPanel id="shipmentItemUpdateDialog" 
                             autosized="true"
                             domElementAttachment="form">
                <f:facet name="header">
                    <h:panelGroup>
                        <h:outputText value="#{shipmentBundle.shipmentItemDetailsHeader}" />
                    </h:panelGroup>
                </f:facet>
                <f:facet name="controls">
                    <h:commandLink>
                        <h:graphicImage value="/core/images/modal/close.png"/>
                        <rich:componentControl target="shipmentItemUpdateDialog" operation="hide" />
                    </h:commandLink>
                </f:facet>
                <h:outputText for="shipmentItemName"
                              value="#{coreBundle.requiredChar} #{shipmentBundle.shipmentItemName}"
                              />
                <h:inputText id="shipmentItemName" 
                             disabled ="false"
                             required ="true"
                             value="#{shipmentItemController.shipmentItemUI.value.name}" 
                             label="#{shipmentBundle.shipmentItemName}"
                             size="40" >
                </h:inputText>  

                <h:outputText for="shipmentItemCode"
                              value="#{coreBundle.requiredChar} #{shipmentBundle.shipmentItemCode}"
                              />
                <h:inputText id="shipmentItemCode" 
                             disabled ="false"
                             required ="true"
                             value="#{shipmentItemController.shipmentItemUI.value.code}" 
                             label="#{shipmentBundle.shipmentItemCode}"
                             size="40" >
                </h:inputText>         

                <h:outputText value="#{coreBundle.requiredChar} #{shipmentBundle.shipmentItemAmount}"
                              />
                <h:inputText id="shipmentItemAmount" 
                             disabled ="false"
                             required ="true"
                             value="#{shipmentItemController.shipmentItemUI.value.amount}" 
                             label="#{shipmentBundle.shipmentItemAmount}"
                             size="4" >
                    <f:validateLongRange minimum="1"/>
                </h:inputText>      


                <h:outputText value="#{coreBundle.requiredChar} #{shipmentBundle.shipmentItemNeedsCooling}"
                              />
                <h:selectBooleanCheckbox id="shipmentItemNeedsCooling" 
                                         disabled ="false"
                                         required ="true"
                                         value="#{shipmentItemController.shipmentItemUI.value.needsCooling}" 
                                         label="#{shipmentBundle.shipmentItemNeedsCooling}"
                                         />                    

                <h:outputText for="shipmentItemDetails"
                              value="#{shipmentBundle.shipmentItemDetails}"
                              />
                <h:inputTextarea id="shipmentItemDetails" 
                                 disabled ="false"
                                 required ="true"
                                 value="#{shipmentItemController.shipmentItemUI.value.details}" 
                                 label="#{shipmentBundle.shipmentItemDetails}"
                                 cols="38" 
                                 rows="5" 
                                 /> 
            </h:panelGrid>

            <h:panelGrid columns="1" dir="LTR">
                <h:panelGrid columns="2" dir="LTR">
                    <a4j:commandButton value="#{coreBundle.acceptButton}" 
                                       action="#{shipmentItemController.onUpdate()}"
                                       render="shipmentItemsTable">
                    </a4j:commandButton>
                    <h:commandLink value="#{coreBundle.closeLink}" 
                                   immediate="true">
                        <rich:componentControl target="shipmentItemUpdateDialog" operation="hide" />
                    </h:commandLink>
                </h:panelGrid>
                <h:outputText value="#{coreBundle.requiredText}"/>
            </h:panelGrid>
            </rich:popupPanel>              
        </h:form>

我希望这有帮助。

For what I have done I used to have the issue to got to submit twice only the first time.

To fix it the form got to be outside the popupPane. And also that the popupPanel should have the attibute domElementAttachment="form".

Example.

        <h:form>
            <rich:popupPanel id="shipmentItemUpdateDialog" 
                             autosized="true"
                             domElementAttachment="form">
                <f:facet name="header">
                    <h:panelGroup>
                        <h:outputText value="#{shipmentBundle.shipmentItemDetailsHeader}" />
                    </h:panelGroup>
                </f:facet>
                <f:facet name="controls">
                    <h:commandLink>
                        <h:graphicImage value="/core/images/modal/close.png"/>
                        <rich:componentControl target="shipmentItemUpdateDialog" operation="hide" />
                    </h:commandLink>
                </f:facet>
                <h:outputText for="shipmentItemName"
                              value="#{coreBundle.requiredChar} #{shipmentBundle.shipmentItemName}"
                              />
                <h:inputText id="shipmentItemName" 
                             disabled ="false"
                             required ="true"
                             value="#{shipmentItemController.shipmentItemUI.value.name}" 
                             label="#{shipmentBundle.shipmentItemName}"
                             size="40" >
                </h:inputText>  

                <h:outputText for="shipmentItemCode"
                              value="#{coreBundle.requiredChar} #{shipmentBundle.shipmentItemCode}"
                              />
                <h:inputText id="shipmentItemCode" 
                             disabled ="false"
                             required ="true"
                             value="#{shipmentItemController.shipmentItemUI.value.code}" 
                             label="#{shipmentBundle.shipmentItemCode}"
                             size="40" >
                </h:inputText>         

                <h:outputText value="#{coreBundle.requiredChar} #{shipmentBundle.shipmentItemAmount}"
                              />
                <h:inputText id="shipmentItemAmount" 
                             disabled ="false"
                             required ="true"
                             value="#{shipmentItemController.shipmentItemUI.value.amount}" 
                             label="#{shipmentBundle.shipmentItemAmount}"
                             size="4" >
                    <f:validateLongRange minimum="1"/>
                </h:inputText>      


                <h:outputText value="#{coreBundle.requiredChar} #{shipmentBundle.shipmentItemNeedsCooling}"
                              />
                <h:selectBooleanCheckbox id="shipmentItemNeedsCooling" 
                                         disabled ="false"
                                         required ="true"
                                         value="#{shipmentItemController.shipmentItemUI.value.needsCooling}" 
                                         label="#{shipmentBundle.shipmentItemNeedsCooling}"
                                         />                    

                <h:outputText for="shipmentItemDetails"
                              value="#{shipmentBundle.shipmentItemDetails}"
                              />
                <h:inputTextarea id="shipmentItemDetails" 
                                 disabled ="false"
                                 required ="true"
                                 value="#{shipmentItemController.shipmentItemUI.value.details}" 
                                 label="#{shipmentBundle.shipmentItemDetails}"
                                 cols="38" 
                                 rows="5" 
                                 /> 
            </h:panelGrid>

            <h:panelGrid columns="1" dir="LTR">
                <h:panelGrid columns="2" dir="LTR">
                    <a4j:commandButton value="#{coreBundle.acceptButton}" 
                                       action="#{shipmentItemController.onUpdate()}"
                                       render="shipmentItemsTable">
                    </a4j:commandButton>
                    <h:commandLink value="#{coreBundle.closeLink}" 
                                   immediate="true">
                        <rich:componentControl target="shipmentItemUpdateDialog" operation="hide" />
                    </h:commandLink>
                </h:panelGrid>
                <h:outputText value="#{coreBundle.requiredText}"/>
            </h:panelGrid>
            </rich:popupPanel>              
        </h:form>

I hope this helps.

你的心境我的脸 2024-12-06 21:09:41

我认为你说得对......将弹出窗口视为常规页面。要提交并关闭弹出窗口,请执行以下操作:

<a4j:commandButton value="Save" onclick="#{rich:component('panelId}.hide();" render="..."/>

希望这有帮助..

I think you got it right.. think of the pop-up as a regular page. To submit and close the pop-up, do something like this:

<a4j:commandButton value="Save" onclick="#{rich:component('panelId}.hide();" render="..."/>

Hope this helps..

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