Announcement

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

    fetchRelatedData on foreign key field set as multiple

    SmartGWT 2.2 GPL
    Firefox
    Netbeans 6.9.1
    SmartGWT 2.0.4

    I have two tables parent/child with a relashionship N:N, so a child is linked to many parents.

    I have a foreign key DataSourceField that is multiple:

    Parent:
    Code:
            DataSourceTextField projectID = new DataSourceTextField( "projectID", "ID" );
            projectID.setPrimaryKey( true );
            projectID.setValueXPath( "projectID" );
    Child:
    Code:
            DataSourceTextField projects = new DataSourceTextField( "projects", "Project List");
            projects.setValueXPath( "projects/projectID" );
            projects.setMultiple( true );
            projects.setTypeAsDataSource( pds );
            projects.setForeignKey( pds.getID() + ".projectID" );
    Parent selection refresh handler, which should show all the children bound to the selected parent:
    Code:
            addChangedHandler(
                new ChangedHandler(){
                @Override
                    public void onChanged(ChangedEvent event) {
                        String projectID = ( String ) event.getValue();
    
                        if ( projectID == null ){
                            SC.warn( "value selected was: " + event.getValue() + ", whose"
                                    + " class is " + event.getValue().getClass() + "."
                            );
                            return;
                        }
    
                        final Record project = getSelectedRecord();
    
                        dt.fetchRelatedData(
                            project,
                            pds,
                            new DSCallback(){
                                @Override
                                public void execute(DSResponse response, Object rawData, DSRequest request) {
                                    dt.markForRedraw();
                                    String attributes = "";
                                    for ( String attribute : request.getCriteria().getAttributes() )
                                        attributes += attribute + ": " + request.getCriteria().getAttribute( attribute ) + "\n";
                                    SC.say(attributes);
                                }
    
                            },
                            null
                        );
                    }
                }
            );
    Well, this way of updating works only if the child has one only parent, in fact your representation of an array field with one only entry is equal to the representation of a single field, where on the other side criteria generated by default on the record passed won't match any comma-separated values put in a string.
    Is there a way to fetchRelatedData with a foreign key fieldset as multiple?

    Thank you in advance.

    yary

    #2
    I solved taking advantage of the comma separated representation using an advanced criteria with a convenient reg-exp:

    Code:
                        AdvancedCriteria ac = new AdvancedCriteria(
                            "projects",
                            OperatorId.REGEXP,
                            "^([0-9]+,)*" + project.getAttribute( "projectID" ) + "(,[0-9]+)*$"
                        );
    
                        mt.fetchData( ac );
    If someone knows a cleaner way and is willing to share with me I would appreciate a lot.

    Yary

    Comment

    Working...
    X