基于其他组件的某些操作更新,执行或呈现jsf组件(update, execute or render a jsf component based on some action of other component)
我遇到了有关基于某些其他组件的操作渲染或执行jsf组件的问题。
我要做的是:首次加载页面时加载一些数据。 所以我写了
<f:metadata> <f:event listener="#{homeController.retrieveAllTagsForUser}" type="preRenderView" /> <f:event listener="#{homeController.populatePostsForUser}" type="preRenderView" /> </f:metadata>
populatePostsForUser方法首先加载用户的所有帖子,如下所示
public void populatePostsForUser() { EntityManager manager = applicationContext.getEntityManagerFactory() .createEntityManager(); Query query = manager.createNamedQuery("Post.selectPostForUser"); query.setParameter("user", this.getUser()); this.posts = (List<Post>) query.getResultList(); System.out.println("populatePostFOrUser called"); }
并在页面加载后,我更新该方法中的posts字段,如下所示
this.posts = (List<Post>)em.createNamedQuery("Post.selectPostsByTags").setParameter("tags", tags).getResultList(); System.out.println("number of posts selected = " + this.posts.size()); System.out.println("selected posts for this tag = " + this.posts); System.out.println("number of posts selected for tag = " + tags + " " + this.posts.size());
这会成功更新posts字段,但在此之后,再次调用相同的populatePostsForUser方法。 每次重新渲染某个组件时都会调用它。
这只是我想知道的一个例子。 我的问题是。 如何控制jsf组件,以便我可以在另一个组件的某个ajax事件上呈现/更新/执行jsf组件?
我想知道在jsf组件之间进行通信的最佳方法,并根据我们的选择在ajax时进行渲染。
I was facing issues regarding rendering or executing the jsf components based on action of some other component.
What I am trying to do is: load some data when the page is first loaded. so I wrote
<f:metadata> <f:event listener="#{homeController.retrieveAllTagsForUser}" type="preRenderView" /> <f:event listener="#{homeController.populatePostsForUser}" type="preRenderView" /> </f:metadata>
populatePostsForUser method first loads all the posts for the user as follows
public void populatePostsForUser() { EntityManager manager = applicationContext.getEntityManagerFactory() .createEntityManager(); Query query = manager.createNamedQuery("Post.selectPostForUser"); query.setParameter("user", this.getUser()); this.posts = (List<Post>) query.getResultList(); System.out.println("populatePostFOrUser called"); }
and after the page is loaded, I update the posts field in that method as follows
this.posts = (List<Post>)em.createNamedQuery("Post.selectPostsByTags").setParameter("tags", tags).getResultList(); System.out.println("number of posts selected = " + this.posts.size()); System.out.println("selected posts for this tag = " + this.posts); System.out.println("number of posts selected for tag = " + tags + " " + this.posts.size());
this updates the posts field successfully but after that, once again the same populatePostsForUser method is called. It is called everytime some component is re-rendered.
This is just an example for what I want to know. My Question is. How can I have control over the jsf components such that I can render/update/execute a jsf component on some ajax event of another component?
I would like to know the best ways to communicate between jsf components and render them according to our choice when ajax is concerned.
原文:https://stackoverflow.com/questions/16250215
最满意答案
jquery-picklist
插件,从版本0.11.0开始,支持双击将项目移动到相反的列表。 你可能想看看。免责声明:我是插件作者。 我建议你看看其他jQuery选项列表插件,找到最适合你需求的插件。
The
jquery-picklist
plugin, as of version 0.11.0, supports double-clicking to move an item to the opposite list. You may want to check it out.Disclaimer: I'm the plugin author. I suggest taking a look at other jQuery picklist plugins as well and find the one that best suits your needs.
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
jQuery的one()将为每个绑定的元素触发附加的事件处理程序一次,然后删除事件处理程序。 如果由于某些原因不符合要求,也可以在单击按钮后完全禁用该按钮。 $(document).ready(function () { $("#submit").one('click', function (event) { event.preventDefault(); //do something $(this).prop('disable ...
-
jquery-picklist插件,从版本0.11.0开始,支持双击将项目移动到相反的列表。 你可能想看看。 免责声明:我是插件作者。 我建议你看看其他jQuery选项列表插件,找到最适合你需求的插件。 The jquery-picklist plugin, as of version 0.11.0, supports double-clicking to move an item to the opposite list. You may want to check it out. Disclaimer: ...
-
如何使用javascript双击对象?(How do I double-click on objects using javascript? Do I have to .click() twice?)[2022-04-15]
像这样调度dblclick事件 : var targLink = document.getElementById ("something"); var clickEvent = document.createEvent ('MouseEvents'); clickEvent.initEvent ('dblclick', true, true); targLink.dispatchEvent (clickEvent); 你可以在jsFiddle看到代码 。 Dispatch a dblclick e ... -
如何定义jQuery是定期点击相同的元素还是双击?(How defined in jQuery was it a regular click on the same element or double-click?)[2024-01-26]
来自QuirksMode : 双击自动 dblclick事件很少使用。 即使使用它,也应该确保永远不要在同一个HTML元素上同时注册onclick和ondblclick事件处理程序。 如果你同时注册,那么找出用户实际完成的工作几乎是不可能的。 毕竟,当用户双击元素时,会在dblclick之前发生一次单击事件。 此外,在Netscape中,第二次单击事件也在dblclick之前单独处理。 最后,警报在这里也很危险。 因此,请将您的点击和dblclicks分开,以避免并发症。 (强调我的) From Quirk ... -
关于jQuery插件开发,你可以阅读的最好的资源可能是learnjquery.com的插件开发模式: http://www.learningjquery.com/2007/10/a-plugin-development-pattern 当然, 从jQuery UI查看官方的jQuery插件开发指南及其等价物并不会有什么坏处。 并且给你一个(非常)小小的洞察力......如果你不是jQuery的新手,插件开发真的很容易。 基本上,它就像 $.fn.myPlugin = function() { // Pl ...
-
只需在init方法中添加代码,但要确保只定位所需的元素。 Plugin.prototype.init = function(){ this.bindEventHandlers(); } Plugin.prototype.bindEventHandlers = function(){ var self = this; $('body').bind('keydown', function(e) { if (e.keyCode == 27) { // "Esc" Key ...
-
jQuery自动完成插件问题(jQuery Autocomplete plugin issue)[2022-03-24]
看起来你正在使用JQuery插件来实现这一目标。 我使用相同的插件,每次按下一个键,它都会向服务器发送一个新的Ajax请求。 您提到您将cacheLength设置为0 ,根据文档 ,值必须>= 1 。 您是否尝试过更改它以查看它是否会改变行为? 编辑1:另外,根据文档,似乎matchContains: true仅在cacheLength > 1有用( cacheLength = 1表示没有缓存,默认为cacheLength = 10 )。 I used this and the things worked ... -
对的,这是可能的。 你应该修改插件。 您需要修改事件处理程序,例如: eventElementHandlers: function (event, eventElement) { var view = this; eventElement .click(function (ev) { if (!eventElement.hasClass('ui-draggable-dragging') && ...
-
我忘记了,这是在事件中无法取消默认操作的边缘情况之一。 在这种情况下,您可能希望对Firefox和Chrome使用CSS方法: -moz-user-select: none; -webkit-user-select: none; 而对于Opera / IE: $("#mytable td").prop("unselectable", "on"); // jQuery 1.6+ $("#mytable td").attr("unselectable", "on"); // jQuery 1.5- 如果 ...