commandButton with Java

Hello,it is possible for one h:commandButtone.g.<h:commandButton styleClass="btd_input" id="assignButton" action="doAssign" value="Assign"/>to generate by Java?Can I generate a commandButton from Java?
[249 byte] By [rbrosea] at [2007-10-2 13:43:19]
# 1

you sure can

the easiest way is to have ..

<h:commandButton biniding = "#{myBean.myVar}"/>

then in your javacode you have

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

HtmlCommandButton myVar= (HtmlCommandButton) application.createComponent( "javax.faces.Button");

//with getter and setter

then you have myvar in your backing code

this link might also help

http://www.jsffaq.com/Wiki.jsp?ptitle=How+to+add+form+components+dynamically%3F&page=HowToAddFormComponentsDynamically

dboyd68a at 2007-7-13 11:38:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
thank you!But I have a Errororg.apache.jasper.JasperException: Expression Error: Object: 'javax.faces.Button' not found
rbrosea at 2007-7-13 11:38:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Ok I haven't a Exeption, but the td where the button must be arrival is empty ;-(

How a say the button be visible? Must i bind the button with a Component?

public class UITMTable extends UIData {

public void encodeBegin(FacesContext context) throws IOException {

ResponseWriter writer = context.getResponseWriter();

writer.startElement("table", this);

writer.writeAttribute("id", getClientId(context), null);

String width = (String)getAttributes().get("width");

String height = (String)getAttributes().get("height");

String style = (String)getAttributes().get("style");

style= (style!=null) ? style + ";" : "";

if (width != null) style += "width:" + width + ";";

if (height != null) style += "height:" + height+ ";";

writer.writeAttribute("style", style, null);

String styleClass = (String)getAttributes().get("styleClass");

if (styleClass!=null)

writer.writeAttribute("class", styleClass, null);

int counterId=0;

List input = new ArrayList();

input = (List)getAttributes().get("input");

if(input != null) {

Iterator iter = input.iterator();

while(iter.hasNext()) {

MasterDocuments mDoc = (MasterDocuments) iter.next();

String masterStyle = (String)getAttributes().get("masterClass");

writer.startElement("tr", this);

if(masterStyle !=null)

writer.writeAttribute("class",masterStyle,null);

writer.startElement("td", this);

writer.writeAttribute("colspan","4",null);

writer.writeText(mDoc.getMasterName(),"");

writer.endElement("td");

writer.endElement("tr");

for(Iterator iterDocument = mDoc.getDocuments().iterator();iterDocument.hasNext();) {

Documents documents = (Documents)iterDocument.next();

String childStyle = (String)getAttributes().get("childClass");

writer.startElement("tr", this);

if(childStyle != null)

writer.writeAttribute("class",childStyle,null);

writer.startElement("td", this);

// <img src="img/p.GIF" alt="leer" width="10" height="15">

writer.startElement("img",this);

writer.writeAttribute("src","img/p.GIF",null);

writer.writeAttribute("width","20",null);

writer.writeAttribute("height","1",null);

writer.endElement("img");

writer.endElement("td");

writer.startElement("td", this);

writer.writeText(documents.getDocName(),"");

writer.endElement("td");

writer.startElement("td",this);

writer.writeText(documents.getLanguage().getLand(),"");

writer.endElement("td");

writer.startElement("td",this);

writer.writeText(documents.getDeadline(),"");

writer.endElement("td");

writer.endElement("tr");

writer.endElement("td");

writer.startElement("td", this);

FacesContext facesContext = FacesContext.getCurrentInstance();

Application application = facesContext.getApplication();

HtmlCommandButton myVar= (HtmlCommandButton) application.createComponent("javax.faces.HtmlCommandButton");

myVar.setTitle("Test");

myVar.setId("button"+Integer.toString(counterId = counterId + 1));

myVar.setStyleClass("btd_input");

writer.endElement("td");

writer.endElement("tr");

}

}

}

}

public void encodeEnd(FacesContext context) throws IOException {

ResponseWriter writer = context.getResponseWriter();

writer.endElement("table");

}

}

rbrosea at 2007-7-13 11:38:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...