Menu

Passing values between different custom tags

Help
Vatsald
2006-08-28
2013-04-25
  • Vatsald

    Vatsald - 2006-08-28

    Can we pass value of a variable from one custom tag to another? If so, how?

    I have the following scenario -:

    On searching based on few words I get a list of items with each item having an associated checkbox in the form of a table. On setting of checkboxes and submittimg that page I get a list of selected items. I need to verify the title of the selected items and the validate the number of items with the selected items of the previous page. Can this be done with the help of JAmeleon? If yes, how? If possible an example will do a lot of good. 

     
    • Christian Hargraves

      Yes, you can do this.

      net.sf.jameleon.function.FunctionTag.setVariable(String key, Object value) does this.

      http://jameleon.sourceforge.net/apidocs/net/sf/jameleon/function/FunctionTag.html#setVariable\(java.lang.String,%20java.lang.Object)

      There are several examples in the code; one of which is http://jameleon.sourceforge.net/jiffie-plugin/xref/net/sf/jameleon/plugin/jiffie/tags/IEIsTextPresentTag.html

      You then can use the Jameleon javadoc taglets to bind a context variable to an instance variable like so:

      /**
      * @jameleon.attribute contextName="someCntxtVar"
      */
      protected String someVar;

      public void testBlock(){
          System.out.println(someVar);
          // Or you can also simple do this:
          someVar = getVariableAsString("someCntxtVar");
      }

      Does this help?

       
    • Vatsald

      Vatsald - 2006-08-29

      Thanks a lot. Yes, now I can access variables in other tags.

      The scenario I have mentioned in my last post - i need little more help there. I want to pick up text of the item whose checkbox has been selected and store it in a variable so that i can validate it on the next page. Can you tell me how to pick up the text of the item from the TD tag through xpath
      Eg - <td>Jameleon</td> After this there is one more element and afte that checkbox. What my logic is - i go to the location of checkbox using xpath, set it using my custom tag. Now since i want to pick text from TD tag one element earlier, I traverse backward but not not able to pick the text and store it.

       
      • Christian Hargraves

        after you check the checkbox, why don't you just use XPath to get the value of the TD?

        Check out the following functions:

        preceding-sibling
        preceding
        parent

        http://www.w3schools.com/xpath/xpath_axes.asp

        For example:
        //td/input[@checked]/parent::td/preceding-sibling::td[2]

        says, find the given checkbox and, then look for the td parent element two back.

        Try using the XPath Checker plug-in for FireFox to play around with the XPath (https://addons.mozilla.org/firefox/1095/)

        Check out the javadocs on IEFunctionTag for methods that you might use to get the matching text.

        http://jameleon.sourceforge.net/jiffie-plugin/apidocs/index.html

         
    • Vatsald

      Vatsald - 2006-08-30

      I posted a wrong query. I was able to pick up the text.

      I have created a context variable and I am using its value using ${var} in the xml script. But what if I need to use the context variable in the other custom class. Should I use it in the java code using ${var} or should I take a variable in the custom class and pass the context variable value to it?
      As i said in my scenario I need to maintain a List of titles of the selected items and the number of selected items. What I have done is I have created a custom class and defined these two variables as context. Now I need to update their value as and when I am using my other custom class(tag) to select item. How should use them here? Also, now how to use their value in other custom tag which is used to validate the titles and number of selected items on the next page  ?
      Lastly, how to use context variables to validate things in the new child browser window?

       
    • Vatsald

      Vatsald - 2006-08-30

      In more simpler words I want to achieve the following:

      Access the context variable defined in one custom tag in another custom tag keeping in mind that its value is updated each time. For example take the case as defined earlier that increment the count variable everytime a checkbox is set. Lastly, use this count variable in another custom tag to validate the number of selected items. Can we access any context variable in our java custom code using ${var}

       
    • Vatsald

      Vatsald - 2006-08-30

      Please skip my last 2 posts. Don't read them and sorry for creating so much of confusion.

      Help needed for the following scenarios -:

      1. How to use List as a context variable and in the last custom tag you need to take elements from the list and check whether their text is present on the page or not. If i use validate text how i am supoosed to access one particular element of the List? I have used a single String as context varaible and able to validate but facing problem in List.

      2. How do you go from one browser to another child browser window. e.g. There is a main browser, which has a link that opens another browser window. Trigger that link, go to the new browser and verify some contents (e.g. employee name etc) there using context variables from the parent browser.
      What i feel is that it can be done in the same way as above apart from the fact that you need to set focus on new child window. Is this enough or am I missing something?

       
      • Christian Hargraves

        1. If you are writing a custom tag, it should be enough to define the variable as a List. If you pass it a String, the Jameleon will create and put the String as the first element in the List. To get nth element from a List in java:
           String value = (String)listVar.get(0);
        Although I wouldn't recommend making a List for a variable and then making a specific element in the that a special meaning. It will make your tag hard to use and hard to debug for those that don't know exactly what is going on.

        2. This depends on the plug-in you are using. But the basic idea is correct. You just have to tell the plug-in which window to act against. As far as the context variables, they are not window specific; they are script scoped.

         
    • Vatsald

      Vatsald - 2006-08-31

      Thanks a lot Christian.

      1. As I saw in some other thread that "null" is not handled ie every String/List attribute which is required needs some value and doesn't handle null. In my script I was facing the same problem. In the first time use of my custom tag I was passing empty String to the attribute of type list and after that for evry subsequent use of my custom tag I passed "${listing}" to my list attribute where "listing" is my context variable. I have to keep on updating "listing" with titles(my scenario). Passing of empty string was not working, so what I did I passed some arbid string in first use of my custom tag. This worked.
      Anyways, can u look in why even on passing empty string it didn't work?

      2. I don't have any application to test the second scenario I mentioned(parent-child window). So, will be making one application and testing it tomorrow. If any problem I'll contact you.

       

Log in to post a comment.