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

标签 jsf jakarta-ee glassfish richfaces

我让 bean 很难理解如何以正确的方式使用 rich:popupPanel 组件。关于如何使用 rich:popupPanel 以及如何从中提交值的帖子(至少我找不到)很少。

更糟糕的是,面板接缝添加(在检查 html 时)一个硬编码的“_content”到它的组件 id 名称(到生成的 div)。我尝试使用 aj4:region 标签来部分呈现完整的表单。但这并没有奏效,导致没有发布到托管 bean 的地方。所以现在我剩下一个选项,面板有自己的形式,在页面上的主要形式之外。

我可以看到表单(弹出)值的评估正在发生,但没有执行持久化值的 bean 函数(我看到命令按钮的 POST 请求)。目前我能想到的唯一原因是弹出面板使用另一个 bean 来保留页面上主表单的值(它们都是 session 范围的)。
我正在考虑一起省略弹出面板,因为很难做到这一点。也许这是一个众所周知的 secret ,因为关于它的帖子很少。如果使用 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>

最佳答案

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

为了修复它,表单必须在 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>

我希望这有帮助。

关于jsf - 如何在弹出面板中提交值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7062931/

相关文章:

java - 在 JSF primefaces 中上传文件

java - Java EE 中的用户管理安全性

java - 在 2 节点 wildfly 集群中调用远程 ejb

java - 设置 Glassfish 数据源问题

java - JSF 和过滤器重定向生成空白页

javascript - 带有 Jsf 1.1 实现的 Ajax

JavaMail附件空指针

mysql - GlassFish Server jdbc 无法将记录插入数据库

glassfish - 严重 : EJB5070: Exception creating stateless session bean - solution with beans. xml

css - 设置 p :panel 的背景图像