0

我正在开发一个项目,以前的程序员在任何地方都重复代码。我需要对一些 JSF 代码进行更改,但不想在任何地方都重复我的更改。我认为必须有更好的方法。

这是场景;有多个数据表显示在几个不同的选项卡上,都在同一页面上。除了 id 和值/数据源不同之外,每个数据表在各个方面都是相同的。我需要使用与构建它相同的技术,因此我无法更改版本或任何东西。

设置:

  • Websphere 7
  • Java 1.5
  • JSF 1.1
  • 战斧1.1

当包含数据表时,如何将数据表外部化并定义 id 和值?这样我就不必为每个表多次进行相同的更改。

选项卡式面板,其中每个 Edit.jsp 页面都包含下面的数据表。

<odc:tabbedPanel id="sampleTab" styleClass="tabbedPanel_3" 
    slantActiveRight="4" slantActiveLeft="4" slantInactiveRight="4"
    slantInactiveLeft="4" width="100%" height="100%"
    variableTabLength="true" showBackNextButton="true" showTabs="true">

    <!--  Start Test panel -->
    <odc:bfPanel id="testsDisplayPanel" name="IPA"
        showFinishCancelButton="false">
        <jsp:include flush="true" page="editHeader.jsp" />
        <jsp:include flush="true" page="testEdit.jsp" />
    </odc:bfPanel>

    <!--  Start Elisa panel -->
    <odc:bfPanel id="elisaDisplayPanel" name="ELISA"
        showFinishCancelButton="false">
        <jsp:include flush="true" page="editHeader.jsp" />
        <jsp:include flush="true" page="elisaEdit.jsp" />
    </odc:bfPanel>

    <!--  Start NMO Tests panel -->
    <odc:bfPanel id="nmoDisplayTestPanel" name="NMO IF"
        showFinishCancelButton="false">
        <jsp:include flush="true" page="editHeader.jsp" />
        <jsp:include flush="true" page="nmoTestEdit.jsp" />
    </odc:bfPanel>

    <!--  Start IF Tests panel -->
    <odc:bfPanel id="ifDisplayTestsPanel" name="PNEO IF"
        showFinishCancelButton="false" >
        <jsp:include flush="true" page="editHeader.jsp" />  
        <jsp:include flush="true" page="ifTestEdit.jsp" />
    </odc:bfPanel>


    <f:facet name="back">
        <hx:commandExButton id="tabbedPanel1back" style="display:none"
            type="submit" value="&lt; Back" />
    </f:facet>
    <f:facet name="next">
        <hx:commandExButton id="tabbedPanel1next" style="display:none"
            type="submit" value="Next &gt;" />
    </f:facet>
    <f:facet name="finish">
        <hx:commandExButton id="tabbedPanel1finish" style="display:none"
            type="submit" value="Finish" />
    </f:facet>
    <f:facet name="cancel">
        <hx:commandExButton id="tabbedPanel1cancel" style="display:none"
            type="submit" value="Cancel" />
    </f:facet>
</odc:tabbedPanel>

表格示例(我缩短了它,它确实有 20 列。)

