Results 1 to 2 of 2
  1. #1
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Posts
    114
    Rep Power
    0

    Default Problem with Attribute in JSP

    Hi, I'm trying to wrap an existing tag with a *.tag file that i created.
    I'm getting all the attributes in but i don't want to pass them all to the tag.
    let's say the tag name is <foo:bar />
    Then i want to put attributes dynamically .
    I cannot put a <c:if> inside the tag since it's should be evaluated in server side and then run in server side.
    Java Code:
    <foo:bar>
    <c:if test="${! empty someAttr}">
    <jsp:attribute name="someAttr">${someAttr}</jsp:attribute>
    </c:if>
    </foo:bar>
    Can i do it at all ?
    Thanks
    Albert:rolleyes:

  2. #2
    susan is offline Member
    Join Date
    Jul 2007
    Posts
    44
    Rep Power
    0

    Default

    Could PageContext and the setAttribute() and getAttribute() methods be what you are looking for?
    If I understand what you want, something like the following could work:

    In the jsp-file:
    Java Code:
    SomeObject theObject = new SomeObject("Stuff");
    pageContext.setAttribute("ObjectByItsName/Key", theObject);
    And in your tag-file(s), you get access to that object by doing something like this:
    Java Code:
    PageContext pageContext;
    pageContext = (PageContext) getJspContext();
    
    SomeObject myObject = (SomeObject) pageContext.getAttribute("ObjectByItsName/Key");
    
    if (myObject != null) {
    	// do stuff with the object...
    }

Similar Threads

  1. how to add an attribute with sax?
    By cecily in forum New To Java
    Replies: 3
    Last Post: 07-19-2007, 04:09 AM
  2. Request attribute PageBean = null
    By Nick15 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 05-17-2007, 03:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •