0

我在我的应用程序中使用 icefaces。页面中有一个表单,其中有几个输入字段。

我只想在字段有效时启用命令按钮(其他组件没有错误)

有可能吗?

示例代码

<ice:form>
<ice:panelGrid  columns="2">
    <ice:outputLabel>Enter Date</ice:outputLabel>
        <ice:panelGroup>
            <ice:selectInputDate renderAsPopup="true" id="InputDate" value="#{Bean.FormDate}" partialSubmit="true" ></ice:selectInputDate> 
                <ice:message for="InputDate" />
        </ice:panelGroup>

     <ice:outputLabel>Days</ice:outputLabel>
        <ice:panelGroup>
            <ice:inputText value="#{Bean.days}"partialSubmit="true" id="inputDays">
                <f:validateLongRange minimum="1" maximum="10"/>
            </ice:inputText>
                <ice:message for="inputDays"/>
            </ice:panelGroup>

    <ice:commandButton value="Submit" action="#{Bean.SomeAction}"></ice:commandButton>
</ice:panelGrid>

在上面的代码中,我只想在日期和日期有效的情况下启用提交命令按钮(没有任何错误入队。

4

3 回答 3

1

如果您使用的是 jsf 2.0,您可以执行以下操作:

    <ice:form>
        <ice:panelGrid columns="2">
            <ice:outputLabel>Enter Date</ice:outputLabel>
            <ice:panelGroup>
                <ice:selectInputDate renderAsPopup="true" id="InputDate"
                    value="#{Bean.FormDate}" partialSubmit="true"
                    binding="#{inputDateComponent}">
                    <f:ajax execute="@this" render="submit inputDateMessage" />
                </ice:selectInputDate>
                <ice:message id="inputDateMessage" for="InputDate" />
            </ice:panelGroup>

            <ice:outputLabel>Days</ice:outputLabel>
            <ice:panelGroup>
                <ice:inputText value="#{Bean.days}" partialSubmit="true"
                    id="inputDays" binding="#{inputDaysComponent}">
                    <f:validateLongRange minimum="1" maximum="10" />
                    <f:ajax execute="@this" render="submit inputDaysMessage" />
                </ice:inputText>
                <ice:message id="inputDaysMessage" for="inputDays" />
            </ice:panelGroup>

            <ice:commandButton id="submit" value="Submit"
                action="#{Bean.SomeAction}"
                disabled="#{!inputDateComponent.valid}" />
        </ice:panelGrid>
    </ice:form>

我没有测试这个具体的例子,但你可以看到我要去哪里。输入字段会根据更改进行评估,并显示验证错误或创建未禁用命令按钮的条件。

如果您希望按钮仅在输入字段有效时出现,您也可以使用 render= 并做出肯定的断言。

于 2011-02-17T01:52:19.750 回答
0

您可以使用此处描述的相位侦听器:

http://balusc.blogspot.com/2007/12/set-focus-in-jsf.html

此示例中的阶段侦听器构建带有附加消息的客户端 ID 的字符串。在 bean 中检查此字符串并根据是否有带有消息的 id 创建一个 bean 属性。

然后您可以根据 bean 属性启用命令按钮。

于 2011-02-17T10:53:57.913 回答
0

将每个输入字段切换为 'immediate="true"' 并向字段添加验证器。

让验证器设置/取消设置布尔值以确定字段是否包含有效数据,并按照 sparrowhawk 的建议执行操作,并在提交按钮的呈现表达式中测试此布尔值。

于 2011-02-19T13:34:04.820 回答