Submit form without bean validation

删除回忆录丶 提交于 2019-12-06 10:51:59
BalusC

Use <f:validateBean> where on you set the disabled attribute.

<h:inputText value="#{bean.input}">
    <f:validateBean disabled="#{bean.draft}" />
</h:inputText>

If this evaluates true, this will skip all bean validation on the property associated with the input's value. You should only ensure that the boolean draft property is set before the validations phase takes place. E.g.

<h:commandButton value="Save draft" action="#{bean.saveDraft}">
    <f:param name="draft" value="true" />
</h:commandButton>

with

@ManagedProperty("#{param.draft}")
private boolean draft;

or if it's a view scoped bean on which @ManagedProperty won't work:

public boolean isDraft() {
    return "true".equals(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("draft"));
}

Another way is to check in EL if the button is pressed by determining the presence of its parameter name. For example, with the following form and button ID

<h:form id="form">
    <h:inputText value="#{bean.input}">
        <f:validateBean disabled="#{not empty param['form:draft']}" />
    </h:inputText>
    <h:commandButton id="draft" value="Save draft" action="#{bean.saveDraft}" />
</h:form>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!