Programmatically set ValueChangeListener for selectOneMenu - jsf

I create two SelectOneMenu in JSF:
SelectOneMenu menu = new SelectOneMenu();
menu.setId("MenuSelect1" + ctrlCenterResultModel.getId());
UISelectItems item = new UISelectItems();
item.setValue(ctrlCenterResultModel.getBudget());
menu.getChildren().add(item);
SelectOneMenu menu1 = new SelectOneMenu();
menu1.setId("MenuSelect2" + ctrlCenterResultModel.getId());
UISelectItems item1 = new UISelectItems();
item1.setId("Item2"+ctrlCenterResultModel.getId());
item1.setValue(ctrlCenterResultModel.getPeriods());
menu1.getChildren().add(item1);
I want set ValueChangeListener for second menu. When I change value in first SelectOneMenu in second I want have different values. For example in first SelectOneMenu I choose Budget1 and I have period for this budget. Next my problem is that I set list of objects in UISelectItems and when I get value for this item I have String, not Object. I know how do that, when SelectOneMenu is created in XHTML, but in this case I create it in Java code.

Related

How to localize a dynamic menu using PrimeFaces?

I'm trying to build an international application that can change locale dynamically on the page. I'm also trying to build a dynamic menu with labels and values that will change when the locale changes dynamically. This is what I tried:
menuModel = new DynamicMenuModel();
DefaultSubMenu inOfficeMailbox = new DefaultSubMenu("#{msg['inofficemailbox']}");
DefaultMenuItem activeItem = new DefaultMenuItem( "#{msg['activeissues']}");
activeItem.setCommand("#{mainMenuMB.loadContent('activeissues')}");
inOfficeMailbox.addElement(activeItem);
DefaultMenuItem resolvedItem = new DefaultMenuItem("#{msg['resolvedissues']}");
resolvedItem.setCommand("#{mainMenuMB.loadContent('resolvedissues')}");
inOfficeMailbox.addElement(resolvedItem);
menuModel.addElement(inOfficeMailbox);
but the menu item just come out with the literals "#{msg['blahblah']}". Where msg is the localization variable. Obviously the EL is not evaluated so the localization doesn't work. What should I do instead?

how to preserve listview selected/ clicked item color while scrolling?

this is really a strange problem i came across several google searches which returned in vain .
Well i have a list view in which the selected item color should be changed while user click on the item.
This post helped me to change the list view selected item color. Now i am able to change the color while the item is clicked . But if i scroll the list view the color jumps out of selection.
https://stackoverflow.com/a/12080202/1657093
If a item is selected say for instance the listview item on first row the last item is also gets selected while scrolling the item color keeps on moving to the item which i never selected.
here is the list view
<ListView
android:id="#+id/loadedlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/horizontalScroll"
android:layout_alignParentLeft="true"
android:layout_below="#+id/Title"
android:layout_toLeftOf="#+id/sidepanel"
android:scrollingCache="false">
</ListView>
I use array adapter to populate the list view
ringlist.setAdapter(new ArrayAdapter
(this,android.R.layout.simple_list_item_1,rings));
and use list view's on click method to set the color ,
ringlist.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int pos,long id) {
// TODO Auto-generated method stub
try{
String con;
String s = ringlist.getItemAtPosition(pos).toString();
con = s.toLowerCase();
String selectedFromList = con;
int resId = getResources().getIdentifier(selectedFromList, "raw",
"com.example.android");
}
if (row != null) {
row.setBackgroundColor(Color.BLACK);
}
row = view;
view.setBackgroundColor(Color.GREEN);
}
}
});
the above code does the job but while scrolling the list something goes wrong
please advice.
This is common issue of Listview in android.
When we use checkbox/radio button in Listview Item after scrolling down or up, the selected position does gets changed at some different places.
The only solution to this till now is, we need to maintain the selected position in a arraylist(or to any structure you are comfortable).
And as you scroll up/down the list view, the getview does gets called.
So write code in your getview() to make checkbox items selected from arraylist.
Also dont use if-else condition in getview for convertview.
Store clicked/selected positions in a set or array in your onItemClick() method. Write code to show clicked/selected items in getview() method of your adapter using stored positions.

ExtJs layout + Window

While adding component dynamically, 'this.container is null' is displayed in firebug.
I have a window with some combo boxes say combo1, combo2, combo3 and a label. Based on the selection value of combo3 the 'label' field is removed and replaced with combobox or text field. i do this my using
form.items.removeAt(4);
form.items.insert(4, newItem); #here newItem can be combox/textfield
form.doLayout();
The form resides inside a panel.
When above lines are execueted. 'this.container is null' is displayed and component fails to insert/add in appropiate position.
Any suggestions?
You should not be modifying the underlying items collection. Use the remove/insert methods on the container.
Try to comment those lines line-by-line to see which one produces error like
form.items.removeAt(4);
//form.items.insert(4, newItem); #here newItem can be combox/textfield
//form.doLayout();
form.items.removeAt(4);
form.items.insert(4, newItem); #here newItem can be combox/textfield
//form.doLayout();
form.items.removeAt(4);
form.items.insert(4, newItem); #here newItem can be combox/textfield
form.doLayout();
Your problem could take place because of inserted/replaced object is no yet prepared when you try to insert it. Give us your newItem initilization code.
Upd
Or you can wrap your changing components (label, combobox, textfields) in a panel with card layout. And on change of combo3 simply select exact card in that panel.

Dynamically Adding Tab At Specific Position to TabView Primefaces

How do we dynamically (from java program) add a tab to existing TabView primefaces component.
My situation is something like this,
There is a drop down with some values,
whenever user selects some value from drop down,
We need to add a tab dynamically at specific position to TabView.
I know we can get existing TabView component, and add a tab,
But if we want add a tab at particular position , how ?
public void addTab(){
FacesContext fc = FacesContext.getCurrentInstance();
TabView tabView = (TabView) fc.getApplication().createComponent(
"org.primefaces.component.TabView");
Tab tab1 = new Tab();
tab1.setTitle("Dynamic Tab-1");
tabView.getChildren().add(index,tab1);
}
You should update the view to reflect the new tab. Use RequestContext for ajax update.
RequestContext context = RequestContext.getCurrentInstance();
context.update("tabview");

Richfaces 3.3.3.final Datatable Selection

Can someone hint me on how to utilize selection functionality of extendeddatatable in rich:datatable ?
My requirement is each row contains more than 15 columns and all are editable and should be able to scale upto 3000 records in a page.
I'm using JSF 1.2 and richfaces 3.3.3.final with spring webflow.
To use the selection attribute on extendeddatatable:
Declare in your view
<rich:extendedDataTable id="xxxDataTable" value="#{xxxBean.listXxxDataModel}"
var="xxxItem" selectionMode="single" rows="3" width="800px" height="100px" noDataLabel="#{msg.dataTable_noDataLabel}"
selection="#{xxxBean.xxxSelection}">
Bind your dataTable value to ExtendedTableDataModel : use a org.richfaces.model.DataProvider to provide data to the ExtendedTableDataModel.
ArrayList<XXX> values = ...;
XXXDataProvider xxxDataProvider = new XXXDataProvider(values);
ExtendedTableDataModel<XXX> xxxDataModel = new ExtendedTableDataModel<XXX>(xxxDataProvider);
The selection is binding to
/** Binding selection */
private SimpleSelection xxxSelection;
Last, to retrieve the selected object from your dataprovider :
key = xxxSelection.getKeys().next();
selectedObject = xxxDataModel.getObjectByKey(key);

Resources