![](/img/trans.png)
[英]How can I put a bean object to sessionMap, and then retrieve its properties on jsp page using Struts 2 property tag
[英]How do I pass a page scoped object to a custom JSP tag using Struts 2?
我正在使用Struts 2,並且需要將頁面范圍的變量傳遞給自定義JSP標記。
如果我使用OGNL語法%{#option}
則會出現以下錯誤:
org.apache.jasper.JasperException: PWC6338: Cannot convert "%{#option}" for the attribute option of the bean com.leaseplanis.iq.model.bo.options.OptionDetail
好像我使用EL語法${option}
,該對象為null
。
我的自定義標簽位於Web應用程序中的* / WEB-INF / tags / option_price_textfield.tag *:
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ tag body-content="empty"%>
<%@ attribute name="option" type="com.leaseplanis.iq.model.bo.options.OptionDetail" required="true" rtexprvalue="true"%>
<s:textfield
id="%{optionId(#option, 'price')}"
name="%{optionField(#option, 'price')}"
value="%{optionGrossPrice(#option).getString()}"
cssClass="input price"
size="8"
maxlength="11"
onchange="%{optionPriceUpdate(#option)}" />
在以下JSP頁面中使用了定制標記:
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib prefix="iq" tagdir="/WEB-INF/tags"%>
.
.
<s:iterator var="option" value="variousOptionList">
.
.
<s:if test="viewConfigService.displayPriceColumn()">
<td class="price">
<s:if test="isPriceEditable(#option)">
<iq:option_price_textfield option="%{#option}"/>
</s:if>
<s:else>
<s:property value="optionGrossPrice(#option).getString()"/>
</s:else>
<s:property default=" " escape="false" value="#option.optionCur"/>
</td>
</s:if>
.
.
</s:iterator>
OGNL允許通過#attr
訪問范圍屬性,例如option
。 更改option
訪問權限以使用它,並且您應該都已設置好:
<s:textfield
id="%{optionId(#attr.option, 'price')}"
name="%{optionField(#attr.option, 'price')}"
value="%{optionGrossPrice(#attr.option).getString()}"
cssClass="input price"
size="8"
maxlength="11"
onchange="%{optionPriceUpdate(#attr.option)}" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.