Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6375633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:38:28+00:00 2026-05-25T01:38:28+00:00

Im trying to create my own custom tag so i can display or hide

  • 0

Im trying to create my own custom tag so i can display or hide the content between the tag depending on an attribute set.

<mytag:isUserInRole role="admin">Show admin specific text</mytag:isUserInRole>`

Basicly i want to show the text between the tags if the logged in user has role==admin.
I thought it would be easy, but so far i’ve had no luck. If i in my tld-file set <body-content>empty</body-content> I get this exception:

“According to TLD, tag auth:isUserInRole must be empty, but is not”

If i set <body-content /> i get this one:

Unable to compile class for JSP – Caused by: java.lang.NullPointerException
at org.apache.jasper.compiler.Parser.parseBody(Parser.java:1857)

Can anyone see what im doing wrong?

Her is my tld-files relevant tag:

    <tag>
    <name>isUserInRole</name>
    <tag-class>no.mycompany.tag.AuthorizationTag</tag-class>
    <body-content />
    <attribute>
        <name>role</name>
        <required>true</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>
</tag>

And here is my AuthorizationTag doStartTag-method:

    public int doStartTag() throws JspException{
    System.out.println("Role"+role);

    //Check that role is given and securitycontext is not null
    if(role==null|| SecurityContextHolder.getContext()==null || SecurityContextHolder.getContext().getAuthentication()==null){
        return Tag.SKIP_BODY;
    }
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();

    if(hasPermission(auth)){
        return Tag.EVAL_BODY_INCLUDE;
    } else {
        return Tag.SKIP_BODY;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:38:29+00:00Added an answer on May 25, 2026 at 1:38 am

    Try this: <bodycontent>jsp</bodycontent>, also note the difference between <body-content> and <bodycontent>

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to create my own custom AttachedProperty for a WPF DependencyObject failed to actually
I've been trying to create my own custom LiveValidation ( LiveValidation.com ) function that
I have my own custom Authorize Attribute and I am trying to check my
I'm trying to create a set of custom file templates for IntelliJ. I basically
I´am trying to create my own custom list component in a Flex mobile Project
I'm trying to create my own Custom Delegates in iOS 5 . In iOS
I've been trying to create my own custom scroll bar implementation in JavaScript. It
I'm trying to create my own error window for the project I am working
I am trying to create my own torrent tracker but dont know how to
I'm trying to create my own plugin. But I'm having trouble getting things right.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.