7

I would like to hide the BACK button at the last tab in a wizard. I'm using primefaces. What would be the solution for it?

Thank you

Balint Szivos
  • 83
  • 2
  • 4

4 Answers4

5

you can do it client-side using jQuery :

Assuming you are using the wizard in the showcase: http://www.primefaces.org/showcase/ui/wizard.jsf:

<p:wizard widgetVar="wiz"  
        flowListener="#{userWizard.onFlowProcess}"
        onNext="hideBackOnLastTab()">

javascript:

function hideBackOnLastTab() {
    if($("ul.ui-wizard-step-titles>li").last()
             .is("ul.ui-wizard-step-titles>li.ui-state-highlight")) {
            $("div.ui-wizard-navbar>button.ui-wizard-nav-back").css("display", "none");
    }

}

Also you can notice that the next button in wizard is hidden (by the PF client-side) at last panel the same way.

Mindwin Remember Monica
  • 1,469
  • 2
  • 20
  • 35
3

I've had the same issue for a long time and finally solved it. Maybe my solution can be helpfull for others in the future:

Webpage:

<p:wizard id="dataLoadSetWizard" widgetVar="wiz" onnext="hideBackOnLastTab()" ...

Javascript:

function hideBackOnLastTab() {
            if(PF('wiz').getStepIndex(PF('wiz').currentStep) > 0) {
                PF('wiz').backNav.css("visibility", "hidden")
            }
        }
Koen Goovaerts
  • 171
  • 2
  • 5
  • Worth mentioning that `visibility: hidden` preserves the element's space - see [What is the difference between visibility:hidden and display:none?](http://stackoverflow.com/questions/133051/what-is-the-difference-between-visibilityhidden-and-displaynone) – Aziz Feb 26 '16 at 17:02
  • Really useful. Thanks. – Fuzzy Analysis Nov 03 '16 at 23:02
0

I would like to share my solution using PrimeFaces 6.2. There is no custom JavaScript on the view side.

<p:importConstants
  type="com.example.WizardController"
  var="WizardController"
></p:importConstants>

<p:wizard
  flowListener="#{wizardController.onFlow}"
  widgetVar="wizard"
>
  <p:tab id="#{WizardController.STEP_LAST}">
  </p:tab>
</p:wizard>

In the flow listener I just hide the navigation buttons and disable the navigation bar on the last step. Hiding the navigation bar is necessary. Otherwise PrimeFaces internal JavaScript for wizard will fade them in again.

@ViewScoped
@Named
public class WizardController {

  public static final String STEP_LAST = "last";

  public String onFlow(FlowEvent flowEvent) {
    if (flowEvent.getNewStep().equals(STEP_LAST)) {
      PrimeFaces.current().executeScript("PF('wizard').backNav.hide(); PF('wizard').nextNav.hide(); PF('wizard').cfg.showNavBar = false;");
    }
  }
}
irieill
  • 1,203
  • 10
  • 32
0

From managed bean you can try this:

  @ManagedBean(name = "testWizardBean")
  @ViewScoped
  public class TestWizardBean implements Serializable {

         private RequestContext requestContext;

         @PostConstruct
         public void init() {
              requestContext = RequestContext.getCurrentInstance();
              if (testWizardDto.getDirection().isEmpty()) {
                    requestContext.execute("PF('signwzd').nextNav.hide();");
         }
  }

}