You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by holod <se...@gmail.com> on 2010/11/05 20:17:11 UTC

How to pass date from action to custom jsp tag?

Hello, I want to create simple dummy tag.
I have an action:

class MyAction extends ActionSupport{

  /** Some code*/
  public Department getRoot(){
    /** Some code foes here...*/
    return departmentInstance;
  }
}

a tag:
<%@tag language="java" pageEncoding="UTF-8"  body-content="empty"  %><%@
attribute name="tree" required="true"%><%@ taglib
uri="http://java.sun.com/portlet_2_0" prefix="p"%><p:defineObjects /><%@tag
import="ejb.model.Department"%><%
	Object attrTree = pageContext.getAttribute("tree");
	System.out.println("TreeTagHelper->tree=["+attrTree+"]");
	if(attrTree!=null){
	
System.out.println("TreeTagHelper->tree.class=["+attrTree.getClass().getName()+"]");
	}else{
		System.out.println("TreeTagHelper->tree.class=[!!NULL!!!]");
	}
	try{
	//some code...
	}catch(Exception e){
		System.out.println("Error while drawing tree["+e.getMessage()+"]");
	}
%>

and my jsp with tag:

<pext:drawTree tree="root"/>

What do I have to do if I want to pass result of MyAction#getRoot to my
dummy tag?

I've tried to these:
<pext:drawTree tree="root"/>
<pext:drawTree tree="#{root}"/>
<pext:drawTree tree="${root}"/>
<pext:drawTree tree="%{root}"/>

Nothing happens, i tag I get String with value "root" or get null. 

I can't pass an object to tag attribute... ((((

What do I do wrong?
-- 
View this message in context: http://old.nabble.com/How-to-pass-date-from-action-to-custom-jsp-tag--tp30144287p30144287.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to pass date from action to custom jsp tag?

Posted by holod <se...@gmail.com>.
I've tried it. The problem is solved. You can see solution here:
http://stackoverflow.com/questions/4109125/struts2-pass-actions-method-result-to-custom-tag
-- 
View this message in context: http://old.nabble.com/How-to-pass-date-from-action-to-custom-jsp-tag--tp30144287p30152338.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to pass date from action to custom jsp tag?

Posted by Li Ying <li...@gmail.com>.
The value passed to tag attribute is a simple String.
You have to EVALUATE IT as a expression to get the real value.

You can read the source of Struts2 tag lib to study how they evaluate
the expression.

For example:
in class [org.apache.struts2.components.Property]
(This class is invoked by tag <s:property>)

it calls:
actualValue = (String) getStack().findValue(value, String.class,
throwExceptionOnELFailure);
to retrieve the real value from the value expression

Hope this helps.

2010/11/6 holod <se...@gmail.com>:
>
> Hello, I want to create simple dummy tag.
> I have an action:
>
> class MyAction extends ActionSupport{
>
>  /** Some code*/
>  public Department getRoot(){
>    /** Some code foes here...*/
>    return departmentInstance;
>  }
> }
>
> a tag:
> <%@tag language="java" pageEncoding="UTF-8"  body-content="empty"  %><%@
> attribute name="tree" required="true"%><%@ taglib
> uri="http://java.sun.com/portlet_2_0" prefix="p"%><p:defineObjects /><%@tag
> import="ejb.model.Department"%><%
>        Object attrTree = pageContext.getAttribute("tree");
>        System.out.println("TreeTagHelper->tree=["+attrTree+"]");
>        if(attrTree!=null){
>
> System.out.println("TreeTagHelper->tree.class=["+attrTree.getClass().getName()+"]");
>        }else{
>                System.out.println("TreeTagHelper->tree.class=[!!NULL!!!]");
>        }
>        try{
>        //some code...
>        }catch(Exception e){
>                System.out.println("Error while drawing tree["+e.getMessage()+"]");
>        }
> %>
>
> and my jsp with tag:
>
> <pext:drawTree tree="root"/>
>
> What do I have to do if I want to pass result of MyAction#getRoot to my
> dummy tag?
>
> I've tried to these:
> <pext:drawTree tree="root"/>
> <pext:drawTree tree="#{root}"/>
> <pext:drawTree tree="${root}"/>
> <pext:drawTree tree="%{root}"/>
>
> Nothing happens, i tag I get String with value "root" or get null.
>
> I can't pass an object to tag attribute... ((((
>
> What do I do wrong?
> --
> View this message in context: http://old.nabble.com/How-to-pass-date-from-action-to-custom-jsp-tag--tp30144287p30144287.html
> Sent from the Struts - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: How to pass date from action to custom jsp tag?

Posted by Dave Newton <da...@gmail.com>.
If you're getting the string "root" then the JSP EL isn't being evaluated,
but we don't know which iteration caused that behavior. If you're getting
null, you may be passing null. I'm not sure why you're not just using EL to
get the tag argument in the tag. IIRC you can also define the expected type
of the attribute.

Portlets don't always act like a regular web app, so I'd also make sure what
you're trying to do is possible the way you're trying to do it.

Dave
 On Nov 5, 2010 2:17 PM, "holod" <se...@gmail.com> wrote: