简体   繁体   English

页面顶部的JSF滚动条

[英]JSF scroll bar at the top of the page

I was wondering how to make the scroll bar of the browser. 我想知道如何制作浏览器的滚动条。 go to top of page. 回到页面顶部。 I am developing a registration screen that is too big, and it contains some fields that are needed. 我正在开发一个太大的注册屏幕,它包含一些需要的字段。 It displayed an error message to the user if the required fields are not informed. 如果未通知所需字段,则会向用户显示错误消息。 The problem is that the scroll bar does not go up, and I want her to go to the top of the page. 问题是滚动条没有上升,我希望她转到页面顶部。 I'm using Primefaces and JQuery, but no this working. 我正在使用Primefaces和JQuery,但没有这个工作。

<div id="msg">

内容页

 onclick="javascript:window.location='#msg'"

I must say that your question looks like some discussion between two people, but I will try to give an answer. 我必须说你的问题看起来像是两个人之间的讨论,但我会尽力给出答案。 I suppose you have p:commandButton for submit the form. 我想你有p:commandButton来提交表单。

First add JavaScript function: 首先添加JavaScript函数:

<script type="text/javascript">
  function handleResponse(xhr, status, args) {
    if (args.validationFailed) {
      window.scrollTo(0, 0);
    }
  }
</script>

validationFailed is callback parameter which is added implicitly by PrimeFaces in case hen validation fails. validationFailed是回调参数,在hen验证失败的情况下由PrimeFaces隐式添加。

Now, commandButton : 现在, commandButton

<p:commandButton value="Submit" actionListener="#{myBean.submit}" oncomplete="handleResponse(xhr, status, args)"/>

This will call JavaScript function after AJAX request is completed. 这将在AJAX请求完成后调用JavaScript函数。

This is as much as I can suggest, you didn't provide much information. 这是我可以建议的,你没有提供太多信息。 Adapt this code to your needs. 根据您的需要调整此代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM