单个JSF表单在页面方法上与几种表单相对应?

时间:2012-11-14 21:13:51

标签: jsf primefaces

将单个页面上的这些隐藏表单合并为一个单一的大表单是否有意义?

提交属于特定表单process属性的特定参数集可用于提交需要处理的所有元素。

这种单一形式方法在使用多种形式方面的优缺点是什么?

   <span class="hiddenForms">
        <h:form>
            <h:inputHidden id="selctdChnlType_in" value="#{channelCntlr.type}"/>
            <h:inputHidden id="selctdChnlId_in" value="#{channelCntlr.channelId}"/>
            <p:remoteCommand name="updateChnlDataPanel" process="@form" actionListener="#{channelCntlr.init()}" update=":channelHeader, :channelDataPanel, :channelSideColumn"/>
        </h:form>

        <h:form>
            <h:inputHidden id="selctdLOBId_in" value="#{lobCntlr.targetLOBId}"/>
            <p:remoteCommand name="updateLOBPanel" process="selctdLOBId_in, @this" actionListener="#{lobCntlr.retrieveCurrentLOB()}" update=":lobFullContentPanel" />
        </h:form>

        <h:form id="lobAction_form" >
            <h:inputText id="targetLOBId_in" value="#{lobCntlr.targetLOBId}"/>
            <h:inputText id="targetResponseId_in" value="#{lobCntlr.targetResponseOrCommmentId}"/>
            <h:inputText id="targetAction_in" value="#{lobCntlr.targetAction}"/>
            <p:remoteCommand name="doLOBAction" process="targetLOBId_in, targetAction_in, targetResponseId_in,@this" actionListener="#{lobCntlr.doLOBAction()}"/>

            <h:inputText id="targetTopics" value="#{lobCntlr.list}" converter="listConverter"/>
            <p:remoteCommand name="suggestAsHotLOB" process="targetLOBId_in, targetTopics, @this" actionListener="#{lobCntlr.addForTryAsHotLOB()}"/>
        </h:form>

        <h:form id="comment_form" >
            <h:inputText id="targetLOBId_in" value="#{lobCntlr.targetLOBId}"/>
            <h:inputText id="targetCommentOrResponseId_in" value="#{lobCntlr.targetResponseOrCommmentId}"/>
            <h:inputText id="comment_in" value="#{lobCntlr.text_input}" required="true">
                <f:validateLength minimum="15" maximum="1000"/>
            </h:inputText>
            <h:inputText id="previousCommenters_in" value="#{lobCntlr.list}" converter="listConverter"/>

            <p:remoteCommand name="addComment" process="@form" actionListener="#{lobCntlr.addUserComment()}" oncomplete="addCommentToPage(args);" />
            <p:remoteCommand name="deleteComment" process="targetLOBId_in, targetCommentOrResponseId_in, @this" actionListener="#{lobCntlr.removeUserComment()}"  oncomplete="removeFromPage(args);" />
        </h:form>

        <h:form id="recosForm">
            <h:inputText id="startFromRecos_in" value="#{recmdnsCntlr.startFromIndex}"/>
            <p:remoteCommand name="fetchAllRecos" actionListener="#{recmdnsCntlr.retrieveAllRecmmndns()}" process="startFromRecos_in,howManyRecos_in,isLocalStorAvailble_in,@this" />
            <p:remoteCommand name="fetchFollowiesList" actionListener="#{recmdnsCntlr.fetchAllFollowiesList()}" process="@this" oncomplete="storeFollowiesList(args)"/>
        </h:form>

        <span id="editsForm" style="display:none">
            <form action="javascript:void(0);" class="edits_submitter" >
                <p:inputTextarea styleClass="editedText"/>
                <input type="submit" value="Save edits"/>
                <a class="cancel-edit" href="javascript:void(0)">Cancel</a>
            </form>
        </span>

    </span>

2 个答案:

答案 0 :(得分:5)

单个单片JSF表单控件的主要内容是(不必要地)发送到服务器进行处理的大量数据。使用现有代码。考虑以下。如果<h:form id="lobAction_form" ><h:form id="comment_form" >中的所有控件都采用单一形式,那么您将拥有

     <h:inputText id="targetLOBId_in" value="#{lobCntlr.targetLOBId}"/>
        <h:inputText id="targetResponseId_in" value="#{lobCntlr.targetResponseOrCommmentId}"/>
        <h:inputText id="targetAction_in" value="#{lobCntlr.targetAction}"/>
        <p:remoteCommand name="doLOBAction" process="targetLOBId_in, targetAction_in, targetResponseId_in,@this" actionListener="#{lobCntlr.doLOBAction()}"/>

        <h:inputText id="targetTopics" value="#{lobCntlr.list}" converter="listConverter"/>
        <p:remoteCommand name="suggestAsHotLOB" process="targetLOBId_in, targetTopics, @this" actionListener="#{lobCntlr.addForTryAsHotLOB()}"/>
        <h:inputText id="targetLOBId_in" value="#{lobCntlr.targetLOBId}"/>
        <h:inputText id="targetCommentOrResponseId_in" value="#{lobCntlr.targetResponseOrCommmentId}"/>
        <h:inputText id="comment_in" value="#{lobCntlr.text_input}" required="true">
            <f:validateLength minimum="15" maximum="1000"/>
        </h:inputText>
        <h:inputText id="previousCommenters_in" value="#{lobCntlr.list}" converter="listConverter"/>

        <p:remoteCommand name="addComment" process="@form" actionListener="#{lobCntlr.addUserComment()}" oncomplete="addCommentToPage(args);" />
        <p:remoteCommand name="deleteComment" process="targetLOBId_in, targetCommentOrResponseId_in, @this" actionListener="#{lobCntlr.removeUserComment()}"  oncomplete="removeFromPage(args);" />
    </h:form>

对于您在该表单中启动的每个命令操作,可能处理1个输入文本组件,无论如何,您总是将所有13个组件发送到服务器。浪费和不必要。对于小型操作,您将拥有大量的客户端 - 服务器通信,有时会缩短响应时间。根据您正在使用的任何JSF框架,您可能能够在这种情况下获得创造性,有选择地处理组件而不是,但这只是不必要和痛苦。关注点的清晰分离也在表示层中发挥作用。

然后存在验证问题。通常,您将在单个表单中选择标记为required的组件,并且与该表单中的其余组件无关。您很可能无法选择性地处理这些组件而不会影响该表单上的所有其他组件。

答案 1 :(得分:0)

我看到你正在使用primefaces。您可以考虑使用向导组件。使用此组件,有一个表单,在不同的选项卡中有更多部分。当您从一个选项卡转到下一个选项卡时,验证将在Ajax模式下完成。由于使用Ajax完成了部分验证,因此只会处理您正在验证的选项卡的字段并将其发送到服务器。

将更长的表单拆分为更易读和用户友好的部分也很有用。

相关问题