开发者

JSF2.x: Navigation based on list box selected items

I need a solution to the below scenario.

I have a home page with a multi select list box and a submit button. Now the list box has only around 开发者_Go百科5 items but in future there can be 50 - 100 items in the list box. For each selected item, it should open the item details screen sequentially. For example if there are 10 items in the list box and when the user selects 2nd,5th and 9th item and clicks Submit should first show the 2nd details page then 5th and 9th page. After submitting from the 9th page the next page should be the home page.

I am going to use Jsf 2.0 or Jsf 2.1 I read somewhere that we should not use faces-config.xml in Jsf 2.x So I am not really sure how to implement the above scenario. Thanks for your help.


Interesting question and you get a +1 from me.

First of all, you're talking about 50+ items, so obviously you will need one page capable of rendering all the item types.

On the page with the list box, when the form is submitted you can populate a java.util.List with the item IDs and set an index variable to 0. Then you should proceed to the item rendering page. On that page, you should handle the preRenderView event so that you show the item in the list at the current index. You can put that event in the @ConversationScoped bean also. Your form submit action for that page should also be handled in the @ConversationScoped bean, with the action incrementing the index so that on the next page load the next item will be shown.

Edit: Since you want one JSF page per item, then you can adapt this idea and return view IDs in your action.

public String submit() {
    // Some processing logic here
    // ...

    // Return the view ID of the next item and increment the index.
    return items.get(index++).getViewId();
}

Your item class might be something like this:

public class Item {
    private int id;
    private String name;
    private String description;
    private String viewId;

    // Getters and setters
    // ...
}

Hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