Sunday, October 23, 2016

Programatically render input text on UI based on the number entered in the spin box

  • Drag and drop a spin box from the component palette on the page.
  • Give the value change listener to the spin box
  • we can also set min,max and default values for Spin Box.
  • Write the following code in the value change listener
  •         private List<String> numList= null;

  • @demo method 

  •         public void numOfInput(ValueChangeEvent vc) {
  •                Object answer=vc.getNewValue();
  •                BigDecimal a = (BigDecimal)answer;
  •                numList= new ArrayList<String>();
  •          for(int i=1;i<=a.intValue();i++) {
  •               numList.add("krt"+i);
  •          }
  • numList is an array list and iterates as many number of times as specified in the spin box.


  • Drag and drop the input text from component palette beneath the spin box. 
  • Surround the input text with an iterator
  • Give the value to the iterator as 
  •  #{viewScope.sampleBean.numList}  (The value property of the iterator takes an array list. In our case numList is an array list)
  • Set the auto submit property for spin box to true and give the id of spin box in the partial trigger property of input text.


Thus depending upon the number entered in the spin box, input text are rendered on the UI. 

No comments:

Post a Comment