在 jsp:include 中传递 EL 表达式或托管 bean 实例

发布于 2024-09-11 01:00:06 字数 788 浏览 2 评论 0原文

我有一个通用按钮 jsp:

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

<wow:button id="deleteButton" iconClass="iconCancel"
            action="#{managedbean.delete}" type="submit"
            value="#{lblMsg.label_delete }" />

这通过以下方式包含在另一个 jsp 页面中。

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

此页面有一个由 EL 表达式使用的托管 bean 实例。我想将 locationBean 的这个实例传递给buttons.jsp。一种方法是在 jsp:include 中将参数值设置为 bean 名称,并在 Buttons.jsp 中使用 requestScope[beanName]。

有更好的办法吗?

编辑:wow 是我们自己的 JSF 组件库。

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" iconClass="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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽容 2024-09-18 01:00:06

使用遗留的 JSP,我认为在语义上没有更好的方法。然而,如果您更改 bean 的范围,您的方法可能会失败。另一种方法可能是使用 JSTL c:set 代替。

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

但这

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

可能会与另一个巧合的同名豆发生冲突。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文