p:steps 示例未运行

p:steps example not functioning

我正在尝试使用 STEPS 组件 - Primefaces。但是在文档中教程很差

谁能写一个使用带有 属性 呈现或类似内容的步骤的示例,我如何使用 STEPS 组件显示和隐藏面板。

我这样试过但是不行

我的 xhtml

<p:steps id="testSteps">
            <p:menuitem value="Personal" update="testSteps" actionListener="#{BeanTest.shown2()}"/>
            <p:menuitem value="Seat Selection" update="testSteps"/>
        </p:steps>

        <form id="formShowField1" >
            <p:panel rendered="#{BeanTest.showfield1}">
                     <p:outputLabel value="FORM 1"/>
            </p:panel>
        </form>

        <form id="formShowField2">
            <p:panel rendered="#{BeanTest.showfield2}">
                <p:outputLabel value="FORM 2" />
            </p:panel>
        </form>

我的豆子

public void shown1(){
    showfield1 = true;
    updateEntirePage("formShowField1");
}

public void shown2(){
    showfield1 = false;
    updateEntirePage("formShowField1");

    showfield2 = true;
    updateEntirePage("formShowField2");        
}

如评论所述,您的 XHTML 代码存在多个问题。

1) 使用<h:form>代替<form>

2) p:steps组件默认是只读的。设置 readonly="false" 以获得交互式菜单项。在这种模式下,它需要被放置在 h:form 内的某个地方 - 我得到一个 javax.faces.FacesException: MenuItem must be inside a form element else.

3) 您的菜单项仅更新 p:steps 组件。您的其他面板不会以这种方式显示,因为它们没有更新。您也应该更新包含它们的元素。不知道 updateEntirePage 是什么,尤其是调用两次时。

4) Bean 名称如 Java 变量通常以小写字符开头。

这样试试:

<h:form>
  <p:steps id="testSteps" readonly="false">
    <p:menuitem value="Personal" update="@form" actionListener="#{beanTest.shown2()}"/>
    <p:menuitem value="Seat Selection" update="@form"/>
  </p:steps>

  <p:panel rendered="#{neanTest.showfield1}">
    <p:outputLabel value="FORM 1"/>
  </p:panel>

  <p:panel rendered="#{beanTest.showfield2}">
    <p:outputLabel value="FORM 2" />
  </p:panel>
</h:form>

在你的 bean 中:

public void shown2(){
    showfield1 = false;
    showfield2 = true;
}