Trying to use actionParameter in backing bean unsuccesfully.
hesher Feb 8, 2010 11:39 AMHi,
I'm trying to use a HtmlActionParameter to report to the backing bean the ID of the button pressed.
The way I do it is have an HTMLPane over HtmlAjaxSupport over HtmlActionParameter.
HTMLPane
\------> HtmlAjaxSupport
\----------> HtmlActionParameter
I expected this to make HTMLPane clickable with AjaxSupport (That worked) and have ActionParam set a value to be used by the function called.
The code that implements this is:
private String currentlySelectedActionButton; public String addActionButton() { // Define Button HtmlPanel button = new HtmlPanel(); String newButtonIndex = Integer.toString(this.actionPanel.getChildren().size()); ExpressionFactory ef = FacesContext .getCurrentInstance().getApplication().getExpressionFactory(); // Add action param to save value ValueExpression ve = ef.createValueExpression( FacesContext.getCurrentInstance().getELContext(), "#{actions.CurrentlySelectedActionButton}", String.class); System.out.println("New Button Index is "+newButtonIndex); HtmlActionParameter actionParam = new HtmlActionParameter(); actionParam.setValue(newButtonIndex); actionParam.setAssignToBinding(ve); actionParam.setName("CurrentButton"); // Define Action Listener MethodExpression me = ef.createMethodExpression( FacesContext.getCurrentInstance().getELContext(), "#{actions.createNewAction}", String.class, new Class[] {}); HtmlAjaxSupport supportObj = new HtmlAjaxSupport(); supportObj.setEvent("onclick"); supportObj.setActionExpression(me); supportObj.setReRender("EditPanel"); // Add new object to action panel supportObj.getChildren().add(actionParam); actionParam.setParent(supportObj); button.getChildren().add(supportObj); supportObj.setParent(button); this.actionPanel.getChildren().add(button); return "Success"; } public String createNewAction() { // Do something with this.currentlySelectedActionButton }
This doesn't work since currentlySelectedActionButton's value doesnt change. (Although createNewAction() is called and tries to access currentlySelectedActionButton, which causes an exception since it is uninitialized.)
I'm wondering what's wrong in this code. Hope that someone has the patience to read my question. :-)
Thank you!
P.S - I'm doing everything from the backing bean since I need the act of adding buttons to be dynamic.