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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:42:56+00:00 2026-05-19T11:42:56+00:00

is it possible to do something like criteria.add(Expression.eq(product, * )) for it to match

  • 0

is it possible to do something like

criteria.add(Expression.eq("product", " * "))  

for it to match everything ?

It would be handy in case that you get a variable that can have many values and a special value “all” that matches against everything. So you can call a method like this and if the variable had a value of “all”, then the expression would match everything.

public void someFunction(String variable) {

    criteria.add(Expression.eq("product", variable))  

}

EDITED: If I had 2 select fields with Source Language & Destination Language and a table listing entries based on which language combination it contains, with IF STATEMENTS it would look like this: (DynamicQuery is an abstraction for Criteria)

private DynamicQuery addCriteria(DynamicQuery dq, String languageFrom, String languageTo){

    if (null != languageFrom && !languageFrom.isEmpty() && null != languageTo && !languageTo.isEmpty()){

        if(languageFrom.equals("All") && languageTo.equals("All")) {
            return dq;
        } else if (!languageFrom.equals("All") && !languageTo.equals("All")) {
            dq.add(PropertyFactoryUtil.forName("languageFrom").eq(languageFrom));
            dq.add(PropertyFactoryUtil.forName("languageTo").eq(languageTo));    
            return dq;
        } else if (languageFrom.equals("All") && !languageTo.equals("All")) {
            dq.add(PropertyFactoryUtil.forName("languageTo").eq(languageTo));   
            return dq;
        } else if (!languageFrom.equals("All") && languageTo.equals("All")) {
            dq.add(PropertyFactoryUtil.forName("languageFrom").eq(languageFrom)); 
            return dq;
        } 
    } 
}

It’s disgusting, consider there would be one more field, it would be even more disgusting…One simply must cover all the combinations that might occur … That’s why I would like to have something like REGEX, because I would assign variable the reqex “*” value and I would add two lines like this

dq.add(PropertyFactoryUtil.forName("languageFrom").eq(languageFromVariable));
dq.add(PropertyFactoryUtil.forName("languageTo").eq(languageToVariable));   
  • 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-19T11:42:57+00:00Added an answer on May 19, 2026 at 11:42 am
    if (null != variable && !variable.isEmpty()){
        criteria.add(Expression.eq("product", variable)) ;
    }
    

    If you only need it when it is selected. You may wanna add an if statement so criteria is added only when needed.

    Edit 1:

    You can define a method if you are gonna use it for more than fields. Even you can define different criterias inside here. Easy maintance (as is used by all and centrilized), code reuse (change at one point at it will be effective to all)

    addCriteria(Criteria criteria, String name, String value){
    
     //you wanna handle special cases like null == name as well accordingly
    
        if (null != value && !value.isEmpty() && null != name && !name.isEmpty()){
            criteria.add(Expression.eq(name, value)) ;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to do something like this? var pattern = /some regex segment/
Is it possible to have something like a JTextArea which will color some keywords
Is it possible to do something like (?'A-B'\s*) ?
Is it possible to do something like this: <% Dim foo as string =
is it possible to create something like this i ASP.NET MVC beta 1 i
is it possible to do something like the following in ASP.NET: <tr<%= index++ %
Is it possible to do something like this? public function something() { $thisMethodName =
Is it possible to have something like Data Grid or Grid View control in
is it possible to do something like this in JSTL: <div class=firstclass<c:if test='true'> someclass</c:if>>
Is it possible to accomplish something like this using linqtosql? select * from table

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.