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 867007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:54:15+00:00 2026-05-15T09:54:15+00:00

For a simple action class with these member variables: … private TestConverterEnum test; private

  • 0

For a simple action class with these member variables:

...
private TestConverterEnum test;
private TestConverterEnum[] tests;
private List<TestConverterEnum> tList;
...

And a simple enum:

public enum TestConverterEnum {
    A,
    B,
    C;
}

Using the default struts2 enum conversion, when I send the request like so:

TestConterter.action?test=&tests=&tList=&b=asdf

For test I get a null value, which is expected. For the Array and List, however, I get and Array (or list) with one null element. Is this what is expected? Is there a way to prevent this.

We recently upgraded our struts2 version, and we had our own converters, which also don’t work in this case, so I was hoping to use the default conversion method. We already have code that is validating these arrays for null and length, and I don’t want to have to add another condition to these branches. Is there a way to prevent this bevavior?

  • 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-15T09:54:16+00:00Added an answer on May 15, 2026 at 9:54 am

    Yes, it is expected behaviour IMO.

    Http parameters are in principle multivalued (typically used in multivalued select lists), hence the struts2 param interceptor asks (by reflection) for setters that accept arrays or (as a second option) a single value. Your action probably has a setTests(TestConverterEnum[] a) setter, so, when Struts2’s interceptor has to map tests= he founds that setter, and thinks to himself: “I must set this ‘tests’ property with an array, let’s see how many parameters were passed… only one (empty), then let’s create an array of length one and fill it with the convertion…” etc.

    I find it reasonable: your request included one ‘tests’ parameter (though empty), hence a one-sized array was created.

    I’d bet that if you try TestConterter.action?tests=&tests= an array of length 2 will be created.

    Updated:

    Let’s see if we agree in this : to pass an empty parameter in a request is (in principle) not the same as not passing it… though frequently one wants to treat both cases as equivalent.

    If you’d want to tell Struts2: “ignore completely the empty parameters”… I don’t think (supposing it is an acceptable idea) this behaviour can be enforced by some global setting.
    You could always write your own interceptor (or extend the Parameters interceptor) so that it cleans out the empty parameters from the request before mapping them.

    BTW, note that this issue is unrelated to Enums or to Arrays, is totally general.

    Now, the case of multivalued parameters requires extra consideration. I assume that if your Action has a public property of type array, it’s because it can be set with several parameters, (a SELECT MULTIPLE typically) – if not, there is some design problem here.
    Now, what would be your expected behaviour for this request?

    TestConterter.action?tests=&tests=A&tests=&tests=B&tests=B
    

    Should this generate an array of length 5 [null, A, null, B, B] or 3 [A, B, B] or 2 [A, B] or what?
    It’s difficult to give general criteria; that’s why this is better dealt with in your setter method, in general.

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

Sidebar

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.