0

I want to save the variable "position" in my BEAN, does anyone know how to do this? I'm starting in javascipt.

 function placeMarker(position, map) {
      var marker = new google.maps.Marker({
        position: position,
        map: map
      });
      map.panTo(position);
      alert(position);

    }

1 Answers1

0

The best way to do this is to include an <h:inputHidden> component on the page on the page and assign its value through the use of Javascript. When you bind the hidden input to a managed bean property then the next time this inputs form is submitted to the server it will apply its request value to the managed bean property.

<h:form id="googleMapForm">
  <h:inputHidden id="positionInput" value="#{managedBean.positionProperty}" />
  <h:commandButton id="myButton" value="Submit" />
</h:form>

In javascript if you know the ID of the positionInput on the page then you can get it in jQuery.

var positionVar = jQuery('#googleMapForm\\:positionInput');
if (positionVar) {
  positionVar.val(position);
}

If you execute this script before submitting the form then the value of position should be applied to the managed bean property.

maple_shaft
  • 10,435
  • 6
  • 46
  • 74