Follow by Email

Tuesday, 16 August 2016

Enable selection and Get selected marker value from dvt:thematicMap in ADF Faces


Hello All

Previously I have posted about using dvt:thematicMap to mark locations using latitude and longitude, In that post I have described about showing different cities as markers on a world map using a POJO based data structure

Now In this post I am going to describe that how can we enable selection in thematic map and get selected location value in managed bean so here in this post I am extending that previous application


dvt:thematicMap looks like this after pointing cities markers


Now to enable selection set selection mode to single for dvt:pointDataLayer and create a selection listener method in managed bean




Now bind dvt:pointDataLayer to bean (Create component binding in Managed Bean)

    private UIPointDataLayer dataLayerBind;

    public void setDataLayerBind(UIPointDataLayer dataLayerBind) {
        this.dataLayerBind = dataLayerBind;
    }

    public UIPointDataLayer getDataLayerBind() {
        return dataLayerBind;
    }

See the generated XML of dvt:thematicMap

<dvt:thematicMap basemap="world" id="tm1" summary="World Map" styleClass="AFStretchWidth"
                                     partialTriggers="::b1" inlineStyle="background-color:#e9ffdc;">
                        <dvt:areaLayer layer="continents" id="al2">
                            <dvt:pointDataLayer id="dl1" value="#{viewScope.MapBean.mapDetail}" var="row"
                                                selectionMode="single"
                                                selectionListener="#{viewScope.MapBean.mapSelectionListener}"
                                                binding="#{viewScope.MapBean.dataLayerBind}">
                                <dvt:pointLocation id="pl1" type="pointXY" pointY="#{row.lattitude}"
                                                   pointX="#{row.longitude}">
                                    <dvt:marker id="m1" shortDesc="#{row.textDisp}" fillColor="#ff0000"
                                                borderWidth="1.0" scaleX="2.0" scaleY="2.0" labelDisplay="on"
                                                labelPosition="bottom" shape="triangleDown" value="#{row.location}"
                                                labelStyle="color:maroon;font-size:10px;"/>
                                </dvt:pointLocation>
                            </dvt:pointDataLayer>
                        </dvt:areaLayer>
                    </dvt:thematicMap>

SelectionListener code to get selected location value

import org.apache.myfaces.trinidad.event.SelectionEvent;
import org.apache.myfaces.trinidad.model.RowKeySet;
import java.util.Iterator;

    /**Method to get selected marker value in Managed Bean
     * @param selectionEvent
     */
    public void mapSelectionListener(SelectionEvent selectionEvent) {
        //getDataLayerBind is binding of dvt:pointDataLayer on page.
        RowKeySet selectedMarker = getDataLayerBind().getSelectedRowKeys();
        //Create iterator from RowKeySet
        Iterator iter = selectedMarker.iterator();

        while (iter.hasNext()) {
            String i = iter.next().toString();
            //LocationDetail is the list used to populate table and name is a column of table
            //So here filter list using index and get values then
            LocationDetail mapRow = mapDetail.get(Integer.parseInt(i));
            FacesMessage msg = new FacesMessage("Selected Marker is: " + mapRow.getLocation());
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    }

All Done :) Run and check application


5 comments :

  1. Hello
    question If possible
    How can I use adf security provided specific column data
    For example :
    No. 1 user can see all the data in which No. 1
    And No. 2 user can see all the data in which No. 2
    Etc ..

    ReplyDelete
    Replies
    1. You can design your quesry using usercode as bind variable and pass user code value in query at runtime . In this way you can get desired result

      Delete
  2. Great technical article. I'd like to feature you in my next article. Promise you can trust my paper review when it happens i'll let you know.

    ReplyDelete
  3. The world map and the selected city within the world map should be marked very well so that the interested people can know.The pro custom writing review will let the people know about the benefits of learning the unknown issues.There are some apps for decorating the apps for arranging the selected cities.

    ReplyDelete
  4. Bingo! I have been hunting this topic for a while. Thanks!

    ReplyDelete