1

我对 jsp 动态包含有疑问。换句话说,我有一个用于模板的主jsp,它包括另外两个jsp。包含的jsp包含SAP hbj taglibrary,主JSP是纯JSP(1.2)代码。

问题是包含的 JSP 在运行时不尊重呈现顺序,但它们呈现在页面顶部。我读了一些关于这个的帖子,但我没有找到解决方案。

请你帮帮我好吗?

谢谢

    // Primo CASO:
// Compiling Exception:
// •    No renderer context available (a htmlb tag without a rendererContext attribute must be nested within a RendererContext tag)


// masterPage.jsp
<%@ taglib uri="tagLib" prefix="hbj" %>
<jsp:useBean id="myBean" scope="session" class="include.test.bean.MyBean" />
<hbj:content id="myContext" >
  <hbj:page title="PageTitle">
   <hbj:form id="myFormId" >

        <div>
        <p>IncludedPage1 Start</p>
            <jsp:include page="includedPage1.jsp" />
        <p>IncludedPage1 End</p>

        <p>IncludedPage2 Start</p>
            <jsp:include page="includedPage2.jsp" />
        <p>IncludedPage2 End</p>

        <p>IncludedPage3 Start</p>
            <jsp:include page="includedPage3.jsp" />
        <p>IncludedPage3 End</p>

        </div>


        <div>
            <h3><%="MyBean: " + myBean.toString()%></h3>
        </div>

   </hbj:form>
  </hbj:page>
</hbj:content>

//includedPage1.jsp
<%@ taglib uri="tagLib" prefix="hbj" %>
<jsp:useBean id="myBean" scope="session" class="include.test.bean.MyBean" />

<div class="radioCheck_elementContainer">
    <hbj:radioButtonGroup id="fldUteRegistrato" columnCount="2" selection="<%=myBean.getRadioButtonValue()%>">  
        <%fldUteRegistrato.setOnClick("onClickRadio");%>
        <hbj:radioButton id="fldUteRegistratoSI" text="SI" key="SI" tooltip="Registrato" disabled="FALSE" />
        <hbj:radioButton id="fldUteRegistratoNO" text="NO, procedere alla registrazione sul sito Poste.it da parte del Cointestatario" key="NO" tooltip="Non Registrato" disabled="FALSE" />
        <hbj:radioButton id="fldUteRegistratoNULL" text="NULL VALUE" key="NULL" tooltip="NULL VALUE" disabled="FALSE" />
    </hbj:radioButtonGroup>             
</div>

//includedPage2.jsp
<%@ taglib uri="tagLib" prefix="hbj" %>
<jsp:useBean id="myBean" scope="session" class="include.test.bean.MyBean" />

<% String ifldId = ""; %>
<hbj:inputField id="fldInputFieldPage2" type="string" maxlength="16" value="">
    <% ifldId = myContext.getParamIdForComponent(fldInputFieldPage2); %>
</hbj:inputField>



<script type="text/javascript">
    alert("ID CAMPO:" + <%=ifldId%>)
</script>

//includedPage3.jsp
<%@ taglib uri="tagLib" prefix="hbj" %>
<jsp:useBean id="myBean" scope="session" class="include.test.bean.MyBean" />

<hbj:inputField id="fldInputField" type="string" maxlength="16" value="" />


<% String avanti="";%>
<hbj:button id="cmdAvanti" text="Avanti" width="127" onClick="onCmdAvanti" design="EMPHASIZED" encode="True">
<%
    avanti = myContext.getParamIdForComponent(cmdAvanti);
%>
</hbj:button>

<script type="text/javascript">
    alert("ID Pulsante:" + <%=avanti%>)
</script>

// Secondo CASO:

// Exception:
// •    Nessuna
// Comportamento:
// •    Solo I campi appartenenti al form da cui parte l’evento vengono inviati al server, la causa è la creazione di più form e quindi di conseguenza nell’HTTP request trovo solo i campi del form da cui è staqto effettuato il submit (Evento)

