如何在JSF中禁用页面/表单 [英] How to disable page/form in JSF

查看:86
本文介绍了如何在JSF中禁用页面/表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的应用程序,我想让用户具有不同的权限.一个权限将允许用户查看我的数据库中的数据,而另一个权限将允许他们编辑数据.登录后,我将检查他们的权限,以确定他们是否可以编辑数据.如果用户具有只读权限,我正在寻找某种方法来禁用我的整个页面.是否有一种简单的方法来禁用<h:form>标记中的所有内容?我将需要能够禁用多个页面,希望仅通过查看backingbean的一个布尔值即可.任何帮助将不胜感激.

For my application I want to have users with different permissions. One permission would allow a user to view the data from my database, while another permission would allow them to edit the data. On log in I would check their permission to determine wether they can edit the data. I am looking for some way to disable the entirety of my page if the user has the read-only permission. Is there a simple way to disable everything within the <h:form> tag? I would need to be able to disable multiple pages, hopefully by just looking at one boolean in by backingbean. Any help would be greatly appreciated.

-编辑-
是否有任何容器或类似的容器可以包裹我可以设置为禁用的输入?这样,我只需要在一个地方引用该diable,也可以让每个字段设置自己的disable属性(如果我拥有的其他逻辑中需要的话)?

-EDIT-
Is there any containers or like that I could wrap around my inputs that could be set to disabled? This way I would only need to reference the diable in one place and could also leave each field to set its own disable property if that is needed in other logic I have?

推荐答案

您可以禁用按钮,链接,输入字段(所有允许编辑的内容)等...将它们全部指向后备bean中的相同值. /p>

You can disable the buttons, links, input fields (everything that allows editing) etc... pointing them all to the same value in the backing bean.

<h:inputText disabled="#{!bean.permissionToWrite}">

我不知道有什么方法可以禁用表单中包含的所有内容,但是您可能不想这样做,因为您可能希望用户随同表单一起提交搜索查询(即搜索框).

I don't know any way to disable everything contained in a form, but you may not want to do that because you may want the user to submit search queries (i.e. a search box) withing the form.

更新:回答Alex Larzelere的评论.

Update: answering to the comment of Alex Larzelere.

IMHO最好使用disabled而不是rendered,因为您可能希望在inputText框中向用户显示字段的值,但不要让他对其进行修改.如果您不渲染它,他将看不到它.您也可以使用outputText来显示它,但随后必须维护两个元素而不是一个.

IMHO in this case is better to use disabled rather than rendered because you may want to display the value of a field to the user in an inputText box, but not let him to modify it. If you don't render it, he can't see it. You could use outputText as well to display it but then you have to maintain two elements instead of one.

更新,回答问题中的修改: 例如,您可以将组件包装在h:panelGroup中并根据逻辑进行渲染,也可以不渲染,但是您不能禁用h:panelGroup内部的输入字段,必须单独进行操作.

Update answering to the edit in the question: You can wrap your components inside a h:panelGroup for example and render it or not depending on your logic, but you can't disable the input fields that are inside from the h:panelGroup, you have to do it individually.

这篇关于如何在JSF中禁用页面/表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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