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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:12:14+00:00 2026-05-29T08:12:14+00:00

For testing purposes, I harded coded a bean array so I can pass variables

  • 0

For testing purposes, I harded coded a bean array so I can pass variables to the database. I’m now pulling the variables from a form and want to set them in the bean array if they are not null. I assume my syntax is wrong.

Hardcode:

CriteriaBean[] filters = new CriteriaBean[]
{
    new CriteriaBean("YEAR","=","2012"),
    new CriteriaBean("LOCATION","in","('XXX','YYY')"),
    new CriteriaBean("TOM","is","not null") 
};

I was trying to do something like this and got the error:

 CriteriaBean[] filters = new CriteriaBean[]
           {
            if (form.getYear() != null) 
            {   
            new CriteriaBean("YEAR","=","2012")
            }


           };

CriteriaBean

public class CriteriaBean
    {
public static final CriteriaBean[] EMPTY_ARRAY = new CriteriaBean[0];

private String fieldName;
private String value;
private String operation;

public CriteriaBean() { } 
public CriteriaBean( String field, 
                              String op, 
                              String val ) 
{
   this.fieldName = field; 
   this.operation = op;
   this.value = val;
}



public String getName() { return this.name; }
public String getOp() { return this.op; }
public String getVal() { return this.val; }

public void setName(String val) { this.name = val; }
public void setOp(String val) { this.op = val; }
public void setVal(String val) { this.val = val; }

Is there a better way to do this??

  • 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-29T08:12:15+00:00Added an answer on May 29, 2026 at 8:12 am

    Close! Try this:

    CriteriaBean[] filters = form.getWySelect() == null
        ? new CriteriaBean[] {}
        : new CriteriaBean[] {
            new CriteriaBean("WORKLOAD_YEAR","=","2012")
          };
    

    This code uses the ternary syntax to use alternate initializers depending on the condition.

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

Sidebar

Related Questions

I'm running an application from inside another one for testing purposes. I want to
For testing purposes I want send mail to my localhost user account rather than
I'm adding some attributes from live to staging for testing purposes, I'm using ldifde:
How do I deploy my app down to the iPhone (for testing purposes) from
For testing purposes, I want to be able to create cookies as I need
I would like to create an in-memory database for testing purposes using Derby/JavaDB. I
I wanted to add my colleague's information in my database for testing purposes. Since
For testing purposes, I want to install two different instances of firefox on ubuntu
For testing purposes I want to update a table by setting bits in colums
For testing purposes, I set this in my htacces: order deny, allow deny from

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.