Announcement

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

    AdvancedCriteria question

    SmartGet 3.0p 1-5-2012 nightly
    Gwt 2.4
    Firefox 6.0

    I have the following scenario...

    Two SectionStackSection- ProjectInfo and Manifest

    In the ProjectInfo stack I created the following form and set it as the stacksections control

    Code:
     DynamicForm pForm = new DynamicForm();
            pForm.setDataSource(projectsDS);
            pForm.setUseAllDataSourceFields(false);
            
            SelectItem project = new SelectItem("ProjectId");
            project.setDisplayField("ProjectName");
            project.setTitle("<font color=\"#FFFF00\">Current Project</font>");
            project.setWidth(400);
            
            ListGridField pName = new ListGridField("ProjectName");
            ListGridField pStart = new ListGridField("StartDate");
            ListGridField pEnd = new ListGridField("EndDate");
            ListGridField pCutOff = new ListGridField("CutoffDate");
            ListGridField pStatus = new ListGridField("ProjectStatus");
            
            
            project.setPickListFields(pName, pStart, pEnd, pCutOff, pStatus);
            project.setDefaultToFirstOption(true);
            project.addDataArrivedHandler(new DataArrivedHandler(){
            	public void onDataArrived(DataArrivedEvent event)
            	{
            		ResultSet rs = event.getData();
            		Record p = rs.get(0);
    
            		eventBus.fireEvent(new ProjectSelectedEvent(p));
            	}
            });
            
            project.addChangedHandler(new ChangedHandler() {
            	public void onChanged(ChangedEvent event)
            	{
            		Criteria criteria = new Criteria();
            		criteria.addCriteria("ProjectId", (Integer)event.getValue());
            		projectsDS.fetchData(criteria, new DSCallback(){
            			public void execute(DSResponse response, Object rawData,
    							DSRequest request) {
            				Record record[] = response.getData();
            				eventBus.fireEvent(new ProjectSelectedEvent(record[0]));
    
    					}
            		});
            	}
            });
    
            pForm.setFields(project);
    
    ....
    ....
    projectInfoSection.setControls(pForm);
    I use the eventBus to pass the fired event to my Manifest which implements the method "projectSelected" shown below.......

    Code:
    public void projectSelected(ProjectSelectedEvent event) {
    		
    		Record projectRecord = event.getProjectRecord();
    		
    		if(ClientSession.getSession().getUser().getUserRole().equals("project_admin"))
    		{
    				   Criterion criteria = new Criterion("ProjectId", OperatorId.EQUALS, projectRecord.getAttribute("ProjectId"));
    				   manifest.fetchData(criteria);
    		}
    		else
    		{
    			AdvancedCriteria criteria = new AdvancedCriteria(OperatorId.AND, new Criterion[]{
    				      new Criterion("ProjectId", OperatorId.EQUALS, projectRecord.getAttribute("ProjectId")),
    				      new Criterion("CompanyId", OperatorId.EQUALS, ClientSession.getSession().getUser().getCompanyId())
    				  });
    			manifest.fetchData(criteria);
    		}
    	}
    So when I go add a user to my Manifest, which is a ListGrid, I have the following customSQL query in my Manifest.ds.xml file...........

    Code:
    		<operationBinding operationType="add" operationId="add_manifest">
    			<customSQL>INSERT INTO manifest (EmployeeId, ProjectId, EmployeeName, Position, DateOfBirth, VisaType, EmbarkDate, DisembarkDate, CompanyId, CabinAssignments) 
    						SELECT A1.EmployeeId as EmployeeId, $advancedCriteria.ProjectId as ProjectId, CONCAT(A1.FirstName, ' ', A1.LastName) as EmployeeName, A1.Position as Position, 
    						A1.DateOfBirth as DateOfBirth, $values.VisaType as VisaType, $values.EmbarkDate as EmbarkDate, $values.DisembarkDate as DisembarkDate, 
    						A1.CompanyId as CompanyId, $values.CabinAssignments as CabinAssignments from employees as A1 WHERE A1.EmployeeId=$values.EmployeeId
    			</customSQL>
    		</operationBinding>
    And when the ListGrid goes to save the user that I had input, it gives me the following error....
    Code:
    20:14:49.595 [ERROR] [mproject] 20:14:49.596:XRP8:WARN:RPCManager:Unknown column '$advancedCriteria.ProjectId' in 'field list', response: {operationId: &quot;add_manifest&quot;,
    clientContext: Obj,
    context: Obj,
    transactionNum: 10,
    httpResponseCode: 200,
    httpResponseText: &quot;//isc_RPCResponseStart--&gt;[{data:&quot;Unknown...&quot;[181],
    xmlHttpRequest: [object XMLHttpRequest],
    transport: &quot;xmlHttpRequest&quot;,
    status: -1,
    clientOnly: undef,
    httpHeaders: Obj,
    isStructured: true,
    callbackArgs: null,
    results: Obj,
    data: &quot;Unknown column '$advancedCriteria.Projec...&quot;[60],
    invalidateCache: false,
    isDSResponse: true,
    queueStatus: -1,
    startRow: 0,
    endRow: 0,
    totalRows: 0}
    
    com.smartgwt.client.core.JsObject$SGWT_WARN: 20:14:49.596:XRP8:WARN:RPCManager:Unknown column '$advancedCriteria.ProjectId' in 'field list', response: {operationId: &quot;add_manifest&quot;,
    clientContext: Obj,
    context: Obj,
    transactionNum: 10,
    httpResponseCode: 200,
    httpResponseText: &quot;//isc_RPCResponseStart--&gt;[{data:&quot;Unknown...&quot;[181],
    xmlHttpRequest: [object XMLHttpRequest],
    transport: &quot;xmlHttpRequest&quot;,
    status: -1,
    clientOnly: undef,
    httpHeaders: Obj,
    isStructured: true,
    callbackArgs: null,
    results: Obj,
    data: &quot;Unknown column '$advancedCriteria.Projec...&quot;[60],
    invalidateCache: false,
    isDSResponse: true,
    queueStatus: -1,
    startRow: 0,
    endRow: 0,
    totalRows: 0}
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
        at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105)
        at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
        at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
        at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
        at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
        at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
        at java.lang.Thread.run(Thread.java:722)
    Is there something that I am missing? Any help would be appreciated. Thanks in advance...

    #2
    This suggests that, despite your attempts, the ProjectId field was not actually sent to the server.

    If you need more help, please show the complete server log for the request (always include this).

    Comment


      #3
      I was actually looking at the wrong piece of code.

      However, the adjustments that I have made have not worked either.
      Below is the relevant code snippets and the error message that I am getting.

      I have a Window that gets displayed when the user selects and "Add" Button that I have available.
      The Window subscribes to the Project Selected event that was previously described.
      The Window also contains a DynamicForm where users are inputting the relevant information and then submitting the form view a "Save" button.

      Below is the Save Button Clickhandler....
      Code:
      newButton.addClickHandler(new ClickHandler() {  
                  public void onClick(ClickEvent event) {
                  	errorText.hide();
                  	if(addUserForm.validate()){
                  		if(embD.getValueAsDate().before(debD.getValueAsDate()))
                  		{
                  			addUserForm.saveData(new DSCallback() {  
      							public void execute(DSResponse response,
      									Object rawData, DSRequest request) {
      								addUserForm.editNewRecord();
      							}  
                          	});
                  		}
                  		else
                  		{
                  			errorText.setValue("Embark must be before Disembark");
                  			errorText.show();
                  		}
                  	}
                  }
              });
      Below is the ProjectSelected function that gets called everytime the eventBus fires the respective event...
      Code:
      public void projectSelected(ProjectSelectedEvent event) {
      		
      		Record projectRecord = event.getProjectRecord();
      		
      		final Criterion criteria = new Criterion("ProjectId", OperatorId.EQUALS, projectRecord.getAttribute("ProjectId"));
      		addUserForm.setValuesAsCriteria(criteria);
      		System.out.println(projectRecord.getAttribute("ProjectId"));
      	}

      So when the "Save" Button is clicked I get an error message on my Tomcat Server...I have attached the errorMessage to not clutter the forum page.

      The Eclipse error message is also attached for further debug info...

      Any help would be appreciated.
      Attached Files

      Comment


        #4
        You seem to be trying to attach Criteria to an "add" operation, that doesn't make sense. Criteria only make sense in update, fetch or remove operations.

        Comment


          #5
          Well heres the scenario that I am trying to accomplish...

          I have a database table that I am using to maintain a list of people on a project. Therefore the following scenario is possible...

          Person 1, Project 1
          Person 2, Project 1
          Person 3, Project 2
          Person 2, Project 2

          I am currently using a ListGrid to display the pertinent project information so I am able to do a ListGrid.fetch(projectCriteria) and it correctly fetches the persons that pertain to the particular project in question.

          However, I also need a way to add people to a particular project, which is what I am trying to accomplish below, albeit perhaps not in the proper way.

          So I created a SelectItem to select the project that I would like to have as the currently "active" project and then use a Form to submit the person to the "active" project.

          So I was trying to use the eventBus to allow the Form know which is the currently "active" project so then I can add person the that project.

          Hopefully, this elaborates a bit more what I am trying to accomplish and a proper suggestion can be made as to how I can accomplish this task.

          Thanks in advance

          Comment


            #6
            Well, the suggestion is the same - criteria on an add operation don't make sense. If what you wanted to do was to set the ProjectId on your new record to a specific value, then just set that value - criteria is not involved.

            Comment


              #7
              It dawned on me the other day what exactly you meant by your comment.

              I finally noticed that DynamicForms have a "setValue" function, which I am now using to solve my problem.

              Thank you for the suggestion, I had completely overlooked that function.

              Comment

              Working...
              X