Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9291693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:42:31+00:00 2026-06-18T20:42:31+00:00

I have a js-function codeAddress() that processess the data from address and updates the

  • 0

I have a js-function codeAddress() that processess the data from address and updates the values of fullAddress and validField.
The data of fullAddress and validField is passed by <p:ajax> to the backing bean, but the setter methods seem to get called one request delayed.
The alert() at the end of codeAddress shows the correct new data.
When address has onchange="test()" everything works fine an the backing beans setter methods are called as they should without any delay.
I am clueless what might be wrong here.

my jsf code:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<h:head>
        <script src="https://maps.googleapis.com/maps/api/js?v=3&amp;sensor=false"></script>
</h:head>

<h:body>
    <h:outputScript name="jsf.js" library="javax.faces" target="head"/>
    <h:outputScript library="js" name="bugMaps.js" />
    <body onload="initialize()" />
    <h:form id="addressForm">
        <p:inputText id="address" onchange="codeAddress()">
            <p:ajax process="fullAddress validField"/>
        </p:inputText>
        <p:message id="addressValidate" for=":addressForm:validField"/>
        <p:commandButton value="submit" />
        <p:inputText id="fullAddress" value="#{addressBean.fullAddress}" />
        <p:inputText id="validField" value="#{addressBean.valid}" />
    </h:form>

</h:body>
</html>

my JS:

var geocoder;
var map;
var valid = false;
var fullAddress = "none";

function initialize() {
    geocoder = new google.maps.Geocoder();
}

function test(){
    fullAddress = Math.random();
    document.getElementById('addressForm:fullAddress').value = fullAddress;
}

function codeAddress() {
    var address = (document.getElementById('addressForm:address').value + ", Germany");
    geocoder.geocode({'address' : address},function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            var latLong = results[0].geometry.location;
            var latitude = results[0].geometry.location.lat();
            var longitude = results[0].geometry.location.lng();
            var country, postal_code, locality, street_number, route;
            for (i = 0; i < results[0].address_components.length; ++i) {
                var component = results[0].address_components[i];
                if (!locality && component.types.indexOf("locality") > -1)
                    locality = component.long_name;
                else if (!postal_code && component.types.indexOf("postal_code") > -1)
                    postal_code = component.long_name;
                else if (!country && component.types.indexOf("country") > -1)
                    country = component.long_name;
                else if (!street_number && component.types.indexOf("street_number") > -1)
                    street_number = component.long_name;
                else if (!route && component.types.indexOf("route") > -1)
                    route = component.long_name;
            }
            if (typeof latLong != "undefined"
                && typeof latitude != "undefined"
                && typeof longitude != "undefined"
                && typeof route != "undefined"
                && typeof street_number != "undefined"
                && typeof postal_code != "undefined"
                && typeof locality != "undefined"
                && typeof country != "undefined"){
                valid = true;
                fullAddress = results[0].formatted_address;
            }
            else{
                valid=false;
                fullAddress="none";
            };
        }
        else{

            valid=false;
            fullAddress="none";
        }
        document.getElementById('addressForm:fullAddress').value = fullAddress;
        document.getElementById('addressForm:validField').value = valid;
        alert(fullAddress + valid);
    });
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T20:42:32+00:00Added an answer on June 18, 2026 at 8:42 pm

    This is not a duplicate question.
    The first fault was using <p:ajax> to submit data that was to be altered by JS, because the ajax request is already prepared while the script is still running.
    The second mistake was to use the non-cross-browser-compatible jsf.ajax.request.
    Now I simply deleted the <p:ajax> and use a solution with jQuery. This function is simply called from the geocoders callback function:

    function jsfSubmit(){
        document.getElementById('addressForm:fullAddress').value = fullAddress;
        document.getElementById('addressForm:validField').value = valid;
        $.ajax({type:'POST', data:$('#addressForm').serialize(), success: function(response) {
            if(valid){
                var destPage = 'nextPage.xhtml';
                window.location = destPage;
            }
        }});
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a js-function codeAddress() that processess the data from address and updates the
I have function which reads Data out of an Webservice. With that Data i
I have the following code where the function codeaddress geocodes the text feild value
I have function LoadTempMovieList(), and need to load movies from sessionStorage. But it seems
I have function getCartItems in cart.js and I want to call that function in
I have function Start() that is fired on ready. When I click on .ExampleClick
I have function that will generate breadcrumbs format for my category e.g. Root->Children .
i have function that changes background color of element and src of image. in
I have function to unlock data sets via an API function unlockData() { var
I have function in my database class that returns the id of the people

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.