Command executes multiple times for menuitems added dynamically to Primefaces SplitButton - jsf

So added primefaces p:splitButton component inside a p:dataView component:
<p:dataView var="product" value="bean.products">
...
//for each item in dataView, I add this split button with a couple of menuitem options
<p:splitButton value="Select Option" icon="pi pi-list" appendTo="#this" model="#{bean.model}" />
...
</p:dataView>
Building the model:
...
DefaultMenuModel menuModel = new DefaultMenuModel();
DefaultMenuItem menuitem = DefaultMenuItem.builder().value("opt1").command("bean.foo1(product)").build();
menumodel.getElements().add(menuitem);
DefaultMenuItem menuitem = DefaultMenuItem.builder().value("opt2").command("bean.foo2(product)").build();
menumodel.getElements().add(menuitem);
The p:dataView ends up looking like this
---
Product 1
[Select Option^]
| Opt 1 |
| Opt 2 |
---
Product 2
[Select Option^]
| Opt 1 |
| Opt 2 |
---
...
---
Product 12
[Select Option^]
| Opt 1 |
| Opt 2 |
---
These are the methods called by the menuitems:
public void foo1() {
System.out.println("first menu item was clicked inside "+product.getName());
}
public void foo2() {
System.out.println("second menu item was clicked inside "+product.getName());
}
So now, when I run the app, this page would display 12 products per page, each with its p:splitButton with the two subitems.
When I click the first menuitem on the first product, it prints a single line as follows:
first menu item was clicked inside Product 1
When I click a menuitem on any subsequent product, it prints a line for each of the prior products, including the clicked one.
So if I click the first submenu item for the 7th product, it prints out:
first menu item was clicked inside Product 1
first menu item was clicked inside Product 2
first menu item was clicked inside Product 3
first menu item was clicked inside Product 4
first menu item was clicked inside Product 5
first menu item was clicked inside Product 6
first menu item was clicked inside Product 7
and so forth...
Does anyone know how to avoid this?

Related

Doesn't recognize SmokeTest tag in testrunner file

my #smoketest tag doesn't get recognized, I've been searching for responses in tools QA but nothing works on my code, help
package testrunners;
import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
#RunWith(Cucumber.class)
#CucumberOptions(
features = {"src/test/java/linkedinLearning/cucumbercourse/features"},
glue = {"stepdefinitions"},
tags = {"#SmokeTest"},
plugin = {"pretty"})
public class TestRunner {
}
My feature file is the following
Feature: Menu Management
#SmokeTest
Scenario: Add a menu item
Given I have a menu item with name "Cucumber Sandwich" and price 20
When I add that menu item
Then Menu Item with name "Cucumber Sandwich" should be added
#RegularTest
Scenario: Add another menu item
Given I have a menu item with name "Cucumber Salad" and price 15
When I add that menu item
Then Menu Item with name "Cucumber Salad" should be added
#NightlyBuildTest #RegularTest
Scenario: Add third menu item
Given I have a menu item with name "Chiken Sandwich" and price 15
When I add that menu item
Then Menu Item with name "Chiken Sandwich" should be added

Navigation Drawer: change selected item after replace another fragment

I'm using android default navigation drawer activity. Assume i have fragment A and fragment B, there is one button in fragment A and it will redirect(replace) from fragment A to B after the button is clicked.
But the selected item in navigation drawer is still highlighting fragment A. Is there any method to change it to highlight the fragment B instead of A?
#Override
public void onClick(View v) {
if(carplate.getText().toString().equals("")){Toast.makeText(getActivity(),"Please enter your car plate number",Toast.LENGTH_SHORT).show();}
else{
Status status = new Status();
FragmentManager fragmentManager = getFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.content_frame,status);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
}
this function is under fragment A. I need the selected item automatic change to fragment B(Status) after i pressed the button in fragment A.
yes it is very easy
first, you have to get Navigation View and then get the menu from that navigation view and high light/show selection on the basis of the item index which is start from the 0. Place the following line of code in the onclick method.
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.getMenu().getItem(0).setChecked(true);
and if you want to open the fragment use the following lines of code with the stated code lines
getSupportFragmentManager().beginTransaction()
.replace(R.id.mainFragment,new yourNewFragment()).commit()
I hope this is helping

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 do I safely add menuItems to an existing menu in Maya MEL

