How to Pass tag attribute value to Java Bean in JSP

Im trying to pass the string fro jsp page to .tag via attribute but the value isnot passing to the java bean in that tag file.

Following is the code in JSP File

<t:detailPane lang="English" ></t:detailPane>   

Tag File :

   <%@attribute name="lang" required="true"%>
    <jsp:useBean id="language" scope="page" class="com.AAA.Test.Language" ></jsp:useBean>
    <%=language.getWord("DepartureCaption",  "${lang}") %>

If i write “English” or “Urdu” or “French” instead of ${lang} it works fine but doesnt work when i use the attribute in the tag file to pass value to java bean.

Answer

Following is the java markup i have found to get attribute

jspContext.getAttribute("lang").toString(); 

It helped in my code as :

<%String lan = jspContext.getAttribute("lang").toString();  %>
<%=language.getWord("DepartureCaption",  lan) %>

Leave a Reply

Your email address will not be published. Required fields are marked *