Announcement

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

    Does Smartgwt have an Anchor widget?

    I'm porting code I've written in GWT to use Smartgwt instead. In GWT, an Anchor widget allows me to set a URL such as "http://www.wikipedia.com" and a title suck as "Click here for Wikipedia", and then the title is shown on the panel with an underline, and if it is clicked-upon, a new browser tab is opened to the associated URL. I can't find any such feature in Smartgwt. Any hints you can provide on where to find this ability or how to emulate it will be greatly appreciated. I thought LinkItem would do it, but that just gets me as far as a being able to associate a click handler that will get called when the user presses on the link, it doesn't open a new tab and go to a specified URL. Thanks for answering my question. - Jim Waschura

    #2
    You can use a LinkItem as the only item of a DynamicForm.

    Comment


      #3
      Whether I create an additional DynamicForm to put only this one LinkItem in it, or whether I just add the LinkItem to an existing Dynamic Form (which is what I was doing before), the behavior is the same. I do not launch another tab on my (Chrome) browser, and I don't go the URL which I've set in the LinkItem object using the setValue() method.

      (1) I see the Showcase example for LinkItem but this only implements a click handler than performs an SC.say() call. Notice this is not what I want to do. I don't want a pop-up dialog message. I want a separate tab to open on my browser and to go to that URL on that new tab of the browser.

      (2) In GWT, I use the following, which performs the way I want it to:

      Anchor Linkto = new Anchor();
      Linkto.setText("Click Me");
      Linkto.setHref("http://www.wikipedia.com");

      (3) In SmartGWT, I am currently using code like this, which doesn't work, though it does display the link on the screen and you can click it and most-likely if I added a Click Handler it would call the click handler when the link was pressed:

      LinkItem Linkto = new LinkItem("title");
      Linkto.setLinkTitle("Click Me");
      Linkto.setValue("http://www.wikipedia.com");

      DynamicForm form = new DynamicForm();
      form.setFields(Linkto);

      getPortlet().addItem( form );

      (4) Do you have any example code for how to use LinkItem to open a new tab on the browser and go to a specified URL?

      Thank you, Jim Waschura

      Comment


        #4
        Hi Jim,

        how about a ClickHandler with com.google.gwt.user.client.Window.open("URL", "_blank", "")?
        I have the same for some of my ListGridFields.

        Best regards
        Blama

        Comment


          #5
          Start by reading the docs for LinkItem. Multiple forms of activation are supported, some of which just run event handlers and some behave like a normal HTML link.

          Comment


            #6
            Blama - Very promising results, Thank you. I can make this work to go to "http:\\mercurynews.com" but I can't get this to work to go to "file:\\\c:" or "file:\\192.168.1.123\Share" which is what my ultimate objective is. Have you use the Window.open() for protocols other than http: ?

            Administrator - Thank you for your advice. Maybe I am not aware of some level of documentation that I ought to be aware of. Of course I have read the entire documentation on the LinkItem class in the Javadoc format, which is what gave me the impression this would work. The class description says:

            A form item that displays a URL. In the default read-only mode (canEdit is false) the URL is shown as a link; in editable mode the URL is shown in a textbox. The link to open is specified as the item value with FormItem.setValue() or FormItem.defaultValue. The link title defaults to the URL unlesslinkTitle is specified.

            Based on this, I followed these instructions but it didn't work. Can you tell me please, is there more documentation available for situations like this? An overview of how to use the object - not just what the interfaces are - would be helpful. Thank you again,

            Jim Waschura





            Comment


              #7
              Is that intended as humor? You quoted the class description, then omitted the last sentence, which tells you what you wanted to know about what the link targets. You read only 4 of the 5 sentences then critiqued the docs?? :)

              Also, what are you expecting those file URLs to do? Cause files on the end user's machine to be opened when clicked?

              Comment


                #8
                Sorry I didn't include the last sentence because setTarget() does not appear to be the API to set the URL destination. I believe the setValue() is the correct API, and I am now able to make it work if I use setValue() and assign a URL prior to adding the item to the dynamic form and adding the form to the portlet and rendering the portlet. I believe my trouble stemmed from changing the URL after the portlet had been rendered, which is something I do because the URL is dynamic and I don't know it at the moment of construction. If I use setValue("http:\\mercurynews.com") at construction time, then when I click on the link, another tab is opened and it displays the mercury news website as I expect.

                Two issues:

                (1) Generally I don't know the URL at the moment of construction and so I'd like to change it later. Is there a way to do this, or should I remove the item and rebuild the form and portlet contents whenever I need to update the URL. - How do I change the URL after construction?

                (2) Even when I create the URL contents at construction time prior to rendering the portlet, if I use setValue( "file:///C:/" ) it doesn't open a tab or display the root folder, like the browser does if you type in this URL directly (try it). On Chrome/Windows, this displays a listing of the contents of the root folder entitled, "Index of C:". Is there anything I can do to allow the use of URL's with the "file://" protocol? I tested it with a setValue("mailto://jim.waschura@gmail.com") and that launched the gmail web site as I expected. - Is there a way to specify a URL utilizing the "file://" protocol?

                Attached is an example of what the browser shows when I use the file:// protocol and specify a folder, for example: "file://zorro/stash".

                Thank you for helping me with this.

                - Jim Waschura



                Background:

                I'm working on a small device that performs electronic testing. The device has an embedded SOC running embedded Linux (Fedora) which is connected to a custom hardware design that connects to high speed (54 Gbits/sec) communications channels and tests them for errors. The device also has a solid-state disk where errors can be captured to. The Linux is running a Samba server to create a network share of the folder containing the captured files. The SOC is also running apache web server and a tomcat server and it serves the website I'm building with Smartgwt as the user interface capable of supporting multiple simultaneous clients. When first connected, the website can ask a custom hardware server running on the Linux machine for its LAN IP address using the RPC features from GWT (basically AJAX). When this information is returned, I can build a string like "file://192.168.1.123/Share" which I want to provide as a link on the user interface so users can click and quickly get to a browser page that shows the contents of the share. - FYI



                Click image for larger version

Name:	gui.png
Views:	152
Size:	158.9 KB
ID:	238126
                Attached Files
                Last edited by jimwaschura; 20 May 2016, 18:19.

                Comment


                  #9
                  1. Call setValue() again

                  2. Can't be done, disallowing this is a browser security feature. You need a system for returning that data via http

                  Comment


                    #10
                    Originally posted by Isomorphic View Post
                    You can use a LinkItem as the only item of a DynamicForm.
                    Is there a way to get the LinkItem to show an old-school "visited" style after it's clicked? (e.g., purple font?)

                    Comment


                      #11
                      For links that are actually ordinary links (not JavaScript / Java actions) you could define the :visited selector in CSS to define a color for a visited link.

                      Comment


                        #12
                        Sorry, we misspoke. For links with a target other than "javascript", the link will automatically go purple if the target has been visited, just like a normal link.

                        For "javascript" links, the browser does not track whether a link is "visited" or not (since such links often represent actions). If you wanted to have a notion of a "javascript" link having been visited, you'd have to track the visited state yourself, and apply CSS to the LinkItem to make it purple.

                        Comment

                        Working...
                        X