Results 1 to 6 of 6

Thread: Use of <portlet:namespace> with Spring Form tag library

  1. #1
    Join Date
    Nov 2007
    Posts
    14

    Default Use of <portlet:namespace> with Spring Form tag library

    We are developing a portlet using the Spring Portlet MVC.

    Within our JSPs, we are trying to use the <portlet:namespace> tag to ensure that IDs are unique to a specific instance of the portlet. However, if we try to use the <portlet:namespace> tag within a Spring Form tag, the <portlet:namespace> tag is not recognised and is treated as text. The <portlet:namespace> tag works fine with 'ordinary' html tags

    e.g. for an ordinary html input field, the following JSP code will generate an input element with the id prefixed with the portlet namespace (such as "specificnamespacefield1")

    <input id="<portlet:namespace/>field1">

    For a Spring form input field, the following JSP code does not recognise that the portlet namespace and will generate an input element with an id of "<portlet:namespace/>field1"

    <form:input id="<portlet:namespace/>field1">

    Does anyone know how to prefix a Spring form tag id with a portlet namespace?

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    You cannot. The id/name/path property only allow textual input not nesting of other tags. Which is what you experience... You can use ${somevalue} however I'm not familiar with the portlet namespace but if you could declare a parameter which holds the result of <portlet:namespace/> you could use that notation.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Nov 2007
    Posts
    14

    Default

    Thanks. We got around it with this.

    <c:set var="portletnamespace" value="<%= renderResponse.getNamespace() %>"/>
    <form:input id="${portletnamespace}field1">

  4. #4
    Join Date
    Sep 2004
    Location
    Arizona, USA
    Posts
    383

    Default

    Two other options:

    You should be able to use this:
    <c:set var="ns"><portlet:namespace /></c:set>

    Although IBM had some buggy versions of the taglib floating around that had a bug flush call in them that made this blow up, so test it first.

    Make the call to renderResponse.getNamespace() in your Controller and pass the namespace in as part of the Model. (If you are using SimpleFormController, include it as "referenceData")

  5. #5
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    Quote Originally Posted by Paulieb12 View Post
    for an ordinary html input field, the following JSP code will generate an input element with the id prefixed with the portlet namespace (such as "specificnamespacefield1")

    <input id="<portlet:namespace/>field1">

    For a Spring form input field, the following JSP code does not recognise that the portlet namespace and will generate an input element with an id of "<portlet:namespace/>field1"

    <form:input id="<portlet:namespace/>field1">
    The difference between these both is that the first is not an ordinary html tag, it's actually no tag at all in the JSP sense. It's just a bunch of characters including a <.

    The second example is indeed a tag, there is a tag handler for form:input.

    Furthermore I think it is not possible to nest tags in JSPs at all. But somebody might correct me on this.

    Joerg
    This post can contain insufficient information.

  6. #6
    Join Date
    Feb 2013
    Posts
    1

    Default

    I'm developing a web application (no portlet), my application have to print some controls html with the same ID, for example:

    <div id="myID" />
    <div id="myID" />

    Can I implement something like : <div id="<portlet:namespace/>myID" /> ??

    And How Could I get that value with JQuery/javascript?

Posting Permissions

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