Reputation: 1
I have a requirement where 2 input values are entered onto JSF 2.2 page. We are using Primefaces controls. These values are then submitted to managed bean method via h:command button.
Then, based upon the values, I want to set a separate output field on the same JSF page to a specific value.
So my issue at the moment is trying to wire a managed bean so that it returns a value back to field on my JSF page which in this case field name is mgrs. The main issue is that I'm dealing with is the third party library that produces the return values and I'm not sure the best approach on how to interface with this library so that I can return the values that I need from it. Also from within my JSF page what would be the best approach from the commandbutton to get the value back from the bean code?
Here is the working portion of my JSF page
<p:panel id="horizontal" header="Horizontal Toggle" toggleable="true"
toggleOrientation="horizontal">
<h:panelGrid columns="2" cellpadding="10" styleClass="left">
<h:outputLabel for="basic" value="Enter Latitude:" />
<p:inplace id="lat">
<p:inputText value="Latitude" />
</p:inplace>
<h:outputLabel for="basic" value="Enter Longitude:" />
<p:inplace id="long">
<p:inputText value="Longitude" />
</p:inplace>
<p:inplace id="mgrs">
<p:inputText value="Longitude" />
</p:inplace>
<h:commandButton actionlistener="#{coordinates.mgrsFromLatLon(lat, long)}" update="mgrs" />
Here is the third party API:
package com.berico.coords;
import gov.nasa.worldwind.geom.Angle;
import gov.nasa.worldwind.geom.coords.MGRSCoord;
import javax.faces.bean.ManagedBean;
@ManagedBean(name="coordinates")
public class Coordinates {
public static String mgrsFromLatLon(double lat, double lon){
Angle latitude = Angle.fromDegrees(lat);
Angle longitude = Angle.fromDegrees(lon);
return MGRSCoord
.fromLatLon(latitude, longitude)
.toString();
}
public static double[] latLonFromMgrs(String mgrs){
MGRSCoord coord = MGRSCoord.fromString(mgrs);
return new double[]{
coord.getLatitude().degrees,
coord.getLongitude().degrees
};
}
}
Upvotes: 0
Views: 1106
Reputation: 13492
Yes Why not its quite simple.
Changes in JSF page
<h:panelGrid/>
or something similar component.id
to your <h:panelGrid id="panelID"/>
<h:outputtext/>
with a variable from your bean.<h:outputtext rendered="#{bean.showOutputBox}" />
render
attribute and give id of pandelgrid
which added in Step2 Changes in Java/bean side
Create a variable(boolean) showOutputBox = false
with get/set
method.
When you click on sumbitmethod call a action in bean ,in that action method make this(above) declare variable true
rest JSF will take care.
Upvotes: -1