dynamic inputText (programmatically)
rogerioag Feb 18, 2009 7:54 AMI need to make the generation of dynamic inputText (programmatically). Adapting some examples I found on the web, my JSF page has a select selectOneMenu where the amount of inputTexts I need to show that, when altered, renders a HtmlPanel. Below are the snippets of code:
* JSF page
<h:selectOneMenu id="qtdeFaixa" styleClass="listbox"
valueChangeListener="#{mapaMB.insertInputTexts}" immediate="true">
<f:selectItem itemValue="1" itemLabel="1"/>
<f:selectItem itemValue="2" itemLabel="2"/>
<f:selectItem itemValue="3" itemLabel="3"/>
<f:selectItem itemValue="4" itemLabel="4"/>
<f:selectItem itemValue="5" itemLabel="5"/>
<f:selectItem itemValue="6" itemLabel="6"/>
<a4j:support event="onchange" reRender="inputTexts"/>
</h:selectOneMenu>
<h:panelGroup id="inputTexts" />
-----------------------------------
* managed bean
public void insertInputTexts(ActionEvent action){
UIComponent group = FacesContext.
getCurrentInstance().
getViewRoot().
findComponent("form1" + NamingContainer.SEPARATOR_CHAR + "inputTexts");
int count = Integer.parseInt(JSFHelper.getRequestParameter("form1" + NamingContainer.SEPARATOR_CHAR + "qtdeFaixa"));
group.getChildren().add(new GeneratePanel().getPanel(count));
DebugUtils.printView(FacesContext.getCurrentInstance().getViewRoot(), System.out);
}
-----------------------------------
* GeneratePanel.java
public GeraPainelInputText(){
init();
}
private void init(){
application = FacesContext.getCurrentInstance().getApplication();
panel = (HtmlPanel)application.createComponent(HtmlPanel.COMPONENT_FAMILY);
panel.setStyle("width:550px");
setComponentes(1);
}
public HtmlPanel getPanel(int qtde){
setComponentes(qtde);
return panel;
}
private void setComponentes(int qtde){
for(int i = 0; i < qtde; i++){
HtmlInputText inputText = (HtmlInputText)application.createComponent(HtmlInputText.COMPONENT_TYPE);
inputText.setId("inputText" + qtde);
panel.getChildren().add(inputText);
}
}
When compiling, I get the following error:
cannot access javax.el.ValueExpression
class file for javax.el.ValueExpression not found
Despite this strange error, I tried this class on the web and found the file jsp-api-2.1-6.0.2.jar. The compilation error was eliminated but gave an error when running the application (one seemed incompatible with the version of Tomcat). Just to test, I created a jarfile contains only this class javax.el.ValueExpression but trying to turn, returns a VerifyError for
"Incompatible argument to function".
My environment:
Tomcat 6.0.16
MyFaces 1.2.5
Richfaces 3.2.2-SR1
Someone could give me an idea of how to proceed?