繁体   English   中英

如何重置primefaces向导的步骤?

[英]how to reset primefaces wizard's steps?

我使用 primefaces <p:wizard>并且我一步一步注册。如果注册成功结束,向导的步骤是第一步,但是如果我继续寻找新记录或用户,向导将无法添加新记录。它正在更新以前的记录/用户相反。如何连续添加新记录? 另一个问题; 当它返回到第一步时,它不能重置该字段。我该怎么做? 它的提交按钮的代码;

<p:commandButton immediate="true" value="Submit" update="@parent,wiz1,growl,panel"
                            actionListener="#{OgrenciKayit.save}" oncomplete="wiz.loadStep (wiz.cfg.steps [0], true)" />

如果向导提交,则返回第一步。

oncomplete="wiz.loadStep (wiz.cfg.steps [0], true)"

和动作监听器

public void save(ActionEvent actionEvent) {
        tx = session.beginTransaction();
        session.save(ogrenci);
        tx.commit();
        FacesMessage msg = new FacesMessage("Başarılı", "Hoşgeldin :"
                + ogrenci.getAd());
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

等待您的想法..(附加信息我使用 Jsf 2.2、Tomcat 7.0.50、Hibernate 4.3.5.final、Primefaces、Shiro)

<p:wizard widgetVar="wiz">
   <p:tab id="tab0">  ...  </p:tab>
   <p:tab id="tab1"> ...
      <p:commandButton value="Jump to tabId"
          actionListener="#{actionTodo.jump}"
          oncomplete="PF('wiz').loadStep('tab0', false)" />
   </p:tab>
 </p:wizard>

这在 PrimeFaces 5.0 上对我有用。 请注意,您只需要向 loadStep 方法提供 tabId。 我们也应该用"PF('widgetVarId')"调用 PF。

org.primefaces.context.RequestContext

RequestContext context = RequestContext.getCurrentInstance();
context.reset("myForm");

我在提交组件上使用这个 javascript 函数和 oncomplete 处理程序:

提交组件:

oncomplete="resetWizard(args, PF('wizardWigetVar'));"

Javascript:

/**
 * Resets the wizard by loading its first step.
 * 
 * @param args
 * @param wizard
 * 
 * @returns
 */
function resetWizard(args, wizard)
{
    if (!args.validationFailed)
    {
        var firstStep = wizard.cfg.steps[0];
        if (wizard.currentStep != firstStep)
            wizard.loadStep(firstStep, true);
    }
}

为了解决这个问题,我不得不合并答案,否则每当我点击编辑按钮时,我在上一版中停止的步骤就会显示出来。

控制器:

public void edit() {
    PrimeFaces.current().executeScript("PF('wizardOrcamento').loadStep('tabCliente', false)");
}

XHTML:

<p:commandButton action="#{orcamentoController.edit}" [...]>
    <f:setPropertyActionListener [...] />
</p:commandButton>

我希望这可以帮助某人。

public void save(ActionEvent actionEvent) {
    tx = session.beginTransaction();
    session.save(ogrenci);
    tx.commit();
    FacesMessage msg = new FacesMessage("Başarılı", "Hoşgeldin :"
            + ogrenci.getAd());
    FacesContext.getCurrentInstance().addMessage(null, msg);

ogrenci = 新的 Ogrenci();

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM