Create dropdown list jsf - jsf

Currently i'm stuck in create two dropdown list in jsf by click a "Add" button.
Initial i have a form with two dropdownlist, a "Add" button and a "submit" button.
The first dropdownlist is list country. The second dropdownlist is list city.
When user choose a country then the second dropdownlist will add dynamic city of this country(i done this using ajax f:ajax).
how can i add two other dropdownlist(list country and list city also) when add button clicked?(it mean user can add a lot of pair dropdownlist using add button)
how about structure of bean to manage all pair dropdownlist when i click submit button?
Please give me some example code to do it.
Thanks

Have you tried using c:forEach? Similar to the following:
<c:forEach var="i" begin="1" end="#{bean.numberOfAddsCLicked}" step="1">
<!-- Your elements to repeat here. Probably bind their values to bean.country[i] respective bean.city[i] with country and city being arrays of bean.numberOfAddsCLicked -->
</c:forEach>

Related

uncheck all other checkboxes when decline is clicked and uncheck decline if other checkbox is checked

I am displaying a list of string values from the bean as checkboxes in jsf as below
<h:selectManyCheckbox value = "#{bean.selectedcountries}">
<f:selectitems value = "#{bean.countries}" />
</h:selectManyCheckbox>
the selected countries list will contain the user selected values before from database. and the countries list will contain the list of options for the user to choose from while editing data.
Now, in the countries list a value is there as Decline, so if user select decline all other checked options should be unchecked automatically and if the decline option checked if user is trying to select any other checkbox Decline option should be unchecked automatically.
I am pretty new to JSF . How to achieve this.

slideMenu and selected submenu value

I have a tree of categories (types) to be showed inside a <p:slideMenu>, I want to select the category showed inside the label of <p:submenu>, and not show its subcategories (contained inside a list of <p:menuitem> tags).
Is there any way to solve this issue, for example add a button in front of each <p:submenu> and when I click the button the current <p:submenu> is selected and its value is sent to a backing bean, and when I click on the label contained inside <p:submenu> the subcategories will be shown.
I am using primefaces 3.5.

How to get the selectManyCheckbox row entire values to the list using JSF and datatables

Select Many Check box items to Cart :
Declare check box first column of data
Declare the command button to the above the data
Once user click the check box current row data add to the list and this list data go to the Cart page
On click the check box current row data add to the list and on submit the button the entire list data go to the Cart page.
Thanks in Advance.
You can use primefaces datatable component for select one or more rows from a table and send this information to everywhere.
Take an example of this in showcase (the datatable have many others options too).

How to use <h:selectOneRadio> on more than one datatable

I'm trying to achieve the well known feature of being able to select a datatable's row by using a radio button.
I have followed this blog:
http://balusc.blogspot.com/2006/06/using-datatables.html#SelectRowByRadioButton
It works perfectly if there is one datatable on the form, but when I add another one (even if it's placed on other form), and try to select a row there, the radio button gets selected then instantly unselected. The data is correctly set on the backing bean though.
Any ideas about how to extend the results of the above blog on more than one datatable?
Thank you
That script will group all radio buttons with the same component ID in the same form. So to fix your particular problem, put the other data table in a different form or give the other <h:selectOneRadio> a different ID.

selectBooleanCheckbox - How do I know which checkbox am I selecting or deselecting?

I develop something like a shopping cart. I can select multiple items (by clicking on the checkbox next to that item) and add them to a list. How can I know which checkbox I am selecting. If I do this
<h:selectBooleanCheckbox value="#{document.checked}"/>
it only tell me a state of a checkbox is selected or not, but does not tell me which one. Remember the number of items is unknown until runtime since I load them from a datasource, meaning I dont know how many check box there are.
You should have a managed bean from which you get and set the booleans for the different checkboxes (different fields with getter and setters for each checkbox value).
Update: take a look at this example, because I think that is what you should be doing. Where the example says "Employee", you take "Article" or whatever your cart items are.
http://www.javabeat.net/tips/43-how-to-use-hselectbooleancheckbox-within-hd.html

Resources