JavaServer Faces: ValueChangeListener doesn't write back to textfield

M

Michael Plate

hello people,

i have an problem and as newbie of javaserver faces i couldn't solve this.

my jsf page have two textfields (textfield1 and textfield2) and i write a
new value at textfield1 and the valuechangelistner should calculate this and
write it back to textfield2. at moment the valuechangelistener works fine,
but i can't write the result of calculation in textfiled2

I couldn't find a similary problem at google. I get many results of
selectOneMenu, but nothing about my problem.

my JSP with JSF-Tags:

<h:inputText value="#{bean.textfield1}"
valueChangeListener="#{bean.textfield1Changed}"
onchange="this.form.submit()"
id="textfield1" converter="javax.faces.Float" size="80">

<h:inputText value="#{bean.textfield2}"
id="textfield2" converter="javax.faces.Float" size="80">

my javabean:
public void textfield1Changed( ValueChangeEvent event) {
float newValue=((Float) event.getNewValue()).floatValue();
// ... calculate newValue and output will back to textfield2

//at this point i haven't an idea to write back
}

Have anyone a idea to resolve my problem.

thank you very much for an answer.

best regards
Michael Plate
 
S

SadRed

hello people,

i have an problem and as newbie of javaserver faces i couldn't solve this.

my jsf page have two textfields (textfield1 and textfield2) and i write a
new value at textfield1 and the valuechangelistner should calculate this and
write it back to textfield2. at moment the valuechangelistener works fine,
but i can't write the result of calculation in textfiled2

I couldn't find a similary problem at google. I get many results of
selectOneMenu, but nothing about my problem.

my JSP with JSF-Tags:

<h:inputText value="#{bean.textfield1}"
valueChangeListener="#{bean.textfield1Changed}"
onchange="this.form.submit()"
id="textfield1" converter="javax.faces.Float" size="80">

<h:inputText value="#{bean.textfield2}"
id="textfield2" converter="javax.faces.Float" size="80">

my javabean:
public void textfield1Changed( ValueChangeEvent event) {
float newValue=((Float) event.getNewValue()).floatValue();
// ... calculate newValue and output will back to textfield2

//at this point i haven't an idea to write back

}

Have anyone a idea to resolve my problem.

thank you very much for an answer.

best regards
Michael Plate

Try immediate="true" for the first h:inputText
 
M

Michael Plate

hello SadRed,

many thanks for your answer. :)

immediate="true" doesn't solve my problem. the effect is same as without
immediate="true". my main problem is to write an value back to textfield2.
this shall happen in bean.

i try out with FacesContext.getCurrentInstance(), but i doesn't find
component 'testfield2'. :-(

best regards
Michael
 
S

SadRed

hello SadRed,

many thanks for your answer. :)

immediate="true" doesn't solve my problem. the effect is same as without
immediate="true". my main problem is to write an value back to textfield2.
this shall happen in bean.

i try out with FacesContext.getCurrentInstance(), but i doesn't find
component 'testfield2'. :-(

best regards
Michael

I forgot to mention that value change listener is
called in the Process Validation phase of JSF
life cycle. So, in your JSF view, immediate should
be false for tf1 and tf2 value update should be
done by calling setValue() method of the component.
And the last line of the listener should be:
facesContext.renderResponse() call.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top