Reputation: 3
I am developing a functionality in my jsf application, which should retrieve the lat and lon of places from the database and plot it in Google map. Since gmaps4jsf library is not updated with google maps java script api v3, i'm using google maps java script api as it is. The problem is that I can't call the script to plot the place in map after retrieving the lat and lon (via jsf).
What is the solution to this problem?
Upvotes: 0
Views: 775
Reputation: 1109422
Just let JSF print it as if it's a JS variable.
<h:form>
<h:commandButton value="Submit" action="#{bean.submit}" />
</h:form>
<h:outputScript rendered="#{not empty bean.lat and not empty bean.lon}">
var lat = #{bean.lat};
var lon = #{bean.lon};
initializeMapSomehowWith(lat, lon);
</h:outputScript>
(the <h:outputScript>
generates a HTML <script type="text/javascript">
element, if you're still on old JSF 1.x, use <h:panelGroup><script>
instead and also <h:outputText>
instead of EL in template text)
with something like
public void submit() {
lat = 12.106173;
lon = -68.935304;
}
Remember: JSF basically generates HTML. JS is part of HTML response.
Upvotes: 2