• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating commandlinks at runtime  RSS feed

 
JP Estrada
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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 ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!