Come faccio a passare un oggetto con ambito di pagina a un tag JSP personalizzato usando Struts 2?

StackOverflow https://stackoverflow.com/questions/8415470

Domanda

Sto usando Struts 2 e devo passare una variabile con ambito di pagina a un tag JSP personalizzato.

Se uso la sintassi OGNL %{#option} Ricevo il seguente errore:

org.apache.jasper.JasperException: PWC6338: Cannot convert "%{#option}" for the attribute option of the bean com.leaseplanis.iq.model.bo.options.OptionDetail

Dove come se usassi la sintassi El ${option} I L'oggetto è null.

Il mio tag personalizzato si trova su */web-inf/tags/option_price_textfield.tag * nella mia applicazione Web:

<%@ 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)}" />

Il tag personalizzato viene utilizzato nella seguente pagina 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="&nbsp;" escape="false" value="#option.optionCur"/>
        </td>
    </s:if>
    .
    .
</s:iterator>
È stato utile?

Soluzione

OGNL consente l'accesso ad attributi con ambito come option attraverso #attr. Cambiare il option accede per usarlo e dovresti essere tutto impostato:

<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)}" />
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top