// masterPage.jsp
<%@ taglib uri="tagLib" prefix="hbj" %>
<jsp:useBean id="myBean" scope="session" class="include.test.bean.MyBean" />


        <div>
        <p>IncludedPage1 Start</p>
            <jsp:include page="includedPage1.jsp"  flush="true" />
        <p>IncludedPage1 End</p>

        <p>IncludedPage2 Start</p>
            <jsp:include page="includedPage2.jsp"  flush="true" />
        <p>IncludedPage2 End</p>

        <p>IncludedPage3 Start</p>
            <jsp:include page="includedPage3.jsp"  flush="true" />
        <p>IncludedPage3 End</p>

        </div>


        <div>
            <h3><%="MyBean: " + myBean.toString()%></h3>
        </div>




//includedPage1.jsp
<%@ taglib uri="tagLib" prefix="hbj" %>
<jsp:useBean id="myBean" scope="session" class="include.test.bean.MyBean" />

<hbj:content id="myContext1" >
  <hbj:page title="PageTitle1">
        <hbj:form id="myFormId" >
        <div class="radioCheck_elementContainer">
            <hbj:radioButtonGroup id="fldUteRegistrato" columnCount="2" selection="<%=myBean.getRadioButtonValue()%>">  
                <%fldUteRegistrato.setOnClick("onClickRadio");%>
                <hbj:radioButton id="fldUteRegistratoSI" text="SI" key="SI" tooltip="Registrato" disabled="FALSE" />
                <hbj:radioButton id="fldUteRegistratoNO" text="NO, procedere alla registrazione sul sito Poste.it da parte del Cointestatario" key="NO" tooltip="Non Registrato" disabled="FALSE" />
                <hbj:radioButton id="fldUteRegistratoNULL" text="NULL VALUE" key="NULL" tooltip="NULL VALUE" disabled="FALSE" />
            </hbj:radioButtonGroup>             
        </div>
        </hbj:form>
    </hbj:page>
</hbj:content>
includedPage2.jsp
<%@ taglib uri="tagLib" prefix="hbj" %>
<jsp:useBean id="myBean" scope="session" class="include.test.bean.MyBean" />

<hbj:content id="myContext2" >
  <hbj:page title="PageTitle2">
        <hbj:form id="myFormId" >
        <% String ifldId = ""; %>
        <hbj:inputField id="fldInputFieldPage2" type="string" maxlength="16" value="<%=myBean.getInputFieldValuePage2()%>">
            <% ifldId = myContext2.getParamIdForComponent(fldInputFieldPage2); %>
        </hbj:inputField>

        <script type="text/javascript">
            alert("ID CAMPO:" + <%=ifldId%>)
        </script>

        </hbj:form>
    </hbj:page>
</hbj:content>


//includedPage3.jsp
<%@ taglib uri="tagLib" prefix="hbj" %>
<jsp:useBean id="myBean" scope="session" class="include.test.bean.MyBean" />


<hbj:content id="myContext3" >
  <hbj:page title="PageTitle3">
        <hbj:form id="myFormId" >
            <hbj:inputField id="fldInputField" type="string" maxlength="16" value="<%=myBean.getInputFieldValue()%>" />

            <% String avanti="";%>
            <hbj:button id="cmdAvanti" text="Avanti" width="127" onClick="onCmdAvanti" design="EMPHASIZED" encode="True">
            <%
                avanti = myContext3.getParamIdForComponent(cmdAvanti);
            %>
            </hbj:button>

            <script type="text/javascript">
                alert("ID Pulsante:" + <%=avanti%>)
            </script>
        </hbj:form>
    </hbj:page>
</hbj:content>
<script type="text/javascript">
    alert("ID Pulsante:" + <%=avanti%>)
</script>

// Appendice:

// MasterPage.java
package include.test;

import include.test.bean.MyBean;
import com.sapportals.htmlb.*;
import com.sapportals.htmlb.enum.*;
import com.sapportals.htmlb.event.*;
import com.sapportals.htmlb.page.*;
import com.sapportals.portal.htmlb.page.*;
import com.sapportals.portal.prt.component.*;

