开发者

Passing EL expressions or managed bean instance in jsp:include

开发者 https://www.devze.com 2023-01-08 20:37 出处:网络
I have a generic buttons jsp: <wow:button id=\"addButton\" iconClass=\"add16 icon16x16\" action=\"#{managedbean.addNew}\" type=\"submit\" immediate=\"true\"

I have a generic buttons jsp:

<wow:button id="addButton" iconClass="add16 icon16x16"
            action="#{managedbean.addNew}" type="submit" immediate="true"
            value="#{lblMsg.label_add }" />

<wow:button id="deleteButton" ic开发者_运维问答onClass="iconCancel"
            action="#{managedbean.delete}" type="submit"
            value="#{lblMsg.label_delete }" />

This gets included in another jsp page via

<wow:outputText value="#{locationBean.disclaimer}"></wow:outputText> <br />
<jsp:include page="buttons.jsp">

This page has a managed bean instance used by the EL expression. I want to pass this instance of locationBean to buttons.jsp. One way is setting a param value in jsp:include to the bean name and using requestScope[beanName] in buttons.jsp.

Is there a better way?

Edit: wow is our own JSF component library.


Using the legacy JSP, I don't think there are semantically better ways. Your approach might however break if you change the scope of the bean. Another way may be to use JSTL c:set instead.

<c:set var="currentBean" value="#{locationBean}" scope="request" />
<jsp:include page="buttons.jsp" />

with

<h:commandButton action="#{currentBean.action}" />

But this might clash with another beans which have by coincidence the same name.

0

精彩评论

暂无评论...
验证码 换一张
取 消