开发者

JSF: Navigation issue (Ajax / Non-Ajax)

When the following (PrimeFaces) button is pressed

<p:commandButton value="Search"
                 actionListener="#{personController.searchPersons}"
                 update="resultTable"/>

I load a list of objects and display them in a table on the current page. This is done via an Ajax call.

Now I'd like to do the following: If only one object is found, don't update the result table but link directly to the "detail page". (e.g. detail.xhtml)

How can this be done?

I know that i can control the navigation via the return value of my searchPersons() method. But It doesn't work as it should. I think it has to do with the update="re开发者_如何转开发sultTable" of my button. But I currently don't know how to solve this...


You can bring in some JS in oncomplete attribute. It will be executed when the bean action and the partial update is completed. You can change the window location in JS by assigning window.location a new URL.

Here's a random kickoff example, assuming that you've a persons table with id persons and that the detail link look something like <a class="detail" href="detail.xhtml?id=123"> somewhere in the table row.

oncomplete="var $persons = jQuery('#persons tbody tr'); if ($persons.length == 1) window.location = $persons.find('a.detail').attr('href');"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