首页 文章

JSF 2.2页面,支持bean,页面呈现?

提问于
浏览
0

我有一个要求,即在JSF 2.2页面上输入2个输入值 . 我们正在使用Primefaces控件 . 然后通过h:command按钮将这些值提交给托管bean方法 .

然后,基于这些值,我想在同一个JSF页面上将一个单独的输出字段设置为一个特定的值 .

所以我现在的问题是尝试连接托管bean,以便在我的JSF页面上返回一个返回字段的值,在本例中,字段名称为mgrs . 主要问题是我正在处理的是产生返回值的第三方库,我不确定如何与这个库接口的最佳方法,以便我可以从中返回我需要的值 . 同样从我的JSF页面中,从命令按钮获取bean代码值的最佳方法是什么?

这是我的JSF页面的工作部分

<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" />

这是第三方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 
    };
}

}

1 回答

  • -1

    是的为什么不是很简单 .

    Changes in JSF page

    • 将您的元素放在 <h:panelGrid/> 或类似的组件中 .

    • 给你_2599010_一个 id

    • 使用bean中的变量绑定 <h:outputtext/> .

    • <h:outputtext rendered="#{bean.showOutputBox}" /> 中使用渲染属性

    • 现在在您的按钮中使用 render 属性,并在 Step2 中添加 pandelgrid 的ID

    Changes in Java/bean side

    • 使用 get/set 方法创建变量(布尔值) showOutputBox = false .

    • 当你点击sumbit方法调用bean中的一个动作时,在那个动作方法中使这个(上面)声明变量 true rest JSF会照顾 .

相关问题