【问题标题】:Prevent a p:selectOneListbox from being submitted inside h:form防止在 h:form 中提交 p:selectOneListbox
【发布时间】:2014-11-25 03:30:10
【问题描述】:

我需要跳过h:form 中的输入组件,以免其被处理/提交,因为它仅用于纯粹的演示需求,并且不会向任何 bean 字段提交值。如何在提交表单时禁用其提交以及其他表单输入?

      <h:form>
            <!--other input components-->

            <p:selectOneListbox id="deptsSel">
                <f:selectItems value="#{listRetriever.list}"
                               var="dept" itemLabel="#{namesDirectory.getName(dept)}" itemValue="#{dept}" />
            </p:selectOneListbox>

            <!--other input components-->
      </h:form>

我省略了 p:selectOneListbox 的 value 属性,但在提交表单时它仍然给出验证错误:“deptsSel: Validation Error: Value is not valid

【问题讨论】:

  • 看起来像 stackoverflow.com/questions/12614882/… 的副本。
  • 你为什么担心它?如果您没有在 bean 中使用该组件,请不要理会它
  • 你用什么提交表单,命令按钮?
  • @BalusC:你删除了你的答案,所以我担心如果我要求一些不可行的东西,或者是吗?
  • 我意识到我误解了您的评论。我会更新答案。

标签: jsf jsf-2 primefaces


【解决方案1】:

postback 期间禁用它,只要它不是rendering the response

<p:selectOneListbox ... disabled="#{facesContext.postback and facesContext.currentPhaseId.ordinal ne 6}">

作为 JSF 防范被黑请求的一部分,UIInput 组件的 disabled 属性在 JSF 生命周期的所有阶段(包括验证阶段)的请求处理期间也得到遵守。


与具体问题无关,您是否有兴趣了解该特定验证错误何时以及为何发生,请访问Validation Error: Value is not valid。这是一个强烈的暗示,表明您的模型已损坏 - 即使您从未打算更新模型,它仍然可能在链中的其他地方产生后果。

【讨论】:

  • 谢谢,但是当我尝试使用 ajax 更新它时,我得到了禁用的输入组件。只有在提交表单时才需要禁用它,而不是在通过 ajax 更新时禁用它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-20
  • 2015-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-20
  • 2013-02-21
相关资源
最近更新 更多