我有一个inputField或其他标记,我想要禁用unitl用户点击它 .
东西like this,但我不能让它在JSF中工作 .
$("div").click(function (evt) {
$(this).hide().prev("input[disabled]").prop("disabled", false).focus();
});
我添加disabled = true " to my input field, and div value set on < h:form > (all parent tags in this case only one), something like j_idt13 and div of input field, so " div“值看起来像 j_idt13:inputID
有人可以用jQuery solutin帮我吗?
我想知道它可以在JSF中完成,以及如何完成 .
1 回答
您需要通过服务器端切换它,而不是通过客户端切换它 . JSF作为基于状态组件的MVC框架以这种方式保护以防止被篡改/被黑客入侵的请求,其中最终用户使用客户端语言/工具(如HTML或JS)来操纵HTML DOM树和/或HTTP请求参数,以便JSF的结果
disabled
,readonly
或甚至rendered
属性已更改 .想象一下,如果JSF开发人员在这样一个布尔属性中检查用户的角色会对管理员角色如此
disabled="#{not user.hasRole('ADMIN')}"
并且黑客以这样的方式对其进行操作,那么会发生什么情况呢?这就是为什么你只能改变提到的属性(以及required
)属性和所有转换器,验证器,事件监听器等)通过服务器端 .您可以在任何ClientBehaviorHolder组件中使用
<f:ajax>
来满足要求 . 您可以让JSF通过<h:panelGroup layout="block">
生成HTML<div>
,这也是ClientBehaviorHolder
:使用此
@ViewScoped
托管bean(@RequestScoped
因commandButton/commandLink/ajax action/listener method not invoked or input value not updated的#5中提到的原因而无效):另见:
What is the need of JSF, when UI can be achieved from CSS, HTML, JavaScript, jQuery?
Why JSF saves the state of UI components on server?
如果您真的对如何通过JS / jQuery获取JSF组件的HTML表示感兴趣,请转到以下答案: Unrelated 具体问题如下:
How to select JSF components using jQuery?
How can I know the id of a JSF component so I can use in Javascript