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

  • SEARCH
  • Home
  • 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 8602519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:06:19+00:00 2026-06-12T02:06:19+00:00

I want to check if a specific item is selected in a drop-down menu.

  • 0

I want to check if a specific item is selected in a drop-down menu. Suppose I have something like this in my JSP:

<sf:select path="xItem" >
    <sf:option value="val1" />
    <sf:option value="val2" />
</sf:select>

and in my corresponding java bean, I want to check it as

if (xItem.equals("val1")) xItem = doSomething();

but, if I define “val1” as a constant, i.e., final static String mytext="val1", and change my jsp file as <sf:option value="${MyClass.mytext}" />, Spring will complain that mytext is not a property of MyClass.
Is there anyway to define this text as a constant and refer to it in JSP and the corresponding Java class?

  • 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-06-12T02:06:21+00:00Added an answer on June 12, 2026 at 2:06 am

    The ${MyClass.mytext} expression applies to beans and properties, specifically it means that the server is expecting to find a bean saved in the current context as MyClass and on that bean to call a getter called getMyText (it’s a jspContext.FindAttribute) which isn’t the case here since you have a static member on a class.

    Here are some workarounds off the top of my head:

    • use a scriptlet and refer to the static member (if you can live with having scriptlets inside your JSPs);
    • save the value in your controller under some key inside your model and refer it in your JSP by that key;
    • define a custom tag that given a class name and static member invokes it and places it under some key in page scope and you can use if from there (see an example in this article: Scriptless JSP Pages: The Constant Constants Consternation);
    • define an EL function that returns the value of the constant (see an example in the same article Scriptless JSP Pages: The Constant Constants Consternation, scroll to the end of it).

    I would personally go with defining an EL function if you refer to constants often in your JSPs or set it under some model key in the controller if it’s a one time only use.

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

Sidebar

Related Questions

How do I check if an item is selected in a TreeView? I want
I have a MySql table. I want to check its specific field in all
I want to check if a specific apk is present in system app folder.
I want to check if a file contains a specific string or not in
So I want to check if the user is in specific county $ip =
I don't want check if an item with a value exists in the arraylist,
I want to check checkbox like $('#riderCheck').attr('checked','true') on some condition. but the problem is
I have a List<string> that has some items like this: {"Pre Mdd LH", "Post
I am implementing a simple drop-down using hiccup: ;DATASET/CREATE (defn get-cols-nms [table] This function
i want to check how much element have class goo. are i can check

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.