struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From victor sosa <>
Subject Problem developing a tag using Struts 2 Arch for Tags
Date Mon, 03 Dec 2007 20:58:06 GMT

I am developing a tag, see tag example below. This tag should produce a json
object using the elements into the value stack.

I need to know how to repeat the execution of the content in this case
<jsongl:jsonproperty/> , also every execution need to push a new item into
the valuestack.

So I develop the tag using Component#start() and Component#end() methods,
the tag work but it isn't iterate the list of elements, and only produce
this output with the last element:

"array3": ["m2"]

correct output:

"array3": ["m1","m2"]

tag example:
		<jsongl:jsonarray name="machines" items="%{machine}">
			<jsongl:jsonproperty value="%{code}"/>

source code:
public boolean start(Writer writer) {
        boolean result = super.start(writer);

            if (mItemsPropertySet) {
                // An items property has been set - if there's anything in
it, then iterate over the items
                if (iterator != null && iterator.hasNext()){
            } else {
                // No collection, so just process the body which should add
items to the array
                // Writer passed here is used to prevent any body content
being written to output stream
        } catch (JspException e){
            // Just rethrow if we got a JspException - it's probably from a
nested tag - no new
            // info for us to add here.
            LOG.error("Just rethrow if we got a JspException - it's probably
from a nested tag");
        } catch (Exception e){
            LOG.error("Unable to create JSON array");

        return result;

// end method
public boolean end(Writer writer, String body) {
        boolean result = false; 
        ValueStack stack = getStack();
        if (iterator != null) {

        if (iterator != null && iterator.hasNext()) {
            Object currentItem =;
            LOG.debug("repeat with next element on array body");
            return true;            
        } //else {
            try {
                LOG.debug("Adding a new Json array object to parent
                // Pop the array jsonEntity off of the stack
                // add the child array object to the parent jsonObject
            } catch (JSONException e) {
                LOG.error("Unable to create JSON array object", e);
                // TODO: handle exception
//        }

// helper method
    private void iterateOverItems() throws JspException, IOException {
        ValueStack valueStack = getStack();
        // Iterator over 'items' collection
        while (iterator.hasNext()){
            Object currentItem =;
            LOG.debug("item: " + currentItem);

View this message in context:
Sent from the Struts - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message