I tried adding menu items to an existing menu in Maya using MEL
Example:
menuItem -label "Mylabel" -insertAfter "someEntry" -parent $gMainFileMenu;
menuItem -label "Mylabel2" -insertAfter "someEntry" -parent $gMainFileMenu;
The issue is that the menu doesn't get populated by the normal entries like it should but only by the entries I've added with these 2 lines of code.
For example, the file menu normally contains "New scene", "Open scene", "Save scene", etc., but when I do these 2 lines, it only contains "Mylabel" and "Mylabel2".
Is there a fix or a workaround to make sure the menu gets fully populated? Is there a way to force Maya to build it without the user actually clicking on it?
Actually the problem is that Maya first populates the menu the first time the user opens it. It checks if the menu length and if it's greater than 0, it doesn't populate it. Since you've added 2 entries, the menu length is greater than 0 and doesn't get populated with the standard entries.
To fix that problem there is two ways to do it. You can do it by force-building the menu items or by registering your build menuItem. Bot ways are usable in different cases.
By force building the menu :
What you have to do, is find the function that Maya call to build the menu you need. You can find these functions in the folder <MayaInstall>/scripts/startup/*. A good way to find the procedure name is to open the Maya Console, enable "echo all commands" and then to click the menu you want to see the function called to build it.
In your case the function is called buildFileMenu() and can be found in the script FileMenu.mel.
Now that you have that function name, you have to check it's parameters. Sometime it need a menu name as parameters some times not. See the bottom section about how to find a menu name if you need one.
Now let's build it.
global string $gMainFileMenu; // Retrieve the menu name
buildFileMenu(); // Build it
// Now build your menu
menuItem -divider true -parent $gMainFileMenu SuperMenuDivider;
menuItem -label "MyLabel1" -parent $gMainFileMenu SuperMenuLab1;
menuItem -label "MyLabel2" -parent $gMainFileMenu SuperMenuLab2;
// Create a proc to remove your menu items
global proc RemoveMyMenuItems()
{
if(`menuItem -ex SuperMenuDivider`) deleteUI -mi SuperMenuDivider;
if(`menuItem -ex SuperMenuLab1`) deleteUI -mi SuperMenuLab1;
if(`menuItem -ex SuperMenuLab2`) deleteUI -mi SuperMenuLab2;
}
// You can then call that function when in the unload function of your plugin.
By registering the build menuItem call
What you have to do is use a function called addMenuItemSafe which takes 3 parameters, the menu you want to populate, the name of the function which populates the menu, and a global variable name to hold the callback.
So first thing you have to do is create the function that will populate your menu, then the function to remove it and then call the AddMenuItemSafe method. Note that in the function you have to check if your menu is already created because Maya will call that function every time the menu is shown.
First, the two functions to add and remove our menu entries:
global proc string AddMyMenuItems()
{
// Global variable to hold the test to see if the menu is populated.
global int $gMyMenuItemsTest;
// Menu var needed in our case because we are inserting in the middle of the menu
global string $gMainFileMenu;
if( $gMyMenuItemsTest == 0 )
{
// Actually build your menu.
// Note that if you don't need to insert it after a specific entry,
// You can just do `menuItem -label "blep"`. No need of -ia and -p
// Also, for inserting in the middle you have to put stuff in reverse order.
// If you are just appending, put it in the normal order.
menuItem -label "Mylabel2" -insertAfter "someEntry" -parent $gMainFileMenu MyMenuLab2;
menuItem -label "Mylabel" -insertAfter "someEntry" -parent $gMainFileMenu MyMenuLab;
menuItem -divider true -parent $gMainFileMenu MyMenuDiv;
$gMyMenuItemsTest = 1;
}
return "RemoveMyMenuItems()"; // Returns the callback
}
global proc RemoveMyMenuItems()
{
global int $gMyMenuItemsTest;
if( $gMyMenuItemsTest == 1 )
{
// Delete your items if they exist (yes we are kind of
// doing the check twice, but I find it safe.
// The user could have deleted it from Maya in the command
// line for whatever reason, more robustness is always good.
if(`menu -ex MyMenuDiv`) deleteUI -mi MyMenuDiv;
if(`menu -ex MyMenuLab`) deleteUI -mi MyMenuLab;
if(`menu -ex MyMenuLab2`) deleteUI -mi MyMenuLab2;
}
}
And then the actual call to the AddMenuItemSafe:
// The menu we want to use ... here it is the File Menu.
global string $gMainFileMenu;
// Our variables needed for the addSafe call
global int $gMyMenuItemsTest;
global string $gMyMenuVariable;
$gMyMenuItemsTest = 0;
$gMyMenuVariable = "";
// The menu creation
addMenuItemSafe($gMainFileMenu, "AddMyMenuItems", "gMyMenuVariable");
You are free to put that function call in a plugin instantiation or where ever it pleases you.
For more information about the function AddMenuItemSafe, you can go in your Maya Scripts Directory it should be there "AddMenuItemSafe.mel".
How to find a menu name
Note for the menu variable names, you can "build" them by using the following convention
"g" + View + Name + "Menu"
Where :
View is the view where you can find that menu. Ex: Main, Polygons, Animations, etc.
Name is the name of the menu. Ex: File, Edit, Mesh, etc.
Note Autodesk will sometimes rename menus and use old globalVariable names so using this method might not always work

uimenucontroller in uiwebview with custom menu items without MORE menu

In my iPad app, there is a UIWebview that displays text content. When I tap hold and select a text, a menu should popup with 2 custom menu.
say, | MENU1 | MENU2 |
But it seems the COPY menu will also accompany, which I couldn't disable. Is there any possibilities to disable it? I tried around the forum and no solutions worked out.
so itz okay to keep the COPY menu along with the other 2. which should now look like
| Copy | MENU1 | MENU2 |
But unfortunately, I 'm getting it displayed with a MORE menu as follows :
| Copy | More... |
Clicking the More... menu is showing the other 2 menu.
But I need all those 2 items to be displayed in the first attempt itself. either just the 2 menus alone, or atleast along with the copy menu.
| Copy | MENU1 | MENU2 |
OR
| MENU1 | MENU2 |
Get me some solution please.... Trying it out in many ways.. But nothing is working out...
Plz help me out...
Thanks,
Brian
It doesn't appear that there is a way to do this without replacing the UIMenuController. One option is to handle your own UILongPressGestureRecognizer (see How to remove th COPY UIMenuItem in UIMenuController). I've seen proposals where you override canPerformAction, but this does not work. Interestingly, the "copy:" action is never called, though it seems that everything else (cut:,select:,etc.) is.
- (BOOL) canPerformAction:(SEL)action withSender:(id)sender
{
if (action == #selector(defineSelection:))
{
return YES;
}
else if (action == #selector(translateSelection:))
{
return YES;
}
else if (action == #selector(copy:))
{
return NO;
}
return [super canPerformAction:action withSender:sender];
}
`

Resources