0

我是 jsf 的新手,正在做以下事情:例如,我要求用户填写表格,然后提交。提交后,我想显示提交是否成功。为此,我创建另一个 html 页面,并在提交后,如果成功,我将页面重定向到这个新的成功 html 页面。所以,我的项目中有很多网页。我的问题是,这是一件坏事吗?除了创建许多“成功”页面之外,还有其他解决方案可以尝试吗?这是我的做法:

<h:form>
        <h:panelGrid columns="2">
            <h:outputText value="Select one:"></h:outputText>
            <rich:select  defaultLabel="Select..."  value="#{account.accountCurrency}" >
                <f:selectItem itemValue="a" itemLabel="a" />
                <f:selectItem itemValue="b" itemLabel="b" />
                <f:selectItem itemValue="c" itemLabel="c" />
            </rich:select>

            <h:commandButton value="Submit" action="#{selection.approve}" ></h:commandButton>
        </h:panelGrid>           
    </h:form>

在我的托管 bean 中,我执行以下操作:

 public void approve() {
   // check whether it is successful, then redirect to successful page
}

谢谢

4

2 回答 2

1

使用消息组件显示一条消息。

<h:commandButton value="Submit" actionListener="#{somebean.someMethod}">
    <f:ajax  render="msg"/>
</h:commandButton>
<h:messages id="msg"/>

Java代码:

String msg = "Successfully submitted!";
FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_INFO, msg, null);
FacesContext.getCurrentInstance().addMessage(null, fm);
于 2013-07-14T06:41:02.307 回答
0

您可以使用复合组件和模板来帮助减少所需的代码量。

于 2013-07-14T01:53:37.147 回答