Deactivate checkbox based on dropdown selection

I'm facing an issue where I need to disable a checkbox when a certain option is selected from a dropdown inside a datatable in my xhtml file. The dropdown has options like L, C, UV, and more, and when "L" is chosen, the checkbox should be disabled.

Below is a snippet of the relevant xhtml code for the dropdown and checkbox:

<r2i4:selectForClass itemClass="VehicleGenericType" value="#{vc.vehicleGenericType}" rendered="#{vc.crudState == null || vc.crudState == 'CREATE'}"
    valueChangedListener="#{vehicleCategory.vehicleDropdownChange">
    <f:selectItems value="#{vehicleCategory.vehicleChanged}" />
    <p:ajax />
</r2i4:selectForClass>

<f:facet name="input">
    <p:selectBooleanCheckbox id="departmental" value="#{vc.isDepartmental}" rendered="#{vc.crudState == null || vc.crudState == 'CREATE'}" 
    disabled="#{vehicleCategory.vehicleChanged eq 'L'}"/>
</f:facet>

In the bean file, the following code is used:

public void vehicleDropdownChange(ValueChangeEvent e) {
        if(e.getNewValue().equals("L")) {
        }
}

Seeking suggestions on how to make this functionality work effectively. Any help is appreciated!

Thank you

Answer №1

Give this code a try:

<r2i4:selectForClass itemClass="VehicleGenericType" value="#{vc.vehicleGenericType}" rendered="#{vc.crudState == null || vc.crudState == 'CREATE'}">
    <f:selectItems value="#{vehicleCategory.vehicleChanged}" />
    <p:ajax event="change" update="departmental" listener="#{vehicleCategory.vehicleDropdownChange} />
</r2i4:selectForClass>

<f:facet name="input">
    <p:selectBooleanCheckbox id="departmental" value="#{vc.isDepartmental}" rendered="#{vc.crudState == null || vc.crudState == 'CREATE'}" 
    disabled="#{vehicleCategory.disable}"/>
</f:facet>


public void vehicleDropdownChange(ValueChangeEvent e) {
        if ( .. ) { disable = true }
}

This should function properly here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Preventing AngularJS from Binding in Rows: A Solution

Currently, I am utilizing AngularJS version 1.5.3 and I am facing an issue with my services. I have two services - one that retrieves Area names and the other that fetches details for each Area. In my code, I first call the service to get the Area names an ...

The error message "THREE is not defined" indicates a problem

Hey there! I've been experimenting with running some three.js examples on my local machine. I ran into some security issues, so I set up a local server using Python. While the background image and text appear as expected, the animations are not workin ...

Eliminating the loaded jQuery AJAX component

I was attempting to create a dialog using AJAX to load content, but I'm struggling to remove it once created. It was essential for the dialog to be multipurpose, PHP-compatible, draggable, and closable. (.center() function enabled) $('a.event& ...

Choosing a value from a dropdown automatically based on the selection of a specific value from another dropdown

Currently, I am working on a project that involves selecting a value from a dropdown menu based on the selection from another dropdown menu. var gender1 = document.querySelector("#gender1"); var gender2 = document.querySelector("#gender2"); gender1.add ...

transferring information from the controller to the model

On my website, I have a piece of code that sends data to Ajax and performs well when adding items to the cart. public function addToCart() { $lapId = $this->input->post('id_lap'); $numItems = $this- ...

Use Django, Ajax, and Jquery to incrementally add items to a "cart" by selecting checkboxes one by one

Despite adding new code, it's still not working as expected... I've been attempting to implement a feature where users can select items using checkboxes and add them to the "cart" displayed at the top of the page. Each item on the page has a che ...

Submitting Multi-part forms using JQuery/Ajax and Spring Rest API

Recently, I started exploring JQuery and decided to experiment with asynchronous multipart form uploading. The form includes various data fields along with a file type. On the server side (using Spring), I have set up the code as follows: @RequestMapping ...

When a webpage reload triggers a 404 error, my website's iframe with the source "videoUrl | sanitize" will display

I am attempting to retrieve a videoUrl from a database and set it to the iframe [attr.src] in order to display a YouTube video. It is imperative that the data originates from the database, as there are limitations preventing us from directly uploading and ...

The error message "TypeError: dom.getElementsByTagName is not a function in Node.js" indicates

I have just started learning HTML and web development. I am trying to extract a list of tags from an HTML document but I keep receiving the error message TypeError: dom.getElementsByTagName is not a function. I am making a GET request using axios, then u ...

Retrieving data from MySQL using PHP and AJAX with radio button selection

How can I update my code to display data from the database when a radio button is clicked instead of using a drop-down box? Here is an example of my current radio button code: <Input type='Radio' Name='compcase' value='1'/& ...

The Geocoder.geocode() method returns XML instead of JSON when invalid credentials are provided

Currently in the process of developing a program that converts addresses from a database to their corresponding lat/long coordinates using the HERE Geocoding API. In order for multiple users to utilize this program, they must manually input their app_id an ...

Discover a scenario in which an identification number is contained within an array

For my Node.js + MongoDB project, I am utilizing sails.js and am currently faced with the challenge of loading all the groups associated with a particular user. Each Group object contains an array of user IDs as follows: Group { users: array } I' ...

Struggling with certain aspects while learning Nodejs and ES6 technologies

Below is an example of using the ES6 method.call() method that is causing an error var obj = { name: "Hello ES6 call", greet: function(somedata) { this.somedata = somedata console.log(this.somedata) ...

Remove an item from the options list in the select2 plugin after an event occurs

I am currently using the Select2 plugin in my project and I am facing an issue where I want to remove an option from the main list. However, when I click on the "x" button generated by the code, it only removes it temporarily from the plugin's list. U ...

Looking to adjust the width of a Bootstrap dropdown menu?

I am trying to adjust the width of my dropdown menu Here is a link to jsfiddle with my code: [jsfiddler][1]. On the right side of the main menu, I have a languages dropdown menu. When it expands, its width is very large and I want it to match the main m ...

What are alternative ways to communicate with the backend in Backbone without relying on model.save()?

Is there a more effective method to communicate with my backend (node.js/express.js) from backbone without relying on the .save() method associated with the model? Essentially, I am looking to validate a user's input on the server side and only procee ...

Interacting with PHP through JavaScript function calls

I am facing some frustration with my website due to an issue involving PHP. When I retrieve data from a PHP file, it returns a JSON list like this: {"Data":{"Recipes":{"Recipe_5":{"ID":"5","TITLE":"Spaghetti Bolognese"},"Recipe_7":{"ID":"7","TITLE":"Wurst ...

What is the best way to initiate a new animation from the current position?

Here is my custom box: <div class="customBox"></div> It features a unique animation: .customBox{ animation:right 5s; animation-fill-mode:forwards; padding:50px; width:0px; height:0px; display:block; background-color:bla ...

The action is undefined and cannot be read for the property type

Using the React+Redux framework, I encountered an error: https://i.sstatic.net/0yqjl.png During debugging, the server data successfully reached the state, but the action was empty: https://i.sstatic.net/41VgJ.png Highlighted below is a snippet of my co ...

Refresh stock value in anychart without having to re-render the entire chart

I am currently experimenting with the Anychart stock candlestick chart and I must say, it is quite impressive. However, I have encountered an issue while trying to update the chart using a setInterval function. The problem is that it re-plots the entire ch ...