Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
How to render outputText when inputText is focused or changes value?

I am learning Java EE and I a ran into an issue I can't figure out. I have this xhtml:

<h:form>
            <fieldset>
                <legend>Random Number (with execute="someId")</legend>
                Range:
                <h:inputText value="#{numberGenerator.range}"
                             id="rangeField">
                    <f:ajax event="change" execute="@this"
                            render="numField3"/>
                    <f:ajax event="focus" execute="@this"
                            render="numField3"/>
                </h:inputText><br/>
                <h:commandButton value="Show Number"
                                 action="#{numberGenerator.randomize}">
                </h:commandButton><br/>
                <h2><h:outputText value="#{numberGenerator.number}"
                                  id="numField3"/></h2>
            </fieldset>
        </h:form>

and here is the bean:

package javaeetutorial.ajaxguessnumber;
import javax.faces.bean.*;
@ManagedBean

    public class NumberGenerator  {
        private double number = Math.random();
        private double range = 1.0;

        public double getRange() {
            return(range);
        }

        public void setRange(double range) {
            this.range = range;
        }

        public double getNumber() {
            return(number);
        }

        public double getNumber2() {
            return(Math.random() * range);
        }

        public String randomize() {
            number = range * Math.random();
            return(null);
        }
    }

My question is how can I manage to make the value rendered in outputText whenever the inputText is focused or changes value? So far I only managed to update it when the inputText is focused, but on value change nothing happens.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Try keyup instead of change. The list of supported events are: blur, change, click, action, dblclick, focus, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, mouseup, and select.

This will likely fire a very large amount of ajax events to your server though, so be prepared for that. You'll get an event for every keystroke.

source: https://www.beyondjava.net/a-comprehensive-guide-to-jsf-ajax

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!