如何验证是否在JSF上填充了outputText? [英] How to validate if a outputText is filled on JSF?

查看:61
本文介绍了如何验证是否在JSF上填充了outputText?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我解释一下情况,假设我有一个包含人员列表的Project类,您可以搜索该人员并将他的任务写在该项目上。

Let me explain the scenario, assume that I have an class Project which contains a list of people, and you can search the a person and write his tasks on the project.

好吧,所以,我有一个添加人员的按钮,它会导致一个模态,带有要填充的字段,还有一个搜索按钮...此搜索按钮会导致另一个模态,这是一个简单的人员搜索,您键入名称,从列表中选择一个,搜索模式关闭,名称转到上一个模式的outputText。

Alright, so, I have a button to add people which leads to a modal, with the fields to fill and a search button... This search button, leads to another modal which is a simple person search, you type the name, select one from the list, the search modal closes and the name goes to an outputText on the previous modal.

问题是,如何验证此字段?我的意思是,其他我可以输入required = true的字段,设置了requiredMessage和ap:message。

The thing is, how do I validate this field? I mean, the other fields I can just put required=true, set a requiredMessage and a p:message.

一切正常,值,按钮,所有功能,除了此字段的验证。为了提供更多的权限,这是我需要的:

Everything works fine, the values, the buttons, all works, except for the validation of this field. To give a little more clearance, this is what I need:

这是我的按钮,打开模式,仅在需要条件时才呈现,一切都很好。 p>

This is my button, opens the modal, only rendered if a condition is required, all good.

<p:commandButton icon="ui-icon-search" validateClient="true" type="button" onclick="PF('modalSearchPerson').show();" rendered="#{projectMB.projectParticipant.type == 'STUDENT'}"/>

这是显示参与者名称的文本,由modalSearchPerson更新。 / p>

And this is the text which displays the name of the participant, which is updated by the modalSearchPerson.

<h:outputText id="personName" title="Participant" value="#{projectMB.projectParticipant.person.name}"/>

我想要的东西很简单,就像required = true requiredMessage =您必须选择一个人。,在h:outputText字段上。

What I wanted, is something as simple as required="true" requiredMessage="You must choose a person.", on the h:outputText field.

我希望我说得清楚,谢谢。

I hope I made it clear, Thanks.

编辑:它必须阻止提交,如果仅使用MB上设置的错误消息更新:growl,该模式将关闭,而我不希望这样做。

edit: It must block the submission, if I only update the :growl with error messages set on the MB, the modal will close, and I dont want that.

我用来不关闭模式的按钮有:

The button I use to not close the modal has:

oncomplete="if (args &amp;&amp; !args.validationFailed) PF('modalAddParticipant').hide();"


推荐答案

JSF仅会验证输入,而不会验证输出。

JSF will only validate inputs, not outputs.

大多数直接方法也将其设置为隐藏的输入值。

Most straightfoward would be setting it as hidden input value too.

<h:outputText value="#{bean.output}" />
<h:inputHidden value="#{bean.output}" required="true" />

或者,使用只读输入字段,该字段对CSS样式的帮助不大,例如输出文本(无边框等),只能在渲染响应期间标记为只读(否则JSF在其他阶段将不会对其进行处理。)。

Alternatively, use a readonly input field which is with little help of CSS styled like output text (without border and such) and is marked readonly during render response only (otherwise JSF won't process it in other phases).

<h:inputText value="#{bean.output}" styleClass="looks-like-output" required="true" readonly="#{facesContext.currentPhaseId.ordinal eq 6}" />

这篇关于如何验证是否在JSF上填充了outputText?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