Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Creating commandlinks at runtime

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys..how do i create a commandlink at runtime? i tried doing this:

FacesContext facesContext = FacesContext.getCurrentInstance();
Application application = facesContext.getApplication();


//UICommand output = (UICommand) application.createComponent("javax.faces.HtmlCommandLink");

UIOutput output = (UIOutput) application.createComponent("javax.faces.HtmlOutputLabel");

output.getAttributes().put("value","TEST DYNAMIC");
output.getAttributes().put("actionListener","#{PersonBean2.saveRecord}");
output.getAttributes().put("action","Ethan");

component.getChildren().add(output);


But it only works for outputLabels..i get a type mismatch error when i use it for commandLinks

Please help!
 
JP Estrada
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it

it should be:
FacesContext facesContext = FacesContext.getCurrentInstance();
Application application = facesContext.getApplication();


UICommand output = (UICommand) application.createComponent("javax.faces.HtmlCommandLink");
output.setId("c1");
output.setValue("TESTING");

component.getChildren().add(output);
 
JP Estrada
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have another problem...

How do i create params at runtime, and assign them to dynamically created commandLink?


Ok, i was able to workaround this by creating a custom actionListener and assigning instances of that class to the dynamically created commandLink...
But,still, is there a way to create params at runtime?
[ April 18, 2006: Message edited by: JP Estrada ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic