I have such custom JSP tag file:

/WEB-INF/tags/formField.tag
--------------------------------------------------------------
<%@ taglib prefix="s" uri="/struts-tags" %>

<%@ tag language="java" pageEncoding="UTF-8" %>

<%@ attribute name="fieldName" %>
<%@ attribute name="inputId" %>
<%@ attribute name="label" %>
<%@ attribute name="labelKey" %>
<%@ attribute name="required" %>

<s:set var="inputId" value="%{#attr.inputId != null ? #attr.inputId :
(#attr.fieldName != null ? #attr.fieldName : '')}"/>
<s:set var="label" value="%{#attr.labelKey != null ? getText(#attr.labelKey)
: (#attr.label != null ? #attr.label : '')}"/>
<s:set var="fieldErrors" value="%{fieldErrors[#attr.fieldName]}"/>
<s:set var="hasFieldErrors" value="%{#fieldErrors != null &&
#fieldErrors.size > 0}"/>

<div class="wwgrp <s:property value="%{#hasFieldErrors ? 'HasFieldErrors' :
''}"/>">
        <table class="HiddenTable">
                <tr>
                        <td class="wwlbl">
                                <s:if test="%{!isBlank(#label)}">
                                        <label class="label" for="<s:property 
value="%{#inputId}"/>">
                                                <s:if 
test="%{#attr.required}">*</s:if>
                                                <s:property value="%{#label}" 
escape="false"/>:</label>
                                </s:if>
                        </td>
                        <td class="wwctrl">
                                <jsp:doBody/>
                                <s:if test="%{#hasFieldErrors}">
                                        <ul class="wwerr">
                                                <s:iterator var="error" 
value="%{#fieldErrors}">
                                                        <li 
class="errorMessage">
                                                                <s:property 
value="%{#error}" escape="false"/></li>
                                                </s:iterator>
                                        </ul>
                                </s:if>
                         </td>
                 </tr>
        </table>
</div>
--------------------------------------------------------------

And here is the part of my "login.jsp" that uses this custom tag:
--------------------------------------------------------------
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>
...
<s:form action="login">
        ...
        <t:formField fieldName="password" required="true"
labelKey="msgkey.label.password">
                <input type="password" id="password" name="password"/>
                TODO: Forgot your password?
        </t:formField>
        ...
</s:form>
--------------------------------------------------------------

Suppose action has a property 'fieldName' and I need to get value of a tag
attribute w/ the same name. I get tag atribute using <s:property
value="%{#attr.fieldName}"/>. The issue here is: if jsp page that uses this
custom tag does not provide value for 'fieldName' attribute, then
<s:property value="%{#attr.fieldName}"/> will return value of action
property 'fieldName'.

I did not found where jsp tag stored its attribute, but it seemed like in
PageContext. 
I tried to get PageContext, but ActionContext returns 'null'. Here is my
Java code:

        PageContext pageContext = ServletActionContext.getPageContext();
        if (pageContext != null)
        {
                log.debug("pageContext.findAttribute('fieldName'): " +
                        pageContext.findAttribute("fieldName"));
        }


Musachy Barroso wrote:
> 
> I am not sure I understand what you mean. Is "someTagAttribute" set in
> the context by your custom tag?
> 
> musachy
> 
> On Mon, Oct 12, 2009 at 2:57 PM, Alex Siman <aleksandr.si...@gmail.com>
> wrote:
>>
>> I have created JSP file tag as it is described here
>> http://java.sun.com/javaee/5/docs/tutorial/doc/bnama.html
>>
>> To get value of tag attribute 'someTagAttribute' I use this code:
>> <s:property value="%{#attr.someTagAttribute}"/>
>>
>> OGNL context works fine within this file tag. But I realized that if
>> there
>> will be an action property with the same name 'someTagAttribute' and
>> value
>> for tag attribute will not be set, then the above code will return value
>> of
>> action property as if it is the value of tag attribute.
>>
>> How to get value of tag attribute directly from OGNL?
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-get-value-of-tag-attribute-from-OGNL--tp25862967p25862967.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>> For additional commands, e-mail: user-h...@struts.apache.org
>>
>>
> 
> 
> 
> -- 
> "Hey you! Would you help me to carry the stone?" Pink Floyd
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-get-value-of-tag-attribute-from-OGNL--tp25862967p25871222.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to