Attaching parameters to be passed when getters and setters a
lrp Mar 19, 2009 6:05 AMHey there,
I just started using richfaces for our most recent development project, and I've been very pleased with it so far. However, I've run into a tiny snag that I'm hoping someone might know a solution for. I'm using 3.3.0 GA, as well as the most recent version of facelets.
In a given view I present out some data about the currently selected element. The thing about the elements I'm presenting is that they can have an arbitrary number of documentation elements attached to them. In other words, I have to generate a variable number of presentation elements for them. The problem arises when assigning value expressions to each of these presentation elements. In reality a documentation element is composed of two comboboxes and an inputtextarea, but I'll simplify it down to the inputtextarea. I have the following method which generates it:
public void addInputTextarea(UIComponent container, String dokIndex, String valueExpression, String event, String text) { FacesContext ctx = FacesContext.getCurrentInstance(); Application app = ctx.getApplication(); HtmlInputTextarea textarea = (HtmlInputTextarea) app.createComponent(HtmlInputTextarea.COMPONENT_TYPE); textarea.setValueExpression("value", app.getExpressionFactory().createValueExpression(ctx.getELContext(), valueExpression, String.class)); HtmlAjaxSupport ajaxSupport = (HtmlAjaxSupport) app.createComponent(HtmlAjaxSupport.COMPONENT_TYPE); ajaxSupport.setEvent(event); HtmlActionParameter dokIndexParameter = (HtmlActionParameter) app.createComponent(HtmlActionParameter.COMPONENT_TYPE); dokIndexParameter.setName("dokIndex"); dokIndexParameter.setValue(dokIndex); ajaxSupport.getChildren().add(dokIndexParameter); textarea.getChildren().add(ajaxSupport); container.getChildren().add(textarea); }
This method is called an arbitrary number of times as such:
addInputTextarea(tekstGrid, "" + i, "#{skjemaBean.skjemaDocumentationText}", "onkeyup", tekst.getTekst());
i here is the index of the documentation element in the underlying data model element. Since there is an arbitrary number of documentation elements, I was hoping to pass this index to the getSkjemaDocumentationText and setSkjemaDocumentationText methods through value binding, and let them handle the mapping to the data model. That's why I added the following part to the method that creates the text area:
HtmlActionParameter dokIndexParameter = (HtmlActionParameter) app.createComponent(HtmlActionParameter.COMPONENT_TYPE); dokIndexParameter.setName("dokIndex"); dokIndexParameter.setValue(dokIndex); ajaxSupport.getChildren().add(dokIndexParameter);
In the getter and setter I then try to fetch this value using
Map reqMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); String dokIndex = reqMap.get("dokIndex").toString();
However, this ends up with a NullPointerException, indicating that the parameter wasn't passed. I've also tried attaching the parameter to the HtmlInputTextarea element directly, with the same result.
So basically, my question would be: Is there any way to pass parameters to the getter and setter function called as a result of assigning a value expression binding to a UIComponent?