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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:05:18+00:00 2026-06-04T22:05:18+00:00

What is the appropriate way to call selectAll Java method when from bean when

  • 0

What is the appropriate way to call selectAll Java method when from bean when I click on a checkbox?

<f:facet name="header">
      <h:selectBooleanCheckbox  binding="#{bean.selectAll}" onclick="highlight(this)" class="checkall"/>
</f:facet>

binding is not working. I just want to execute the code in this Java method.

EDIT

private HashMap<String, Boolean> selected = new HashMap<>();
public void selectAll() throws Exception {

        String SqlStatement = null;

        if (ds == null) {
            throw new SQLException();
        }

        Connection conn = ds.getConnection();
        if (conn == null) {
            throw new SQLException();
        }

        SqlStatement = "SELECT ID FROM ACTIVESESSIONSLOG";

        PreparedStatement ps = null;
        ResultSet resultSet = null;
        int count = 0;

        try {
            conn.setAutoCommit(false);
            boolean committed = false;
            try {
                ps = conn.prepareStatement(SqlStatement);
                resultSet = ps.executeQuery();
                selected.clear();

                while (resultSet.next()) {

                    selected.put(resultSet.getString("ID"), true);
                }
/*
                for (Map.Entry<String, Boolean> entry : selectedIds.entrySet()) {
                    entry.setValue(true);
                }

*/                conn.commit();
                committed = true;
            } finally {
                if (!committed) {
                    conn.rollback();
                }
            }
        } finally {
            ps.close();
            conn.close();
        }
    }
  • 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-04T22:05:20+00:00Added an answer on June 4, 2026 at 10:05 pm

    Use <f:ajax> to send an ajax request.

    <h:selectBooleanCheckbox value="#{bean.selectAll}" onclick="highlight(this)" class="checkall">
        <f:ajax listener="#{bean.onSelectAll}" render="@form" />
    </h:selectBooleanCheckbox>
    

    with

    private boolean selectAll;
    
    public void onSelectAll(AjaxBehaviorEvent event) {
        // If you're using a boolean property on the row object.
        for (Item item : list) {
            item.setSelected(selectAll);
        }
    
        // Or if you're using a Map<Long, Boolean> on item IDs
        for (Entry<Long, Boolean> entry : selected.entrySet()) {
            entry.setValue(selectAll);
        }
    }
    
    public boolean isSelectAll() {
        return selectAll;
    }
    
    public void setSelectAll(boolean selectAll) {
        this.selectAll = selectAll;
    }
    

    Ideally the bean should be placed in the view scope by @ViewScoped to keep it alive across the ajax requests on the same view.

    Don’t use binding to a bean property unless you have a very good reason. It’s intented to bind the whole UIComponent to the bean which allows dynamic component manipulation, but more than often there are simpler and less obtrusive ways.

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

Sidebar

Related Questions

What is the appropriate way to call a method with an action, and what
In a controller, what is the most appropriate way to call the action of
To repeat a method call (or message send, I guess the appropriate term is)
Is it possible to call a COM API from Java (specifically the HP/Mercury Quality
What is the most appropriate way of getting the mouse cursor position or button
What is the appropriate way to flip an ExtJs Panel horizontally for RTL languages,
I'm looking for the appropriate way of storing files into the document folder within
I am looking for an appropriate way to store and access pdf files in
I'm not sure whether or not this is the appropriate way of doing this,
After searching, I dont find the appropriate way to resolve following problem. After activating

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.