0

I have an issue where I have a primefaces outputtext field and from the managed bean, I'm attempting to return an array type back to this field. Something is amiss in that I'm getting no return value back to my outputtext field. I will admit that I'm a bit rusty on my Java coding skills and it could be that I'm not performing something correctly within my bean method with respect to my return value.

My JSF page outputtext field

   <p:panel id="horizontal" header="Conversion from Lat Long to MGRS" toggleable="true" toggleOrientation="horizontal">
     <h:panelGrid columns="2" cellpadding="10" styleClass="left">
  <h:outputLabel for="lat" value="Enter Latitude:" />
            <p:inplace id="lat">
                <p:inputText value="Latitude" />
            </p:inplace>

  <h:outputLabel for="long" value="Enter Longitude:" />
            <p:inplace id="long">
                <p:inputText value="Longitude" />
            </p:inplace>

  <h:outputLabel for="mgrs" value="MGRS conversion value:" />
   <h:outputText id="mgrs"  value="#{coordinates.MGRSCoordreturn}" />

  <p:commandButton value="Submit" update="mgrs" icon="ui-icon-check" actionListener="#{coordinates.mgrsFromLatLon(lat, long)}"/>

 </h:panelGrid>

 </p:panel>

 <h:outputLabel for="mgrs_input" value="Enter MGRS:" />
            <p:inplace id="mgrs_input">
                <p:inputText value="MGRS" />
            </p:inplace>


  <h:outputLabel for="mgrs_output" value="Lat Long conversion values:" />
    <h:outputText id="mgrs_output"  value="#{coordinates.latLongVReturn}" />

  <p:commandButton value="Submit" update="mgrs_output" icon="ui-icon-check" actionListener="#{coordinates.latLonFromMgrs(mgrs_input)}"/>

My managed bean code:

@ManagedBean
@SessionScoped 

public class Coordinates implements Serializable{
private String MGRSCoordreturn;
    private Double LatLongVReturn;

public   String mgrsFromLatLon(double lat, double lon){

       // 37.10, -112.12
    Angle latitude = Angle.fromDegrees(lat);

    Angle longitude = Angle.fromDegrees(lon);

    MGRSCoordreturn = MGRSCoord.fromLatLon(latitude, longitude).toString();
            return MGRSCoord.fromLatLon(latitude, longitude).toString();
}

    public String getMGRSCoordreturn() {
        return MGRSCoordreturn;
    }

    public void setMGRSCoordreturn(String MGRSCoordreturn) {
      this.MGRSCoordreturn = MGRSCoordreturn;
     }

public double[] latLonFromMgrs(String mgrs){

    MGRSCoord coord = MGRSCoord.fromString("31NAA 66021 00000");


            double LatLongVReturn[] = new double[]{ 
        coord.getLatitude().degrees, 
        coord.getLongitude().degrees 
    };

    return new double[]{ 
        coord.getLatitude().degrees, 
        coord.getLongitude().degrees 
    };

    }


     public Double getLatLongVReturn() {
        return LatLongVReturn;
}
     public void setLatLongVReturn(Double LatLongVReturn) {
      this.LatLongVReturn= LatLongVReturn;
     }

 }
  • Please try this without PrimeFaces and you'll see it does not work either. The reason is because, as menthioned in your other question, you **don't** return values from actionListeners and from actions you only return page outcomes... In JSF you assign values to fields in beans and the inputs/outputs in the form and in the page you refer to these fields (like you do with the ``. I'm almost certain the page you use above will throw errors. – Kukeltje Oct 26 '17 at 22:08
  • And as mentioned in the other question, the [PrimeFaces showcase has an very closely related example](https://www.primefaces.org/showcase/ui/data/gmap/addMarkers.xhtml) of your actual case (they use two 'hidden fields' there, but you can do it in one field (comma separated) and split it in the client) – Kukeltje Oct 26 '17 at 22:08
  • @Kukeltje I am getting return value back to my JSF page for MGRS outputtext field. This is working just fine. I'm not sure what you mean by return page outcomes in this context...according to what I've read ajax listeners are more for usage with input and select components. My further understanding is that Action and actionlistener is more for command components and they do return values. Not trying to be obtuse or ignorant but what am I missing here with regard to your comment about return page outcomes. – Mark Griffin Oct 26 '17 at 22:34
  • in `public double[] latLonFromMgrs(String mgrs){` the double[] return value is not common... (I'm surprised it works at all) All in https://stackoverflow.com/questions/3909267/differences-between-action-and-actionlistener return `void`. (Ok sort not identical ones, but still). But what is your problem then if you have a return value? – Kukeltje Oct 26 '17 at 23:46
  • @kukeltje what worked was the first function which is not included in this example which it only returns one value works – Mark Griffin Oct 27 '17 at 02:29
  • @Kukeltje I added the outputtext field and bean code that is working in the form – Mark Griffin Oct 27 '17 at 11:55

0 Answers0