Discussions

Web tier: servlets, JSP, Web frameworks: Accessing Body Elements in Custom Action Code

  1. Accessing Body Elements in Custom Action Code (1 messages)

    I have experience with Java and EJB, but I am only now starting to get into JSP. I am exploring the power of custom actions. I am trying to figure out how to access body elements within the code for the action.

    I am not sure if this is even possible, but consider this JSP fragment:

    (Assume the prefix "abc" has been mapped to some uri above)

    <abc:process name="foo">
       <abc:child>
           <abc:c1>Test1</abc:c1>
           <abc:c2>Test1</abc:c2>
       </abc:child>
       <abc:child>
           <abc:c1>Test2</abc:c1>
           <abc:c2>Test2</abc:c2>
       </abc:child>
    </abc:process>

    I could have any number of "child" elements, so trying to force the values for "c1" and "c2" into attributes isn't a viable option. So how can I reference the values for "c1" and "c2" in the Java class extending SimpleTagSupport? In other words, how can my action class know that the value for the "c1" child of the first "child" element is "Test1"?
     
    Moreover, does this example even make sense? It may be that the "child" elements aren't even allowed because they aren't valid HTML (though they are valid XML).

    As you can see, I am very much a novice. Any insights are appreciated.

    Thanks very much.
  2. No, the example does not make sense at all. What are you using the child elements for? It looks like you're tyring to use them like an array. That's not really what they're for.
    Take a look at the Struts tag library, or any other tag lib and see what they're doing.