<h:dataTable id="elisaTestResults" styleClass="data-entry"
    value="#{pc_SampleEdit.sample.test.elisaTestResults}" var="elisaTestResults" border="0"
    cellpadding="0" cellspacing="0" rowClasses="none, grey-highlight">

    <!-- hidden input column -->
    <h:column>
        <h:inputHidden value="#{elisaTestResults.testResultsIk}" />
        <h:inputHidden value="#{elisaTestResults.test.testIk}" />
        <h:inputHidden value="#{elisaTestResults.dirty}" id="mustSaveT1" />
    </h:column>

    <!-- Ordered column --> 
    <h:column id="testResultsOrderedCol">
        <f:facet name="header">
            <h:outputText id="ot01" styleClass="outputText" value="" />
        </f:facet>
        <h:selectOneMenu id="ordered" styleClass="selectOneMenu"
            rendered="#{elisaTestResults.ordered != null}"
            value="#{elisaTestResults.ordered}"
            onchange="setDirty(this, 'T1')"
            converter="javax.faces.convert.IntegerConverter">
            <f:selectItems value="#{pc_UtilRefLists.ordered}" />
        </h:selectOneMenu>
    </h:column>

    <!-- Test Name Column -->   
    <h:column id="testResultsTestNameCol">
        <f:facet name="header">
            <h:outputText id="ot02" styleClass="outputText" value="Test Name" />
        </f:facet>
        <h:outputText id="testResultsTestName" style="font-weight: bold"
            value="#{elisaTestResults.testName}" />
    </h:column>

    <!-- Result1 Column --> 
    <h:column id="testResultsResult1Col">
        <f:facet name="header">
            <h:outputText id="ot03" styleClass="outputText" value="Result1" />
        </f:facet>
        <t:inputText id="testResultsResult1" style="font-weight: bold"
            value="#{elisaTestResults.result1}" size="7" maxlength="15"
            onchange="setTestDate(this, 'T1')" 
            displayValueOnly="#{elisaTestResults.valid1 != null && elisaTestResults.valid1}" 
            displayValueOnlyStyleClass="outputText"/>       
    </h:column>

    <!-- Date1 Column -->   
    <h:column id="testResultsDate1Col">
        <f:facet name="header">
            <h:outputText id="ot04" styleClass="outputText" value="Date" />
        </f:facet>
        <h:panelGroup rendered="#{!elisaTestResults.valid1}">
            <h:inputText id="testResultsDate1__DT" styleClass="inputText"
                value="#{elisaTestResults.date1}"
                onchange="setDirty(this, 'T1')"
                size="7">
                <f:convertDateTime type="date" pattern="MM/dd/yyyy" />
            </h:inputText>
            <hx:graphicImageEx id="testResultsDate1__DTCal"
            styleClass="graphicImageEx" value="/shared/images/schedule.gif" />
            <h:message styleClass="error-message" for="testResultsDate1__DT" />
        </h:panelGroup>
        <h:outputText id="testResultsDate1" styleClass="outputText"
            value="#{elisaTestResults.date1}" rendered="#{elisaTestResults.valid1}">
            <f:convertDateTime type="date" pattern="MM/dd/yyyy" />
        </h:outputText>
    </h:column>

    <!-- Valid Result1 Column -->   
    <h:column id="testResultsValid1Col">
        <f:facet name="header">
            <h:outputText id="ot05" styleClass="outputText" value="OK" />
        </f:facet>
        <h:selectBooleanCheckbox id="testResultsValid1"
            onchange="setDirty(this, 'T1')"
            styleClass="selectBooleanCheckbox" value="#{elisaTestResults.valid1}" />
    </h:column>

    <!-- Result2 Column --> 
    <h:column id="testResultsResult2Col">
        <f:facet name="header">
            <h:outputText id="ot06" styleClass="outputText" value="Result2" />
        </f:facet>
        <t:inputText id="testResultsResult2" style="font-weight: bold"
            value="#{elisaTestResults.result2}" size="7" maxlength="15"
            onchange="setTestDate(this, 'T1')" 
            displayValueOnly="#{elisaTestResults.valid2 != null && elisaTestResults.valid2}" 
            displayValueOnlyStyleClass="outputText"/>       
    </h:column>

</h:dataTable>
4

1 回答 1

0

为了解决这个问题,我将 jsf 代码分解为几个 jsp 文件,并在需要的地方插入它们。

数据表Elisa.jsp

<h:dataTable id="elisaTestResults" styleClass="data-entry"
  value="#{pc_SampleEdit.sample.test.elisaTestResults}" var="elisaTestResults" border="0"
  cellpadding="0" cellspacing="0" rowClasses="none, grey-highlight">

  <jsp:include flush="true" page="innerTable.jsp"/> 

</h:dataTable>

数据表Nmo.jsp

<h:dataTable id="nmoTestResults" styleClass="data-entry"
  value="#{pc_SampleEdit.sample.test.nmoTestResults}" var="elisaTestResults" border="0"
  cellpadding="0" cellspacing="0" rowClasses="none, grey-highlight">

  <jsp:include flush="true" page="innerTable.jsp"/> 

