Problem with binding values to jsf h:inputTextArea - Websphere
This is a discussion on Problem with binding values to jsf h:inputTextArea - Websphere ; Hi,
I am a fairly new to jsf, and have a seemingly simple problem that is proving very difficult.
I have an h:inputTextArea on a page that I want to use to initially display a value from a database, and ...
-
Problem with binding values to jsf h:inputTextArea
Hi,
I am a fairly new to jsf, and have a seemingly simple problem that is proving very difficult.
I have an h:inputTextArea on a page that I want to use to initially display a value from a database, and if I change it
to then store that new text back in the database.
Writing the value entered is easy. I just have a button woth a doButtonAction method that takes the value from the h:inputtextarea and writes it to the database.
To display the current value when I first enter that screen I thought I would bind the h:inputTextArea value to a bean which gets the current value out of the db.
It works fine on the initial load of the page.
The problem is if I make a change to the text and submit it only saves the old text again, because the existing value bound to it seems to override any text I type in the h:inputTextArea.
So I thought I should not bind the bean to it and just initialize the value when the page loads, but I haven't been able to work out how.
I tried putting initialization code in a constructor for the backing bean, but that doesen't seem to work and often results in problems.
The other way I was thinking was to somehow get the new text only from the input not its value, but h:inputTextArea doesent seem to have a property for this.
I'm sure this must be a common problem, so there must be a solution for this somewhere. But I cant seem to find anything.
If anyone has any ideas I would love to hear them. We are using jsf 1.1
Regards
Bill
-
Re: Problem with binding values to jsf h:inputTextArea
OK I found a solution.
getTextarea1().getValue().toString() kept returning the old value.
So I had to use request.getParameter("parameterName") to get the true value
The parameter name changes with every request because of the changing namespace appended to it.
I couldn't find a way to get just the namespace. There's probably a way but I didn't have time.
So to get the parameter name I had to access the parameter names in the external context.
Iterator it = getFacesContext().getExternalContext().getRequestP arameterNames();
This is a bit of a kludge but it was the only way I new to get the textarea1 parameter name
while(it.hasNext()){
String requestParameterName = (String)it.next();
if(requestParameterName .endsWith("textarea1")){
parameterValue = request.getParameter( requestParameterName );
}
}
So request.getParameter( requestParameterName ) returns the edited text.
Regards
Bill