How to dynamically add JFace WizardPage - java

I'm currently trying to implement an "import wizard" for an application using JFace Wizard.
Basically I have to add the next page "just in time" based upon the input from the user, as each "step" within the wizard is depends upon the previous ones.
So, in the constructor of WizardImport I would add the first page, using:
addPage(new WizardImportSourcePage(data));
Within this page (WizardImportSourcePage) I would then like to add the next page, depending upon the chosen source, e.g.:
btnCsv.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent arg0) {
data.getWizard().addPage(new WizardImportSourcePage(data));
setPageComplete(true);
}
});
As you can see all of this happens in the appropriate Listener. Unfortunately this doesn't work. The Wizard is missing the "Next" button, but only shows the "Finish" button, as it doesn't know anything about the next page until the button is actually being pressed. I've already tried to invoke updateButtons(), but it didn't change anything.
So, any suggestions how to make it work? What would be the right way to build the wizard pages dynamically? Most tutorials seem to assume that the pages are created in the beginning and only the ordering is changed using getNextPage().

In your code extending Wizard you can override
public IWizardPage getNextPage(IWizardPage page)
which lets you decide which page to return next given the current wizard page (there is also a getPreviousPage.

Related

Programmatically set active-menuitem of PrimeFaces responsive themes

We're using one of the new responsive themes of PrimeFaces 8 (Mirage if that matters) I've implemented a dynamic menu to create the menu of my page. Depending on several parameters, the landing page can be different. Example:
Suppose there's a communications environment in which the menu items are
Documents (opens by default)
E-mail
Pictures
When arriving in the communications environment, the application checks whether there are new e-mails. If so, the user won't arrive on the "Documents" page but on the "E-mails" page.
The theme uses cookies to restore the menu state based on what the user has chosen previously. So suppose last time (s)he has chosen "Pictures", the result now is that the menu item "Pictures" is marked as active-menuitem but the displayed page is "E-mail".
I was already able to clear the cookies so that no menu item is active, but now I'm trying to activate the correct menu item. I got most successful by calling
PF('sidebarMenu').activate($('.custom-active-menuitem').closest('li'));
PF('sidebarMenu').activate($('.custom-active-menuitem').closest('ul').closest('li'));
but since the page is rebuild using ajax, this only works once 🤨. Using the build-in .active-menuitem doesn't work so that's why I introduced .custom-active-menuitem that I set in Java code:
DefaultMenuItem.builder()
.value("E-mail")
.icon("fa fa-letter")
.command("#{communicationBean.openEmailPage()}")
.styleClass("custom-active-menuitem") // or something else to mark this item active
.process("#this")
.update(":page");
So now I'm puzzled. Can someone please get me in the correct direction? How can I make the theme show the menu item I choose as active one?

making a jface wizard come to the start on hitting a button/link

I have a jface Wizard, I have a link on the bottom of the wizard and when I click the link the wizard should start a fresh from the start and all the previous selections must go ,It should work as if i'm opening a new wizard again with no selections remaining from current selections.
I've tried opening the first page on the widget selection but it doesn't seem to work, I'm unable to hit the next button
In a WizardPage you could do something like:
IWizard wizard = getWizard();
IWizardPage page = wizard.getPage("page name");
IWizardContainer container = wizard.getContainer();
container.showPage(page);
"page name" is the name of the wizard page you specified in its Constructor.
This will show the particular page, you will need to clear the contents in the setVisible method.

How to handle the reveal action after hits the cancel button in popup

When I click a add link it opens a popup and I cancel the popup then it goes to the previous place.
private class CancelHandler implements ClickHandler {
#Override
public void onClick(ClickEvent event) {
if (popupPanel != null) {
popupPanel.hide();
getUiHandlers().getPlaceManager().revealPreviousPlace();
//I added this code, after the popup closes, the url is not resetting. So I revealed to the previous place.
}
}
}
One list page shows a list of records, Here one validation is handled i.e If there is only one record in a list page it will automatically reveal to the display page. In display page (i.e popup) cancel button is present, If I hits the cancel button it is cancelling but it again opens the display page. If I comment the below line of the code (getUiHandlers().getPlaceManager().revealPreviousPlace();), It is not opening, but I want that line for this purpose, after clicking cancel button I need to reset the url for that I am revealing the request to previous place.
Can anyone say how to fix this issue?
As far as I know PlaceManager#revealPreviousPlace() doesn't exist.
I don't know the exact behavior you are looking for. If all you want to do is go back to the previous URL, you can call com.google.gwt.user.client.History.back(). Note that this is the same as the user clicking the browser's back button. For more safety, I would recommend having the cancel action always redirect to the same place.

How to create Multi step form

We want to give option to author to create multi steps tabs or wizard. This number of steps/tabs should be configurable in Form Start component in Edit button. Once author selects the number of steps/tabs then steps/tabs will be created automatically and then author can drag and drop other components like "File Upload", etc.. Please refer to the attached screenshot.
Kindly let me know how to proceed on this.
You can try to leverage the OOTB tabctrl component provided in geometrixx-outdoors along with the OOTB form component. The only customization needed would be changing the form end component to accomodate prev and next buttons, and then adding a bit of javascript to navigate the tabs on click of those buttons.
Steps to create this.
Drag and drop the default form component on page.
Inside the form drag and drop the tab control component.
Configure the number of tabs required and the contents within each tab in the tab control component.
Modify the form end component to accomodate the previous and next buttons.
Attach handlers for the previous and next buttons using the following JS(currently consists only of the basic functionality. Can be modified according to your requirements).
JS:
jQuery(function ($) {
$(document).on('click', '.prev', function(){ // 'prev' is class of previous button
var tabctrl = $(this).closest('form').find('.tabctrl');
var currentItemHeader = $(tabctrl).find(".tabctrl-header li.active");
$(currentItemHeader).prev().find('a').click();
});
$(document).on('click', '.next', function(){ // 'next' is class of next button
var tabctrl = $(this).closest('form').find('.tabctrl');
var currentItemHeader = $(tabctrl).find(".tabctrl-header li.active");
$(currentItemHeader).next().find('a').click();
});
});
NOTE: Try to include the appropriate clientlibs in geometrixx site before testing this, else tabctrl wouldn't work properly. Or else, you can check this dierctly in geometrixx-outdoors site.

Modal Window or confirm box in Form.onSubmit

In Form.onSubmit can I add a SimpleAttributeModifier to that form? Actually I have a situation where the onSubmit method of the form look like this:
#Override
public void onSubmit() {
//some code
if (some_condition) {
//here I want to show Javascript confirm box or wicket modal window
//but I can not get any AjaxRequestTarget here to show that modal
add(new SimpleAttributeModifier("onSubmit", "return confirm('confirm msg')"));
}
//some code
}
It is not working. Is there any way to achieve this? Thank you.
What you're trying will definitely not work, as the onSubmit() method is not called in time. It is a server-side method called when the form is submitted. In order to show a confirm dialogue, you want some javascript executed on the client before the form is sent back from the client to the server.
You need the attachment of javascript to happen when the html is rendered, so that it's there to be called when the user clicks the submit button.
It can of course be done. I don't have my own code for it handy, but I think this example should get you pointed in the right direction.

Categories