Results 1 to 18 of 18
  1. #1
    dino2dy is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default Multiple Multishuffles

    Hello everyone I use Jdeveloper 11g R2 and have 3 multishuttles on my jsp that are all supposed to refresh when navigation buttons are pressed.

    This means all the multishuttle code should be in a single backing bean, so the navigation button could call the refresh method from that bean, which would refresh all three.

    This is the code I have


    Java Code:
    package view.backingbeans;
    
    
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;
    import view.objekti.utils.JSFUtils;
    import javax.faces.application.FacesMessage;
    import javax.faces.context.FacesContext;
    import javax.faces.event.ActionEvent;
    import javax.faces.event.ValueChangeEvent;
    import javax.faces.model.SelectItem;
    
    import oracle.adf.model.BindingContext;
    import oracle.adf.model.binding.DCBindingContainer;
    import oracle.adf.model.binding.DCIteratorBinding;
    
    import oracle.adf.view.rich.component.rich.nav.RichCommandToolbarButton;
    
    import oracle.binding.AttributeBinding;
    
    import oracle.binding.BindingContainer;
    import oracle.binding.OperationBinding;
    
    import oracle.jbo.Row;
    import oracle.jbo.domain.Number;
    
    
    public class FormShuttle {
      
      private RichCommandToolbarButton Next1;
      
        public FormShuttle() {
            super();
        }
        List selectedFruits;
        List allFruits;
        List selectedTerminali;
        List allTerminali;
        Boolean refreshSelectedList = false;
    
    
        public void setSelectedFruits(List selectedItems) {
            this.selectedFruits = selectedItems;
        }
    
        public List getSelectedFruits() {
            if (selectedFruits == null || refreshSelectedList) {
                selectedFruits =
                        attributeListForIterator("KonekcijeView1Iterator",
                                                 "AdslId");
                    //    attributeListForIterator("TerminaliUObjektuView1Iterator", "TipTerminalaId");
            }
            return selectedFruits;
        }
    
        public void setAllFruits(List allItems) {
            this.allFruits = allItems;
        }
    
    
        public static List attributeListForIterator(String iteratorName,
                                                    String valueAttrName) {
            BindingContext bc = BindingContext.getCurrent();
            DCBindingContainer binding =
                (DCBindingContainer)bc.getCurrentBindingsEntry();
            DCIteratorBinding iter = binding.findIteratorBinding(iteratorName);
            List attributeList = new ArrayList();
            for (Row r : iter.getAllRowsInRange()) {
                attributeList.add(r.getAttribute(valueAttrName));
            }
            return attributeList;
        }
    
        public List getAllFruits() {
            if (allFruits == null) {
                allFruits =
                        selectItemsForIterator("AdslView1Iterator", "AdslId", "TipKonekcije");
            }
            return allFruits;
        }
    
        public static List<SelectItem> selectItemsForIterator(String iteratorName,
                                                              String valueAttrName,
                                                              String displayAttrName) {
            BindingContext bc = BindingContext.getCurrent();
            DCBindingContainer binding =
                (DCBindingContainer)bc.getCurrentBindingsEntry();
            DCIteratorBinding iter = binding.findIteratorBinding(iteratorName);
            List<SelectItem> selectItems = new ArrayList<SelectItem>();
            for (Row r : iter.getAllRowsInRange()) {
                selectItems.add(new SelectItem(r.getAttribute(valueAttrName),
                                               (String)r.getAttribute(displayAttrName)));
            }
            return selectItems;
        }
    
        public void refreshSelectedList() {
            refreshSelectedList = true;
        }
    
        public Number getCurrentPersonId() {
            BindingContext bctx = BindingContext.getCurrent();
            DCBindingContainer bindings =
                (DCBindingContainer)bctx.getCurrentBindingsEntry();
            AttributeBinding attr = (AttributeBinding)bindings.get("ObjekatId2");
            Number personId = (Number)attr.getInputValue();
            return personId;
        }
    
    
        public String processShuttle() {
            BindingContext bctx = BindingContext.getCurrent();
            DCBindingContainer binding =
                (DCBindingContainer)bctx.getCurrentBindingsEntry();
            DCIteratorBinding iter =
                (DCIteratorBinding)binding.get("KonekcijeView1Iterator");
    
            //Removing all rows
            for (Row r : iter.getAllRowsInRange()) {
                r.remove();
            }
    
            if (this.getSelectedFruits().size() > 0) {
                for (int i = 0; i < selectedFruits.size(); i++) {
    
                    Row row = iter.getRowSetIterator().createRow();
    
                    row.setNewRowState(Row.STATUS_INITIALIZED);
                    row.setAttribute("ObjekatId", getCurrentPersonId());
                    row.setAttribute("AdslId", getSelectedFruits().get(i));
    
                    iter.getRowSetIterator().insertRow(row);
                    iter.setCurrentRowWithKey(row.getKey().toStringFormat(true));
                    System.out.println("inside ");
                }
            }
            String ok = doCommit();
            System.out.println("Commit value" + ok);
            return null;
        }
    
      public String doCommit() {
          BindingContainer bindings = getBindings();
          OperationBinding operationBinding =
              bindings.getOperationBinding("Commit");
          Object result = operationBinding.execute();
          if (operationBinding.getErrors().isEmpty()) {
             /*  List errors = operationBinding.getErrors();
              Iterator<oracle.jbo.JboException> iterator = errors.iterator();
              while (iterator.hasNext()) {
                  FacesMessage fm =
                      new FacesMessage(FacesMessage.SEVERITY_ERROR, iterator.next().getMessage(),
                                       null);
                  FacesContext fctx = FacesContext.getCurrentInstance();
                  fctx.addMessage(null, fm);
              } */
    
              return "problem";
          }
          return "ok ki flight";
      }
       
    
    
      public void setSelectedTerminali(List selectedItems) {
          this.selectedTerminali = selectedItems;
      }
    
      public List getSelectedTerminali() {
          if (selectedTerminali == null || refreshSelectedList) {
              selectedTerminali =
                      attributeListForIterator2("TerminaliUObjektuView1Iterator",
                                               "TipTerminalaId");
          }
          return selectedTerminali;
      }
    
      public void setAllTerminali(List allItems) {
          this.allTerminali = allItems;
      }
    
    
      public static List attributeListForIterator2(String iteratorName,
                                                  String valueAttrName) {
          BindingContext bc = BindingContext.getCurrent();
          DCBindingContainer binding =
              (DCBindingContainer)bc.getCurrentBindingsEntry();
          DCIteratorBinding iter = binding.findIteratorBinding(iteratorName);
          List attributeList = new ArrayList();
          for (Row r : iter.getAllRowsInRange()) {
              attributeList.add(r.getAttribute(valueAttrName));
          }
          return attributeList;
      }
    
      public List getAllTerminali() {
          if (allTerminali == null) {
              allTerminali =
                      selectItemsForIterator2("TipTerminalaView1Iterator", "TipTerminalaId", "Naziv");
          }
          return allTerminali;
      }
    
      public static List<SelectItem> selectItemsForIterator2(String iteratorName,
                                                            String valueAttrName,
                                                            String displayAttrName) {
          BindingContext bc = BindingContext.getCurrent();
          DCBindingContainer binding =
              (DCBindingContainer)bc.getCurrentBindingsEntry();
          DCIteratorBinding iter = binding.findIteratorBinding(iteratorName);
          List<SelectItem> selectItems = new ArrayList<SelectItem>();
          for (Row r : iter.getAllRowsInRange()) {
              selectItems.add(new SelectItem(r.getAttribute(valueAttrName),
                                             (String)r.getAttribute(displayAttrName)));
          }
          return selectItems;
      }
    
     {
          refreshSelectedList = true;
      }
    
      public Number getCurrentObjekatId() {
          BindingContext bctx = BindingContext.getCurrent();
          DCBindingContainer bindings =
              (DCBindingContainer)bctx.getCurrentBindingsEntry();
          AttributeBinding attr = (AttributeBinding)bindings.get("ObjekatId2");
          Number objekatId = (Number)attr.getInputValue();
          return objekatId;
      }
    
    
      public String processShuttle2() {
          BindingContext bctx = BindingContext.getCurrent();
          DCBindingContainer binding =
              (DCBindingContainer)bctx.getCurrentBindingsEntry();
          DCIteratorBinding iter =
              (DCIteratorBinding)binding.get("TerminaliUObjektuView1Iterator");
    
          //Removing all rows
          for (Row r : iter.getAllRowsInRange()) {
              r.remove();
          }
    
          if (this.getSelectedTerminali().size() > 0) {
              for (int i = 0; i < selectedTerminali.size(); i++) {
    
                  Row row = iter.getRowSetIterator().createRow();
    
                  row.setNewRowState(Row.STATUS_INITIALIZED);
                  row.setAttribute("ObjekatId", getCurrentObjekatId());
                  row.setAttribute("TipTerminalaId", getSelectedTerminali().get(i));
    
                  iter.getRowSetIterator().insertRow(row);
                  iter.setCurrentRowWithKey(row.getKey().toStringFormat(true));
                  System.out.println("inside ");
              }
          }
          String ok = doCommit();
          System.out.println("Commit value" + ok);
          return null;
      }
    
    
      public BindingContainer getBindings() {
          return BindingContext.getCurrent().getCurrentBindingsEntry();
      }
    
    
        public String previous_action() {
            BindingContainer bindings = getBindings();
            OperationBinding operationBinding = bindings.getOperationBinding("Previous");
            Object result = operationBinding.execute();
            if (!operationBinding.getErrors().isEmpty()) {
                return null;
            }
            refreshSelectedList();
            return null;
        }
        
      
      
    
      public String adslSljedeciButton_action() {
          if(((Boolean)JSFUtils.getManagedBeanValue("bindings.Commit.enabled")) == false) {
              BindingContainer bindings = getBindings();
              OperationBinding operationBinding = bindings.getOperationBinding("Next1");
              Object result = operationBinding.execute();
              if (!operationBinding.getErrors().isEmpty()) {
                  return null;
              }
          } else {
              FacesContext context = FacesContext.getCurrentInstance();
              context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Napravili ste neke izmjene morate ih prvo pohraniti ili povratiti" +
                  " prije nego mozete nastaviti!", null));
          }
        
        refreshSelectedList();
        return null;
    
      }
      public void setNext1(RichCommandToolbarButton Next1) {
          this.Next1 = Next1;
      }
    
      public RichCommandToolbarButton getNext1() {
          return Next1;
      }
    }
    Unfortunately this comes with problems when commiting the values (the refresh works), as the values are not stored in the database, and I get a commit value problem output message. If I put them in separate java classes it works, and will commit for all three, but the refresh button only works for one multishuttle (the one that has the method it uses for action).

    I am a beginner in Java so really any help would be greatly appreciated.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    I don't know adf, and I suspect there aren't many here who do, but this:
    Java Code:
    if (operationBinding.getErrors().isEmpty()) {
        return "problem";
    }
    looks wrong. Surely if there are no errors then there isn't a problem?

    Anyway, I suspect you'd have better luck over at OTN.

  3. #3
    dino2dy is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default Reply

    I have posted at OTN but so far no luck with the answer, I was hoping that this thing I was doing was java, not adf. I mean I implement it in the page using adf but im pretty sure the code was written in Java, thats why I posted here. But as I said I am a total newbie at this stuff so you guys probably know better.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    Except the ADF stuff is (for me) disguising any problems you might be having with your data or queries.

    Oh, and I have no idea what a multishuttle is...which isn't helped by the language issue so I can't even guess at what it is you are doing. That bit isn't, of course, your fault...;)

  5. #5
    dino2dy is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    A multishuttle is just my name for a select many shuttle component, a component that has 2 boxes with lists in them and buttons in between for switching list items between.

    In other words you solve a many to many in that you have in the left list all available items, and in the right selected items. The user can then choose items he selects.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    OK.
    So why do you need an Ajax component?
    Doesn't the user simply save the page once they're happy with the items in the selected box?

  7. #7
    dino2dy is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    There is a save button to save the changes in the database yes but it doesn't work it gives me errors. Also which Ajax component do you mean? Do you mean the Shuttle? The shuttle is the easiest way to give an interface to a many to many relationship which allows users to add and remove items from the intersection table.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    I suspect I'm confusing myself.
    I seem to have mangled two threads together in my head!
    :)

    I have no idea where I got the Ajax thing from...oopsie.

    Right, so you are clicking save and sending the data from the client to the server.
    What data are you getting?
    In fact, what exception are you getting?
    Errors?
    Where from?

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Quote Originally Posted by dino2dy View Post
    I have posted at OTN
    The cross post is at
    OTN Discussion Forums : 3 Multi Shuttles on a page that are all ...

    db

  10. #10
    dino2dy is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    I did some tests. If I comment out (/*, */) everything after the do commit line, so
    from here
    Java Code:
    /*
      public void setSelectedTerminali(List selectedItems) {
          this.selectedTerminali = selectedItems;
      }
    then It works for the remaining shuttle (the fruits one). But something in there is messing it up so that when I press commit, it not only doesn't commit it throws out everything that was in the table (it deletes all data in the intersection table).

    I then tried commenting out partial stuff like the procesShuttle2 and doCommit but even if both are commented out and I put them in a different java class (so I put the 2 commit buttons action attributes to 2 different java classes) it still throws the same error.

    Thing is if I separate them completely, so 2 java classes for two shuttles, it works, the only problem then is navigation, as I can't get one navigation button to refresh both shuttles because there are 2 refresh methods in 2 classes.

    Hope this made some sense (although i doubt it)

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    You still haven't told us what errors you're getting, in any of these situations.

  12. #12
    dino2dy is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    I don't get an error. As I said what happens is that when I press save instead of saving data in the database it deletes the data in the table (not just one row either but all the data).

    Thing is as you can see from the code, there are some println statements that fire for certain conditions and I get an output that says

    Commit valueProblem.

    However even when I had only one shuttle and it worked, it would print out

    inside
    Commitvalue

    I got this code from a blog so not quite sure what the deal is.

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    You're going to need to add more debugging code in there then.
    For example is that "CommitValue" output coming from processShuttle() or processShuttle2()?

    That "Problem" part of the output comes from the code I quoted in my first post.
    The code I thought looked odd.

    But this is all down to ADF or JBO...I can see where you are removing rows, and I think I can see the inserts, and possibly the commit (surely that's not really how you commit with this stuff??), but I can't say more than that.

    ETA: As for code from a blog, don't go copying stuff until you know the technology that it's using.

  14. #14
    dino2dy is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    You don't understand. processShuttle and processShuttle 2 are the same pieces of code. Except for 2 different shuttles. But the code itself is exactly the same, just the variables are changed.
    The guy who has the blog told me this

    "why you are duplicating your code for every shuttle ? yes you can do this in same java class.

    The methods attributeListForIterator and the other one are parameter based so you need to just pass the name of iterator to work.

    Same thing call the refresh method in navigation operations. when refreshSelectedList value will be true your shuttle will refresh

    I think you better look at basics of java before writing code"

    I did copy the code and just put in the variables for the second shuttle, and thats probably the problem but not sure how to solve it.

  15. #15
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    He's quite right, you know.
    This stuff is not basic and if your grasp of the technology here isn't up to scratch then you are not going to get this to work. You're going to have to learn the technology involved. And the problems you are having seem to stem from the db interactions.

  17. #17
    dino2dy is offline Member
    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Default

    Yes you are no doubt right but I don't have time now to devote myself to learning Java. I have to finish this project first and then I should have time to finish this. There was talk of sending me to some courses but so far none of that has materialised and yet I still need to finish this.

  18. #18
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    Well, I hate to say it, but more fool the people who assigned this to you.
    I cannot understand the mentality that seems to think "you know <insert random language here>, so you can rework this piece of code in <insert other random language here>".

Similar Threads

  1. Running multiple threads on multiple CPU cores?
    By Dosta in forum Threads and Synchronization
    Replies: 2
    Last Post: 09-19-2010, 03:48 PM
  2. Use multiple forms
    By coco in forum Java Applets
    Replies: 2
    Last Post: 06-14-2010, 05:14 AM
  3. Multiple Views
    By MrDave in forum AWT / Swing
    Replies: 8
    Last Post: 04-09-2010, 09:20 PM
  4. multiple program
    By mm2236 in forum Threads and Synchronization
    Replies: 2
    Last Post: 10-02-2009, 12:27 PM
  5. Multiple window
    By shoeb83 in forum New To Java
    Replies: 1
    Last Post: 08-30-2009, 10:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •