-->

Equivalent of TagUtils.getInstance().lookup() Stru

2019-08-05 16:24发布

问题:

I have this function in Struts 1:

/*
 * (non-Javadoc)
 * 
 * @see org.apache.struts.taglib.bean.WriteTag#doStartTag()
 */
public int doStartTag() throws JspException {

    Carac carac = (Carac) TagUtils.getInstance().lookup(pageContext, name, property, scope);
    // Code here
    return SKIP_BODY;
}

and I am trying to create the same tag in Struts 2 but don't know what's the purpose of this:

TagUtils.getInstance().lookup()

回答1:

I found a solution to get my object from the view to the tag in struts 2 :

my tag :

<%@ taglib uri="wells/taglib/produit" prefix="produit"%>

         <produit:produitPhoto prod="row" />

Here is how t can get it:

  getStack().findValue(this.prod, Produit.class); // return Object Produit

Ref : Class TagUtils



回答2:

Precisely what the documentation says: it returns the named bean's property from the provided scope.