Dynamically Adding Tab At Specific Position to TabView Primefaces - jsf

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");

Related

Dynamically TextView Or buttons Android Studio

I'm not sure how to do this:
I have a variable that is passed threw an intent to my new activity.
This variable is a Number. That number received threw the intent will be different depending on the user.
So I want to dynamically write buttons or texViews depending on Number variable.
Example : Number = 4;
There is 4 buttons or textviews (with onclick listener each and text written has Button 1, Button 2, et. ).
Example Number = 10;
There is 10 buttons or textviews or etc. (with onclick listeners each).
Not sure how I can approach this problem
You can create new dynamic views something like that:
Button myButton = new Button(this);
myButton.setText("Push Me");
LinearLayout ll = (LinearLayout)findViewById(R.id.yourLinearLayoutId);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
// with addView method you say to your app when you want to add this view inside on your LinearLayout view
ll.addView(myButton, lp);

Add tree component to OverFlowMenu

I am using codename one to create an application, and i am in front of a situation that is making me use the "tree component" in the pop-up of the OverFlowMenu
how can i do that?
That won't work. The overflow menu uses a renderer approach and isn't very customizable.
Instead add a command to the right side of the toolbar and show a popup dialog pointing at that button e.g.:
popupCommand = toolbar.addMaterialCommandToRightBar("", FontImage.MATERIAL_MORE_VERT, e -> showPopup());
private void showPopup() {
Button b = toolbar.findCommandComponent(popupCommand);
Dialog popup = new Dialog(new BorderLayout());
popup.add(BorderLayout.CENTER, new Tree());
popup.showPopup(b);
}

Programmatically set ValueChangeListener for selectOneMenu

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.

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?

GXT: UiBinder new instance of a Widget

I have a TextField form inside a window. Created with UiBinding. Next to the TextField is a button. I wanted to know if it was possible to create a new TextField widget when that button was pressed using UiBinder?
This is what I have:
Window class:
#UiField
TextField text;
#UiField
HorizontalPanel hPanel;
....
#UiHandler("addText")
public void onClick(SelectEvent event){
hPanel.add(text);
}
My UiBinder file:
<gxt:Window ...(generic setup)...>
<g:VerticalPanel>
<gxt:FramedPanel>
<container:VericalLayoutContainer>
<container:child>
<g:HorizontalPanel ui:field="hPanel">
<form:FieldLabel text="Text">
<form:Widget>
<form:TextField ui:field="text"/>
</form:Widget>
</form:FieldLabel>
<button:TextButton ui:field="addText"/>
</g:HorizontalPanel>
</container:child>
</container:VericalLayoutContainer>
</gxt:FramedPanel>
</g:VerticalPanel>
</gxt:Window>
When I click the button it all it does is move the button from the right side of the text field to the left. I have more textfields in the window so I played around to see what it was really doing. It's taking that field and just moving it next to the button.
Is there a way I can create a new TextField underneath the original?
Probably LazyDomElement will help you.

Resources