I'm working with a wizard in primefaces, the behavior is the regular one, a few tabs, click next to go next, click back to go back, onflowproces, etc. The problem is that in certain cases you can enter to the page in read-only mode, and as in that case is unnecessary to pass every single step to reach a certain step, I want to find the way to click in the tab and redirect.
The wizard consists in 8 tabs, every single tab could be accessed adding the id of the tab in the url param, the only thing I have to do is find a way to click the tab and redirect to the url of the tab.
Is there a way to achieve this? thanks!
To make the name of the wizard as a link to their tab I override WizardRenderer like this:
package myImportantPackage;
import java.io.IOException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.primefaces.component.tabview.Tab;
import org.primefaces.component.wizard.Wizard;
public class WizardRenderer extends org.primefaces.component.wizard.WizardRenderer {
@Override
protected void encodeStepStatus(FacesContext context, Wizard wizard) throws IOException {
ResponseWriter writer = context.getResponseWriter();
String currentStep = wizard.getStep();
boolean currentFound = false;
writer.startElement("ul", null);
writer.writeAttribute("class", Wizard.STEP_STATUS_CLASS + " wizard-panels", null);
int i = 0;
for(UIComponent child : wizard.getChildren()) {
if(child instanceof Tab && child.isRendered()) {
Tab tab = (Tab) child;
boolean active = (!currentFound) && (currentStep == null || tab.getId().equals(currentStep));
String titleStyleClass = active ? Wizard.ACTIVE_STEP_CLASS : Wizard.STEP_CLASS;
if(tab.getTitleStyleClass() != null) {
titleStyleClass = titleStyleClass + " " + tab.getTitleStyleClass();
}
if(active) {
currentFound = true;
}
writer.startElement("li", null);
writer.writeAttribute("class", titleStyleClass, null);
if(tab.getTitleStyle() != null) writer.writeAttribute("style", tab.getTitleStyle(), null);
writer.startElement("a", null);
final String wiz = wizard.resolveWidgetVar();
writer.writeAttribute("href", "javascript:PF('"+wiz+"').loadStep(PF('"+wiz+"').cfg.steps["+i+"], false)", null);
if (tab.getTitletip() != null) writer.writeAttribute("title", tab.getTitletip(), null);
writer.write(tab.getTitle());
writer.endElement("a");
writer.endElement("li");
i++;
}
}
writer.endElement("ul");
}
}
And registered it in faces-config.xml
, like this
<renderer>
<component-family>org.primefaces.component</component-family>
<renderer-type>org.primefaces.component.WizardRenderer</renderer-type>
<renderer-class>myImportantPackage.WizardRenderer</renderer-class>
</renderer>