</h:dataTable>

内表.jsp

<!-- hidden input column -->
<h:column>
    <h:inputHidden value="#{elisaTestResults.testResultsIk}" />
    <h:inputHidden value="#{elisaTestResults.test.testIk}" />
    <h:inputHidden value="#{elisaTestResults.dirty}" id="mustSaveT1" />
</h:column>

<!-- Ordered column --> 
<h:column id="testResultsOrderedCol">
    <f:facet name="header">
        <h:outputText id="ot01" styleClass="outputText" value="" />
    </f:facet>
    <h:selectOneMenu id="ordered" styleClass="selectOneMenu"
        rendered="#{elisaTestResults.ordered != null}"
        value="#{elisaTestResults.ordered}"
        onchange="setDirty(this, 'T1')"
        converter="javax.faces.convert.IntegerConverter">
        <f:selectItems value="#{pc_UtilRefLists.ordered}" />
    </h:selectOneMenu>
</h:column>

<!-- Test Name Column -->   
<h:column id="testResultsTestNameCol">
    <f:facet name="header">
        <h:outputText id="ot02" styleClass="outputText" value="Test Name" />
    </f:facet>
    <h:outputText id="testResultsTestName" style="font-weight: bold"
        value="#{elisaTestResults.testName}" />
</h:column>

<!-- Result1 Column --> 
<h:column id="testResultsResult1Col">
    <f:facet name="header">
        <h:outputText id="ot03" styleClass="outputText" value="Result1" />
    </f:facet>
    <t:inputText id="testResultsResult1" style="font-weight: bold"
        value="#{elisaTestResults.result1}" size="7" maxlength="15"
        onchange="setTestDate(this, 'T1')" 
        displayValueOnly="#{elisaTestResults.valid1 != null && elisaTestResults.valid1}" 
        displayValueOnlyStyleClass="outputText"/>       
</h:column>

<!-- Date1 Column -->   
<h:column id="testResultsDate1Col">
    <f:facet name="header">
        <h:outputText id="ot04" styleClass="outputText" value="Date" />
    </f:facet>
    <h:panelGroup rendered="#{!elisaTestResults.valid1}">
        <h:inputText id="testResultsDate1__DT" styleClass="inputText"
            value="#{elisaTestResults.date1}"
            onchange="setDirty(this, 'T1')"
            size="7">
            <f:convertDateTime type="date" pattern="MM/dd/yyyy" />
        </h:inputText>
        <hx:graphicImageEx id="testResultsDate1__DTCal"
        styleClass="graphicImageEx" value="/shared/images/schedule.gif" />
        <h:message styleClass="error-message" for="testResultsDate1__DT" />
    </h:panelGroup>
    <h:outputText id="testResultsDate1" styleClass="outputText"
        value="#{elisaTestResults.date1}" rendered="#{elisaTestResults.valid1}">
        <f:convertDateTime type="date" pattern="MM/dd/yyyy" />
    </h:outputText>
</h:column>

<!-- Valid Result1 Column -->   
<h:column id="testResultsValid1Col">
    <f:facet name="header">
        <h:outputText id="ot05" styleClass="outputText" value="OK" />
    </f:facet>
    <h:selectBooleanCheckbox id="testResultsValid1"
        onchange="setDirty(this, 'T1')"
        styleClass="selectBooleanCheckbox" value="#{elisaTestResults.valid1}" />
</h:column>

<!-- Result2 Column --> 
<h:column id="testResultsResult2Col">
    <f:facet name="header">
        <h:outputText id="ot06" styleClass="outputText" value="Result2" />
    </f:facet>
    <t:inputText id="testResultsResult2" style="font-weight: bold"
        value="#{elisaTestResults.result2}" size="7" maxlength="15"
        onchange="setTestDate(this, 'T1')" 
        displayValueOnly="#{elisaTestResults.valid2 != null && elisaTestResults.valid2}" 
        displayValueOnlyStyleClass="outputText"/>       
</h:column>
于 2014-05-06T18:58:57.447 回答