开发者

How to implement adjusting dynamicly dataTable's row number equal to user inputted/selected value in JSF page?

How to implement adjusting dynamicly dataTable's row number equal to user inputted/selected value in a JSF pag开发者_如何学运维e?

The context is like this. There is a inputText component NumOfCars and a dataTable named CarInfoList for inputting information of cars. The row number of CarInfoList depends on the value of NumOfCars. For example, if the user input 5 in the NumOfCars, we want the row number of CarInfoList adjust to 5 right away.

Anybody knows how to implement this with a JSF page?


If you mean that you want to show a list of 5 cars max after the user enters 5, just bind the inputText field to a backing bean and for simplicity add a button that you bind to an action method. In this action method, create a sublist of your main list. Your view should then bind to this sublist.

Basically something like this:

@ManagedBean
@ViewScoped
public class SomeBacking {

    private int numberOfCars;
    private List<Car> allCars;
    private List<Car> displayedCars;

    @PostConstruct
    public void init() {
        allCards = ... // get from some service
        displayedCars = allCars;
    }

    public void adjustDisplayedCars() {
         displayedCars = allCars.subList(0, numberOfCars);
    }

    // Getters/setters
}

(Don't forget to add a range validator to your inputText component.)

If with 'right away' you mean without pressing any button, you can do this with AJAX. If you're using JSF 2.0, AJAX is build-in, otherwise you need an external component library such as RichFaces.


I suggest to use primefaces component or jquery datatable plugin available at

http://www.datatables.net/release-datatables/examples/basic_init/zero_config.html

Also primefaces datatable component has great features and ajax compatibility...

Check out it here

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