Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Dependent Selects showing the Key of the ValueMap instead of the Value

    All the samples of the Dependent Selects have just a display value. For Example they show

    final Map<String, String[]> departments = new HashMap<String, String[]>();
    departments.put("Marketing", new String[] { "Advertising", "Community Relations" });
    departments.put("Sales", new String[] { "Channed Sales", "Direct Sales" });
    departments.put("Manufacturing", new String[] { "Design", "Development", "QA" });
    departments.put("Services", new String[] { "Support", "Consulting" });


    I am looking for a solution where I can do something like
    departments.put("Marketing", marketingHashMap);
    departments.put("Sales", salesHashMap); etc..
    where the marketing Hashmap for example looks like
    final Map<String, String[]> marketingHashMap = new HashMap<String, String[]>();
    departments.put("A", "Advertising");
    departments.put("C", "Community Relations");

    This way when you choose the Marketing it populates another field that has a valueMap of key value pairs. So it displays the value but saves the key as that actual value of the data. This mostly works in that the display is correct put once i choose it, the grid shows the key instead of the value.

    Anyone know a way to deal with this??

    SelectItem selectItem = new SelectItem();
    selectItem.setAddUnknownValues(false);

    MXListGridField benchmark = new MXListGridField("benchmark", "Benchmark");
    benchmark.setType(ListGridFieldType.TEXT);
    benchmark.setCanEdit(true);
    benchmark.setRequired(true);
    benchmark.setEditorValueMapFunction(valueMap);
    benchmark.setEditorProperties(selectItem);

    protected EditorValueMapFunction valueMap = new EditorValueMapFunction()
    {
    public Map getEditorValueMap(Map values, ListGridField field, ListGrid grid)
    {
    ... String division = (String) values.get("division");
    Map<String, String> divisions = departments.get(division);


    return divisions ;
    }
    };
    but here the divisions has different values of key vs value
    Last edited by rs44; 4 Apr 2017, 13:28.

    #2
    The samples do not actually have this problem, but you could create this problem by, for example, only setting a valueMap on the editor, and not on the ListGridField.

    Comment


      #3
      Thanks Isomorphic but I am still confused. The ListGridField's valueMap is a dynamic based on the EditorValueMapFunction. So how would I set the valueMap on the ListGridField?
      The editor of the item doesn't have a valueMap either because it also would need to be dynamic. So how would I do this?

      These are my 2 gridFields: The benchmarks are based on the currency
      final Map<String, String[]> currencies= new HashMap<String, String[]>();
      currencies.put("1", "USD");
      currencies.put("2", "CAD");


      // Grid Columns
      ListGridField currency = new ListGridField("ccy", "CCY");
      currency.setType(ListGridFieldType.TEXT);
      currency.setCanEdit(true);
      currency.setValueMap(currencies);
      currency.setRequired(true);

      SelectItem benchmarkSelectItem = new SelectItem();
      benchmarkSelectItem.setAddUnknownValues(false);

      ListGridField benchmark = new ListGridField("benchmark", "Benchmark");
      benchmark.setType(ListGridFieldType.TEXT);
      benchmark.setCanEdit(true);
      benchmark.setRequired(true);
      benchmark.setEditorValueMapFunction(benchmarkValueMap);
      benchmark.setEditorProperties(new EditorValueMapFunction()
      {
      public Map getEditorValueMap(Map values, ListGridField field, ListGrid grid)
      {
      String ccy = values.get("ccy").toString();
      return benchmarks.get(ccy );
      }
      });
      the resulting benchmark Map would be something like
      final Map<String, String[]> benchmark= new HashMap<String, String[]>();
      currencies.put("SP", "S&P");
      currencies.put("NS", "Nasdaq");

      With this code, the benchmark column always shoes SP or NS. How do I get it to show S&P or Nasdaq?
      Last edited by rs44; 6 Apr 2017, 09:28.

      Comment


        #4
        You can just use a CellFormatter to dynamically provide values for static display.

        Comment


          #5
          I tried putting a cellformatter on the ListGridField benchmark . It does not work either
          Last edited by rs44; 6 Apr 2017, 09:27.

          Comment


            #6
            Actually, that worked. Thank you!

            Comment

            Working...
            X