Announcement

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

    ValuesManager.getValuesAsCriteria() missing?

    I'm trying to span a search form over two cells in an HLayout. Four fields on one side and four on the other. I'm using ValuesManager as in the example in the Showcase, but when I attempt to recreate the call from the button to filter a datasourceI have notices that the getValuesAsCriteria is not part of Values Manager ? I assumed that it would take the place of the DynamicForm in this splitting instance ?

    Old code with a single Form:
    Code:
    searchButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (myForm.validate()) {
                myListGrid.filterData(myForm.getValuesAsCriteria());
            }
        }
    });
    Trying to do the same with two forms linked through a ValuesManager:
    Code:
    searchButton.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            if (valuesManager.validate()) {
                myListGrid.filterData(valuesManager.getValuesAsCriteria()); // err?
            }
        }
    });
    Any guidance on this would be gratefully received.

    Al

    #2
    We'll that add API, in the meantime, manually converting to Criteria is required.

    Comment


      #3
      Understood. Will do.

      There appears to be one further issue with the ValueManager which you may want to look into.

      If I have a / character in the name of a form item it breaks the Values Map in the ValueManager, as follows

      Note: the DynamicForm works perfectly with / in the field name, this is only an issue in the ValueManager.

      Code:
      TextItem campusTextItem = new TextItem();  
      campusTextItem.setName("institute/campus");
      ...
      
      searchButtonItem.addClickHandler(new ClickHandler() {  
      	public void onClick(ClickEvent event) {
      		if (vm.validate()) {
      			Criteria criteria = new Criteria();
      			Map formValues = vm.getValues();
      	 		Iterator it = formValues.entrySet().iterator();
      	 		while (it.hasNext()) {
      	 	        Map.Entry pairs = (Map.Entry)it.next();
       	 		GWT.log("VM Keys: " + pairs.getKey() + " = " + pairs.getValue());
      	 	        criteria.addCriteria((String)pairs.getKey() ,(String)pairs.getValue());
      	 	    }
      			myListGrid.filterData(criteria);
      		}
      	}  
      });
      I get the following from the Log
      Code:
      VM Keys: institute = [object Object]
      If I replace the / with an _ as follows it works fine
      Code:
      TextItem campusTextItem = new TextItem();  
      campusTextItem.setName("institute_campus");
      ...
      
      searchButtonItem.addClickHandler(new ClickHandler() {  
      	public void onClick(ClickEvent event) {
      		if (vm.validate()) {
      			Criteria criteria = new Criteria();
      			Map formValues = vm.getValues();
      	 		Iterator it = formValues.entrySet().iterator();
      	 		while (it.hasNext()) {
      	 	        Map.Entry pairs = (Map.Entry)it.next();
      	 	        criteria.addCriteria(pairs.getKey().toString().replace('_','/') ,(String)pairs.getValue());
      	 	 	GWT.log("VM Keys: " + pairs.getKey() + " = " + pairs.getValue());
      	 	    }
      			myListGrid.filterData(criteria);
      		}
      	}  
      });
      I get
      Code:
      VM Keys: institute_campus = abc123
      Could this be fixed at the same time ?

      Comment


        #4
        FormItem.name in general must be an identifier, by luck you have not yet hit the many things your "/" would break. This will be not be changed.

        Comment


          #5
          Originally posted by Isomorphic
          FormItem.name in general must be an identifier, by luck you have not yet hit the many things your "/" would break. This will be not be changed.
          OK, but it breaks the behaviour in the DynamicForm which I thought ValueManager is supposed to mirror. DynamicForm allows the use of / in the name.

          For convenience I am using the xpath path to the source element in the name and this is working well in our use case. I can work around this limitation in ValueManager as shown in the sample, but I see no reason to have DynamicForm and ValueManager behave differently? Can't we simply have ValueManager mirror DynamicForm as the documentation suggests and "developer beware" if the client chooses to go down this route ?

          Out of interest what other aspects of SmartClient would the "/" break ? Your comment sounds quite ominous but provides no explanation.

          Comment


            #6
            Again, it is considered a usage error in both DynamicForm and ValuesManager. The fact that you haven't hit any of the problems it causes does not mean it's supported - it isn't.

            Comment


              #7
              Originally posted by Isomorphic
              Again, it is considered a usage error in both DynamicForm and ValuesManager. The fact that you haven't hit any of the problems it causes does not mean it's supported - it isn't.
              Sure, you have said that but can you explain why? What is it about the / that makes it some problematic?

              Comment


                #8
                Maybe because "/" is a special character in XPath is the reason.

                Comment


                  #9
                  Originally posted by timprice17
                  Maybe because "/" is a special character in XPath is the reason.
                  Agreed, that's the very reason I'm using it. Works brilliantly in my use case. Perhaps not if your using the inbuilt datasources for REST

                  Comment


                    #10
                    Originally posted by Isomorphic View Post
                    We'll that add API, in the meantime, manually converting to Criteria is required.
                    Any success on this one? Or anything like Evaluator.parseAdvancedCriteria(map)?

                    Comment


                      #11
                      Hi,

                      I had the same problem, I miss the criteria related methods on ValuesManager.

                      I used well the ValuesManager.saveData to save data from a form that had a CanvasItem with a nested form with two fields.

                      But now I need to use the same kind of form that has a CanvasItem with a nested form that has two fields (amount and currency) that should support the generation of an advanced criteria like: "amount >= 10.0 and amount <= 20.0 and currency = 'EUR' " or only "amount >= 10.0 and currency = 'EUR' ." depending on a selected operator.

                      How can that be achieved without ValuesManager.getValuesAsCriteria method?

                      When will be release the promised implementation of ValuesManager.getValuesAsCriteria method?

                      Regards,
                      Mihnea

                      Comment


                        #12
                        You actually don't need a ValuesManager to do what you're describing. You can use a standard CanvasItem embedded within a normal DynamicForm. Have this CanvasItem display a DynamicForm with two fields (named, say, "greaterThan" and "lessThan"), and use setCriterionGetter and related methods (setCriterionSetter, setCanEditCriterionPredicate) to assemble your own AdvancedCriteria object based on the values of the inner form.
                        No need for ValuesManager.

                        Comment


                          #13
                          Thanks for the advice. It works well to create the criteria without that missing Value Manager API. There is even a default implementation for a CanvasItem with a nested form with fields, so I didn't have to use the setCriterionSetter.

                          Now I have another problem. I use the Value Manager to set values to the inner fields from the inner form of the CanvasItem.
                          I use valueManager.setValues and that works well.
                          But my field amount depends on the currency field. The amount value is in minor units (like 123) but has to be displayed in major units (like 1,23) depending on the selected currency (like EUR with scale 2). To achieve that I used the FormItemValueFormatter/FormItemValueParser that read the selected currency and make the right transformation to be displayed well in major units and parsed well to minor units.
                          The problem appears when using valueManager.setValues. I set 123 as amount value and EUR as currency, but the amount is not displayed well (should be displayed as 1,23), perhaps because it is set before the currency value.
                          I would need a way to either specify the order of setting those values (first currency then amount) or a hook after the values are set to redraw the amount item.
                          I found only the method CanvasItem.addShowValueHandler, but I don't know if that handler is called after the values managers sets the values to the inner fields (amount and currency). I anyway don't use the CanvasItem value at all. I think I would need something like Form.addSetValuesHandler to add a handler to be called after the form values are set.

                          A similar problem I have with another operator field (equal,between,...) and the amount(s) fields. If operator is set to "equal" I need to show only one amount field, if it is set to "between" then I need two amounts fields (from/to).

                          Could you please advise me on this issue?

                          Thanks,
                          Mihnea

                          Comment


                            #14
                            It's a bit difficult to answer this question definitively given your description. It's not absolutely clear what your code looks like at this point, but here are some reactions:

                            If you have a CanvasItem, the typical usage is that its value will be specified - for example via formItem.setValue(), or dynamicForm.setValues(), and the showValueHandler is a way to specify how that value is displayed within the CanvasItem.

                            For example if you had a field who's data was a string, you could have a CanvasItem with a showValue handler which wrote that string value out into a Label, or an editable field, or whatever.

                            So - if you have a CanvasItem containing a DynamicForm with a couple of sub-fields, you'd typically have code set a value on the CanvasItem, and the showValue handler would handle populating the two fields. That of course would allow you to handle this case - you could set the values of the two sub-fields in whatever order you like, or have some other strategy like storing out a static value indicating the "current currency" which is consulted as part of the formatting logic for the value field.

                            However - it sounds like you're taking a different approach involving ValuesManagers, and setting the values of your inner items directly.
                            In this case presumably you have control over code that calls "setValues()" on the valuesManager. Therefore it would seem that you can handle this yourself in various ways (explicitly call "setValue" on the relevant sub items in the order you need, redraw the form after the values have been set, etc).


                            If this doesn't help you, it might be useful for you to show us a small runnable test case. This would allow us to see your actual component / ValuesManager setup, what your calling code to populate it looks like, and also a clear description of the expected vs actual behavior

                            Comment


                              #15
                              Thank you for such an informative answer.

                              I'm trying to implement an AmountCurrencyItem component that should hide as much as possible the implementation details and to not force each caller to set the values in the right order or to update the form. I would like to do that only once in the component. Is that possible?
                              I didn't find the event/handler to update the form after the values are set. Exists such a handler? If not, is it possible to add it in 3.1?
                              Last edited by mpretorian; 28 Jun 2013, 06:11.

                              Comment

                              Working...
                              X