Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set current displayed tab programmatically in p:wizard

Is it possible to set current displayed tab programmatically in <p:wizard>?

For example, I want that for two different request to the same page which contains a wizard, to have a different tab selected.

What I am currently trying to do, is to have a wizard with many tabs, in the second tab I have a redirection to another page, so when I come back I want to come to the last step which caused the redirection.

Can you please help me ? Thank you a lot !

like image 507
Ioan Avatar asked Dec 04 '25 05:12

Ioan


2 Answers

According to primefaces documentation there's a step attribute for p:wizard tag, which specifies the step of the wizard you're currently in.

attribute: step
default value: 0
type: String
description: Id of the current step in flow

You must bind this attribute to a value of your backing bean and maintain it during redirection and coming back. If your wizard's bean is @ViewScoped you'll loose that info during redirection step, so you have to pass it using a view param or flash scope.

like image 94
Xtreme Biker Avatar answered Dec 07 '25 15:12

Xtreme Biker


My answer would most probably not meet your complete requirements, but, nonetheless, it may point you towards solution to your problem.

As far as I know, the PrimeFaces Wizard UIComponent is designed for a workflow of one page. That effectively means that inputs will be handled by a backing beans that is in a view scope.

This way, making a redirection on a certain step will clear all data inputs, because your view changes and the old one is destroyed.

Anyway, a means of setting a current tab for display is step attribute of Wizard component. So,

<p:wizard step="#{wizardBean.currentStep}" >...</p:wizard>

will force the wizard to show you step which you specified in your bean. You may be able to get it by using, for example, a view parameter, like in

<f:viewParam name="step" value="#{wizardBean.currentStep}" />

But it will make sense if lifetime of your bean is more that for a view, for example, the bean could be put in session scope.

That said, maybe it is a better idea to do login beforehand. Or, if it is absolutely necessary to do it in step 2 of your wizard, provide for a built-in login functionality in a page itself, or in a popular window?

Also, programmatically the setting you speak of can be achieved via a binding of component to your backing bean and setting the step value in the backing bean, for example, in a preRenderView event.

like image 29
skuntsel Avatar answered Dec 07 '25 15:12

skuntsel