Announcement

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

    how to store criteria for a long time

    Hi,

    I need to store some criteria for a long time to use it in requests as parameter several times. Now I can not do it because when my application does several requests the first one criteria becoming garbage. Could you give me an advice, please?

    #2
    Typically this is done by serializing the criteria to JSON.

    You'll have to be more specific about how you got the criteria to become "garbage".

    Comment


      #3
      By "garbage" I mean that there is no specific criteria in Criteria object after several requests.

      Originally posted by Isomorphic View Post
      Typically this is done by serializing the criteria to JSON.
      Could you provide me with an example or reading material please?

      Comment


        #4
        JSON.encode() encodes to JSON.

        There is also an example of saved search on the wiki.

        Comment


          #5
          You are man! Thank you very much!

          Comment


            #6
            Hey, Isomorphic. Could you help me?
            I did:
            Code:
            private String jsonCriteria;
            
            public void onRecordClick(RecordClickEvent event) {             	
                String typ_id = event.getRecord().getAttribute("Typ_id");            	
                criteria.addCriteria("typ_id", typ_id);
                Criteria advancedCriteria = new AdvancedCriteria(JSON.decode(typ_id));
                jsonCriteria = JSON.encode(criteria.getJsObj());    
                groupList.fetchData(criteria);    
            }
            now I want to get this string as criteria or value after I do this method, but I did not sent criteria for server because this is Insert:
            Code:
            saveButton.addClickHandler(new ClickHandler() {
            	public void onClick(ClickEvent event) {
            		dsRequest.setData(jsonCriteria);
            		groupList.setAddOperation("massUpdate");
            		groupList.saveAllEdits();								
            	}
            });
            DMI class:
            Code:
            public class GetCriteriaDMI {
            	public DSResponse dsResponse(DSRequest dsRequest) throws Exception {				
                            // any advice here?
            		return dsRequest.execute();		
            	}
            }
            Code:
            <DataSource ID="groupDS" serverType="sql" tableName="MeasureGr">
            	<fields>
            		<field name="id" type="sequence" hidden="true" primaryKey="true" />
            		<field name="Name" type="text" title="ShortName" /> 
            		<field name="FullName" type="text" title="FullName" />
            		<field name="cmt" type="text" title ="Comment"/>
            	</fields>
            	<operationBindings>
            		<operationBinding operationType="fetch">
            			<tableClause> Column_meta, MeasureGr </tableClause>
            			<whereClause> Column_meta.Typ_id = MeasureGr.Typ 
            			              AND Column_meta.TP = 1 
            			              AND Column_meta.Typ_id = $criteria.typ_id 				
            			</whereClause>
            		</operationBinding>
            		<operationBinding operationType="add" operationId="massUpdate">
            			<serverObject className="kz.factor.measureloader.server.GetCriteriaDMI" methodName="dsResponse"/>							
            			<customSQL>
            				DECLARE @FactorVal INTEGER = (SELECT value FROM bi_settings WHERE param = 'Ediz_factorval')	
            				DECLARE @GrQualityProp INTEGER = (SELECT value FROM bi_settings WHERE param = 'GrQualityProp')							
            				INSERT INTO MeasureGr
            				VALUES($criteria.typ_id, @FactorVal, $values.Name, $values.FullName, '', @GrQualityProp, $values.cmt, '')								
            			</customSQL>		
            		</operationBinding>
            	</operationBindings>	
            </DataSource>
            I need to get $criteria.typ_id or $values.typ_id for insert statement. How can I do this? Maybe Velocity support?

            Comment


              #7
              Hey, Isomorphic

              I am waiting for your answer?

              Comment


                #8
                Please don't follow up so soon; we are sometimes very fast but the actual response time commitments are longer.

                There is no $criteria in an "add" operation. If you want those values they should be part of dsRequest.data. One way to do this would be to use setEditValues() to make them part of the data that is automatically saved by the grid.

                Another, if you already have these values at the server side, would be to add them to the DSRequest in server code.

                Comment


                  #9
                  OK.
                  I know that there is no criteria in add operation. Data which I want to pass doesn't part of the ListGrid. As I said before I need to get some data on server-side.
                  Client-side code:
                  Code:
                  String jsonCriteria = JSON.encode(criteria.getJsObj());
                  dsRequest.setData(jsonCriteria);
                  Now how can I get this data on the server side?

                  Comment


                    #10
                    We just told you:

                    One way to do this would be to use setEditValues() to make them part of the data that is automatically saved by the grid.
                    Once you've called listGrid.setEditValues(), the values will be part of dsRequest.data, so they'll be available via $values just like other values.

                    Note, there'd be no reason to encode to JSON in this case; it would just mean you'd have to decode server-side before you could make use of the data in a SQL template.

                    Comment


                      #11
                      Wait, I can not understand you.
                      Suppose I want to have in DataSource some String value to use it in SQL query. But as I use "add" operation this can not be part of criteria, right?
                      Now how listGrid.setEditValues() can pass this data to dsRequest.data? Could you clarify your answer?
                      setEditValues() method accepts two parameters int rowNum and java.util.Map values. What should I use as input parameters?

                      Comment


                        #12
                        When you call listGrid.saveAllEdits(), it's going to take all the user's changes and put them into the DSRequest as DSRequest.data.

                        When you call listGrid.setEditValues(), you are telling the grid to take the key/value pairs in the Map, and pretend that the user has made those edits. So those values get saved along with other user edits.

                        Make sense?

                        Comment


                          #13
                          Do you mean that?
                          Code:
                          Map<String, Integer> mp = new HashMap<String, Integer>();
                          mp.put("one", 13);
                          mp.put("two", 169);
                          listGrid.setEditValues(1, mp)
                          and user can get this $values.one in SQL template?

                          Comment


                            #14
                            Yes, with that code, when row 1 is saved, $values.one will be available in SQL template.

                            Note that "one" must be a field that exists in the DataSource.

                            Comment


                              #15
                              Originally posted by Isomorphic View Post
                              Note that "one" must be a field that exists in the DataSource.
                              You mean
                              Code:
                              <DataSource ID="groupDS" serverType="sql" tableName="MeasureGr">
                              	<fields>
                              		...
                              		<field name="one" type="text" title ="Comment"/>
                              	</fields>
                                      ...
                              </DataSource>
                              And another question. How can I know which row user is going to edit? For instance, if user will never edit row 1.

                              Comment

                              Working...
                              X