使用JSF显示只读形式(值显示为文本而不是禁用的输入控件)吗? [英] Displaying read-only forms (values are shown as text instead of disabled input controls) with JSF?

查看:166
本文介绍了使用JSF显示只读形式(值显示为文本而不是禁用的输入控件)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据输入表单,用户可以在其中输入大量数据.当用户访问该页面以查看现有数据时,该页面应以只读模式显示(所有值均显示为文本),当他单击编辑"按钮时,应显示所有输入控件的标准格式,以便用户可以更改并保存数据.

I have a data entry form where user enters lots of data. When user comes to the page to view existing data, the page should be displayed in read-only mode (all values shown as text), when he clicks 'Edit' button, normal form with all input controls should be shown so that user can change and save data.

我们将JSF 2.0与PrimeFaces库一起使用.对于文本框和文本区域,可以轻松实现上述行为,但对于复选框,多选,单选,.....控件则不容易实现.有什么简单的方法可以实现上述行为,而不是编写我们自己的代码(这可能会花费很多行,从而使Bean代码的支持变得难看)

We are using JSF 2.0 with PrimeFaces library. It is easy to achieve above behavior for text box and text area but not for Checkbox, multi-select, radio,..... controls. Is there any easy way available to achieve above behavior rather than writing our own code (which may run into lot of lines thus making backing bean code ugly)

感谢您的帮助...

推荐答案

我不确定为什么您认为需要其他的支持bean代码.您已经在支持bean中拥有了所有必需的值.您的问题更多是在这些价值的表述中.只需通过相应地编写视图代码以所需的格式显示它们即可.也许您在想这太难了.

I'm not sure why you think that you need additional backing bean code for this. You've all the needed values in the backing bean already. Your problem is more in the presentation of those values. Just display them in the desired format by writing the view code accordingly. Perhaps you were thinking it too the hard way.

例如,您可以显示是"或否"值,而不是选择布尔值复选框.

Instead of a select boolean checkbox, you could display for example a "Yes" or "No" value.

<h:selectBooleanCheckbox value="#{bean.checked}" rendered="#{bean.edit}" />
<h:outputText value="#{bean.checked ? 'Yes' : 'No'}" rendered="#{not bean.edit}" />

您可以只在输出文本中显示值,而不是选择一个菜单/收音机.

Instead of a select one menu/radio, you could just display the value in an output text.

<h:selectOneMenu value="#{bean.selectedItem}" rendered="#{bean.edit}">
    <f:selectItems value="#{data.availableItems}" />
</h:selectOneMenu>
<h:outputText value="#{bean.selectedItem}" rendered="#{not bean.edit}" />

例如,您可以只显示所有以逗号分隔的值,而不是选择多个列表框/复选框.

Instead of a select many listbox/checkbox, you could just display for example all values comma separated in a loop.

<h:selectManyListbox value="#{bean.selectedItems}" rendered="#{bean.edit}">
    <f:selectItems value="#{data.availableItems}" />
</h:selectManyListbox>
<h:panelGroup rendered="#{not bean.edit}">
    <ui:repeat value="#{bean.selectedItems}" var="selectedItem" varStatus="loop">
        #{selectedItem}#{not loop.last ? ', ' : ''}
    </ui:repeat>
</h:panelGroup>

您可以将它们全部包装在标记文件或复合文件中,以最大程度地减少样板和代码重复.

You could wrap it all in a tag file or a composite to minimize boilerplate and code repetition.

这篇关于使用JSF显示只读形式(值显示为文本而不是禁用的输入控件)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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