how to prevent multiple click and submit on ZK button? - java

My button on zul file using MVVM.
<button id="ok" label="OK" onClick="#command('vm.myCommand')"/>
my vm
#Command
public void myCommand(){
System.out.println('my command clicked');
}
It display twice when I double click on my button. How to prevent this?

use autodisable attribute of button please have a look below code.
<zk>
<button id="ok" label="OK" autodisable="self" />
</zk>
You can run this code in zk Fiddle .When you click on button it automatically disable itself and when action is done it enable again.
Not related to your concrete problem but ZK Progree Bar another option to prevent user click after any action performed by user.

Related

How to handle in-app main menu to submenu navigation and properly using MaterialToolbar and menu.performIdentifierAction()?

I am having problems getting my in-app menu navigation to work. Unfortunately, I have not been able to find a solution here so far. Since I'm quite a newbie to Android development, I'm not sure what info you guys need for better assistance, so bear with me.... ;]
Problem:
The "back to main menu" submenu option triggers the menu.performIdentifierAction(R.id.back_to_main_menu, 0) action. This works fine in principle, but only once. So, suppose the user navigates from the main menu to submenu A, he can return to the main menu and also go to submenu A again. But if he now wants to return to the main menu for the second time, the entire menu will be completely closed. Then the user can still click on all items, but the "Return to main menu" option does not work and instead simply closes the entire menu.
All other methods/actions associated with the menu items will be invoked properly.
What I tried so far:
I tried closing and inflating the menu again. But it lead to different other problems mostely due to not being compatible with MaterialToolbar and using an optionsMenu and related functionalities instead.
Also the solutions I found for selecting a specific menu element programmatically were about using the above mentioned method "menu.performIdentifierAction()".
App structure:
My app consists of three activities and one background service. In all activities I use the same xml menu. And the behavior is the same in all activities. The in-app menu consists of several items and submenus. In each submenu, I added a "back option" so that the user can return to the main menu without closing and reopening the menu.
The menu is included in the activity xmls for each activity, like (simplified):
\<com.google.android.material.appbar.AppBarLayout
android:id="#+id/appBarLayout_mainActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"\>
<com.google.android.material.appbar.MaterialToolbar
android:id="#+id/materialToolbar_mainActivity"
style="#style/Widget.MaterialComponents.Toolbar.Primary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/material_toolbar_settings"
app:title="#string/page_title_mainActivity_text" />
</com.google.android.material.appbar.AppBarLayout>
Referenced like:
materialToolbar_mainActivity = findViewById(R.id.materialToolbar_mainActivity);
Clicked item handling like (simplified):
materialToolbar_mainActivity.setOnMenuItemClickListener(menuItem -\> {
// handle item selection
switch (menuItem.getItemId()) {
// ...
case (R.id.item_mainMenu_app_info):
showInfo();
return true;
// ...
case (R.id.item_submenu_backToMainMenu):
materialToolbar.getMenu().performIdentifierAction(R.id.item_main_menu, 0);
return true;
// ...
default:
return false;
}
});
If you have any suggestions or solutions, please don't hesitate and let me know. If you need any further information, please let me know as well.
With kind regards

Making a button 'disappear' when pressed

So I'm trying to make a kind of Wheel of Fortune game or Hangman. I have 33 buttons which represent the alphabet, 1 button = 1 letter. When a user presses one, it has to 'dissapear' (become disable and invisible). I created all the buttons in the SceneBuilder so they are located in the FXML file.
How do I actually do that? I created this method for the first button. But it doesn't work properly, no matter what button I press the first one dissapear. Is there an easier way to do it wIthout writing 33 different methods for each button?
public void letterChosen (ActionEvent evt) {
b1.setDisable(true);
b1.setVisible(false);
The Button that was clicked is available as the source of the ActionEvent.
Additionally userData could be attached to the Button, in case you cannot get the necessary information to handle the button click from other properties of the Button:
public void letterChosen(ActionEvent event) {
Button source = (Button) event.getSource();
source.setVisible(false);
System.out.println("pick: "+source.getUserData());
}
FXML
<Button onAction="#letterChosen" userData="a" text="A"/>
<Button onAction="#letterChosen" userData="b" text="B"/>
Note that it isn't necessary to disable a Node that isn't shown, since a Node that is not visible cannot be interacted with. a disabled Button will appear "faded" by default, but could also be shown differently, e.g. using CSS.

Popup disappears while selecting options from ListBox<String>

I have a popup in GWT UI screen, in that popup I have Listbox. My problem is when I try to select any option in the ListBox popup closes itself and all I can see is ListBox dropdown options.
PopupPanel have autoHide function in default.
Use below code to disable autoHide when creating PopupPanel.
PopupPanel myPopUp = new PopupPanel(false);
Use these methods to handle open and close PopupPanel.
myPopUp.show();
myPopUp.hide();

h:commandButton onclick event interrupted by button action

My onclick event gets interrupted by button action (full submit). Any ideas?
An alternative would be to change the h:commandButton to a4j:commandButton, but I need a full submit in order for the button to work correctly like this.
<h:commandButton onclick="trackClick();" action="#{bean.print}" />

JFace Action and ImageDescriptor - I wnt to show image and text

Action myAction= new Action("LABEL", ImageCache.getImageDescriptor("IMAGE"));
This code shows me a button without any text. Instead it only shows the image.
What should I do to display them both side by side?
I tried using setText() and setDescription() and setImageDescriptor() but none helped.
Text is not normally shown for an action in a ToolBar if there is also an image.
If you are adding the Action to the tool bar manager using an ActionContributionItem you can call ActionContributionItem.setMode(ActionContributionItem.MODE_FORCE_TEXT);

Categories