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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:30:11+00:00 2026-06-18T06:30:11+00:00

How can I create toggle buttons in JSF? Basically, I need two buttons in

  • 0

How can I create toggle buttons in JSF?

Basically, I need two buttons “in” and “out”. They essentially call the same managed bean, but as a result of every click the one should be disabled and the other should be enabled and vice versa. How can this be done? Should I use ajax functionality?

  • 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-18T06:30:12+00:00Added an answer on June 18, 2026 at 6:30 am

    Just have a boolean property which you inverse in action method and use exactly that property in the disabled attribute of the both buttons, inversed.

    Kickoff example:

    @ManagedBean
    @ViewScoped
    public class Bean {
    
        private boolean enabled;
    
        public void toggle() {
            enabled = !enabled;
        }
    
        public boolean isEnabled() {
            return enabled;
        }
    
    }
    

    With

    <h:form>
        <h:commandButton value="Enable" action="#{bean.toggle}" disabled="#{bean.enabled}" />
        <h:commandButton value="Disable" action="#{bean.toggle}" disabled="#{not bean.enabled}" />
    </h:form>
    

    Ajax is technically not necessary. Feel free to add <f:ajax> to both buttons to improve the user experience though.

    A @ViewScoped bean is in turn very necessary. A @RequestScoped one would be trashed on end of request and recreated in next request, hereby causing the boolean to be reinitialized to default and thus seemingly fail to work after second click, because JSF will as part of safeguard against tampered/hacked requests also check the disabled (and rendered) attribute before actually invoking the action.

    See also:

    • How to choose the right bean scope?
    • commandButton/commandLink/ajax action/listener method not invoked or input value not updated (point 5)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody suggest me how to create toggle buttons in UIWebView Keyboard's toolbar very
Is there a way to create two toggle buttons in a Matlab GUI such
So I wanted to create a toggle-button for a table, where I can make
I can create and use dynamic two dimensional array in Fortran (in 77 standard).
I can create an array of buttons in Windows Form but how can i
I'm using the following to create a toggle switch instead of radio buttons -
How can I create in a Swing interface a toggle image button? I have
In my project I need to create some play,pause,stop buttons in one composite. For
Possible Duplicate: How can I create a toggle button similar to the Twitter apps
I am attempting to create a checkbox in each uitableviewcell that can toggle between

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.