public class MasterPage extends PageProcessorComponent {

    public DynPage getPage() {
        return new MasterPageDynPage();
    }

    public static class MasterPageDynPage extends JSPDynPage {

        private MyBean myBean = null;

        private void initBean() {
            IPortalComponentSession componentSession =
                ((IPortalComponentRequest) getRequest()).getComponentSession();
            Object o = componentSession.getValue("myBean");
            if (o == null || !(o instanceof MyBean)) {
                myBean = new MyBean();
                componentSession.putValue("myBean", myBean);
            } else {
                myBean = (MyBean) o;
            }

        }

        public void doInitialization() {
            IPortalComponentSession componentSession =
                ((IPortalComponentRequest) getRequest()).getComponentSession();
            Object o = componentSession.getValue("myBean");
            if (o == null || !(o instanceof MyBean)) {
                myBean = new MyBean();
                componentSession.putValue("myBean", myBean);

            } else {
                myBean = (MyBean) o;
            }
            myBean.setMethod("doInitialization");
        }

        public void doProcessAfterInput() throws PageException {
            initBean();
            InputField ifld = (InputField) getComponentByName("fldInputField");

            if(ifld!=null && ifld.getValue()!=null) {
                myBean.setInputFieldValue(ifld.getValue().toString());
            }
            else {
                myBean.setInputFieldValue("NULL VALUE");
            }


            RadioButtonGroup radioButtonGroup = (RadioButtonGroup) getComponentByName("fldUteRegistrato");

            if(radioButtonGroup!=null && radioButtonGroup.getSelection()!=null) {
                myBean.setRadioButtonValue(radioButtonGroup.getSelection());
            }
            else {
                myBean.setRadioButtonValue("NULL");
            }

            InputField ifld2 = (InputField) getComponentByName("fldInputFieldPage2");

            if(ifld2!=null && ifld2.getValue()!=null) {
                myBean.setInputFieldValuePage2(ifld2.getValue().toString());
            }
            else {
                myBean.setInputFieldValuePage2("NULL VALUE");
            }

            myBean.setMethod("doProcessAfterInput");
        }

        public void doProcessBeforeOutput() throws PageException {
            this.setJspName("masterPage.jsp");
        }

        public void onClickRadio(Event event) {
            initBean();
            myBean.setEvent("onClickRadio");
        }

        public void onCmdAvanti(Event event) {
            initBean();
            myBean.setEvent("onCmdAvanti");
        }
    }
}

//MyBean.java
package include.test.bean;


import java.io.Serializable;

public class MyBean implements Serializable {
    private String event = "";
    private String inputFieldValue = "";
    private String inputFieldValuePage2 = "";
    private String radioButtonValue= "";
    private String method = "";


    public String getEvent() {
        return event;
    }
    public void setEvent(String e) {
        event = e;
    }


    /**
     * @return
     */
    public String getInputFieldValue() {
        return inputFieldValue;
    }

    /**
     * @param string
     */
    public void setInputFieldValue(String string) {
        inputFieldValue = string;
    }

    /**
     * @return
     */
    public String getRadioButtonValue() {
        return radioButtonValue;
    }

    /**
     * @param string
     */
    public void setRadioButtonValue(String string) {
        radioButtonValue = string;
    }




    /**
     * @return
     */
    public String getInputFieldValuePage2() {
        return inputFieldValuePage2;
    }

    /**
     * @param string
     */
    public void setInputFieldValuePage2(String string) {
        inputFieldValuePage2 = string;
    }


    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return "MyBean [method=" + method + ", event=" 
+ event + ", inputFieldValue=" + inputFieldValue 
+ ", inputFieldValuePage2=" + inputFieldValuePage2
            + ", radioButtonValue=" + radioButtonValue + "]";
    }
    /**
     * @return
     */
    public String getMethod() {
        return method;
    }

    /**
     * @param string
     */
    public void setMethod(String string) {
        method = string;
    }

}
4

0 回答 0