Announcement

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

    LinkItem as "mailto" link in dynamic form

    v8.3p_2012-11-29/PowerEdition Deployment (built 2012-11-29)

    LinkItem stops working when it's used in dynamic form as mailto link.

    Code:
    LinkItem mailtoItem = new LinkItem(dsField.getName());
    mailtoItem.setCanEdit(false);
    mailtoItem.setValueFormatter(new FormItemValueFormatter()
    {
                        @Override
                        public String formatValue(Object value, Record record, DynamicForm form, FormItem item)
                        {
                            if (value == null)
                            {
                                return null;
                            }
                            String val = (String) value;
                            if (val.contains("@"))
                            {
                                [b]((LinkItem) item).setLinkTitle(val);[/b]
                                val = "mailto:" + val;
                            }
                            return val;
                        }
    });
    ((LinkItem) item).setLinkTitle(val) inside formatter gives an infinite loop. And without it linkTitile is "mailto:email".
    Is there a way to overcome this issue? Is there a need to run formatter formatValue() method on setLinkTitle?

    I've also tried to override LinkItem's setValue(...) methods, but without any luck, overridden methods are not called.

    TY.

    #2
    setLinkTitle() leads to a re-render which will (correctly) call formatCellValue(). You could avoid this by not calling setLinkTitle() unless you actually applying a new title - the method doesn't automatically no-op in this case.

    About overriding setValue() - the correct approach if you need to be aware of programmatic value changes is a CanvasItem with a ShowValueHandler

    Comment


      #3
      Thank you for your reply.

      So do i understand you correctly:

      There's no other way to setLinkTitle for mailto item, than to extend CanvasItem?

      I don't mean a simple case

      linkItem.setValue("mailto:email");
      linkItem.setLinkTitle("email");

      I mean the case where LinkItem value is set dynamically by for example ValuesManager.fetchData();

      As i mentioned in first message, i've tried calling setLinkTitle inside FormItemValueFormatter and it leads to infinite loop. I've not found any more ways to do it.

      Comment


        #4
        No, CanvasItem is not the only approach. Re-read:

        setLinkTitle() leads to a re-render which will (correctly) call formatCellValue(). You could avoid this by not calling setLinkTitle() unless you actually applying a new title - the method doesn't automatically no-op in this case.

        Comment


          #5
          I'm sorry, I've reread it a couple of times. I don't actually understand you. Can you please be more specific about how to avoid calling setLinkTitle if i need to remove "mailto:" substring from it.

          Do you mean i have to do it in some other handler if LinkItem or something else?

          Comment


            #6
            If getLinkTitle() returns the same string you would pass to setLinkTitle(), do not call setLinkTitle().

            Comment


              #7
              I think there's a misunderstanding between us..

              I'm not trying to pass the same value to setLinkTitile()

              DynamicForm receives value "abc@gmail.com"

              what i am trying to achieve is to set

              value: mailto:abc@gmail.com
              linkTitle: abc@gmail.com

              If i use the FormItemValueFormatter without calling setLinkTitle, than linkTitle is automatically == "mailto:abc@gmail.com".

              So to be clear: without calling setLinkTitle - i have a correct working link, but with incorrect title "mailto:abc@gmail.com".
              Last edited by vostapenko; 3 Dec 2012, 13:52.

              Comment


                #8
                Yes, we understand.

                Every call to setLinkTitle() will result in a call to formatValue().

                So, the first time, you actually do need a call setLinkTitle(), so you call it.

                The second time, you have already changed the link title, getLinkTitle() will return the same value you would pass to setLinkTitle(), so don't call setLinkTitle() and a loop will not occur.

                If you don't understand, just try the suggestion anyway. It's one line of code.

                Comment


                  #9
                  Thanks, i finally got it, very simple. Just break the infinite loop.

                  Sorry for slowpoking, probably, that's because of language boundary.

                  Comment


                    #10
                    Isomorphic, can you please say a few words about HibernateDataSource related questions. As far as i know alius was a developer responsible for the support of such questions and his last activity is a month ago. Is he on some vacation or something or he's not a staff member any more? Should i expect any response on such questions in the near future?

                    I mean the following topics:
                    http://forums.smartclient.com/showthread.php?t=24463
                    http://forums.smartclient.com/showthread.php?t=24439
                    http://forums.smartclient.com/showthread.php?t=24149

                    Thanks a lot.

                    offtopic, can be deleted.
                    Last edited by vostapenko; 3 Dec 2012, 14:16.

                    Comment


                      #11
                      These haven't been ignored, but we can't get you an ETA on a response. Bugs and requests for help from customers with support plans come first, and these vary day by day.

                      Alius is one of several developers who might be assigned to look into any of these. His absence from the forums just means he's working on something unrelated.

                      Comment

                      Working...
                      X