You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Lixin Chu <li...@gmail.com> on 2006/09/13 04:22:56 UTC

calling method of a bean from JSP

Hi,
would like to check if there is existing tag available to allow method
invocation from JSP directly, something similar to this :
"Call JavaBean methods from JSP 2.0 pages "

http://www.javaworld.com/javaworld/jw-05-2003/jw-0523-calltag.html

thanks
lx

Re: calling method of a bean from JSP

Posted by Lixin Chu <li...@gmail.com>.
this should work. thanks !

On 9/16/06, Strachan, Paul <Pa...@det.nsw.edu.au> wrote:
>
> you could move the logic into the view/jsp layer...something like:
>
> <c:forEach items="${item.values}" var="value">
> <c:if test="${value.attribute.id == 'id'}">
>    <c:out value="${value.value}" />
> </c:if>
> </c:forEach>
>
> or maybe a custom tag library...
>
>
>
>
> ________________________________
>
> From: Lixin Chu [mailto:lixin.chu@gmail.com]
> Sent: Sat 16/09/2006 1:25 PM
> To: Struts Users Mailing List
> Subject: Re: calling method of a bean from JSP
>
>
>
> i do not think it works.
>
>
> **********************************************************************
> This message is intended for the addressee named and may contain
> privileged information or confidential information or both. If you
> are not the intended recipient please delete it and notify the sender.
> **********************************************************************
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: calling method of a bean from JSP

Posted by Yujun Liang <yu...@acm.org>.
I only used String as key.

    public Object getStringMapped(String key) {
        return map.get(key);
    }

    public void setStringMapped(String key, Object value) {
        map.put(key, value);
    }



Regards

On 9/18/06, Lixin Chu <li...@gmail.com> wrote:
>
> On 9/17/06, Yujun Liang <yu...@acm.org> wrote:
> >
> > Have you tried "Mapped Properties"?
> > http://struts.apache.org/1.2.9/faqs/indexedprops.html
> >
> > Regards
>
>
> this is a good point. I have not tried it. Is it ok (in terms of
> performance) to use a custom class as the key, not using Java primitives
> like Long ?
>
>


-- 
Yujun Liang
yujun.liang@acm.org

Re: calling method of a bean from JSP

Posted by Lixin Chu <li...@gmail.com>.
On 9/17/06, Yujun Liang <yu...@acm.org> wrote:
>
> Have you tried "Mapped Properties"?
> http://struts.apache.org/1.2.9/faqs/indexedprops.html
>
> Regards


this is a good point. I have not tried it. Is it ok (in terms of
performance) to use a custom class as the key, not using Java primitives
like Long ?

Re: calling method of a bean from JSP

Posted by Yujun Liang <yu...@acm.org>.
Have you tried "Mapped Properties"?
http://struts.apache.org/1.2.9/faqs/indexedprops.html

Regards

On 9/16/06, Strachan, Paul <Pa...@det.nsw.edu.au> wrote:
>
> you could move the logic into the view/jsp layer...something like:
>
> <c:forEach items="${item.values}" var="value">
>   <c:if test="${value.attribute.id == 'id'}">
>     <c:out value="${value.value}" />
>   </c:if>
> </c:forEach>
>
> or maybe a custom tag library...
>
>
>
>
> ________________________________
>
> From: Lixin Chu [mailto:lixin.chu@gmail.com]
> Sent: Sat 16/09/2006 1:25 PM
> To: Struts Users Mailing List
> Subject: Re: calling method of a bean from JSP
>
>
>
> i do not think it works.
>
>
> **********************************************************************
> This message is intended for the addressee named and may contain
> privileged information or confidential information or both. If you
> are not the intended recipient please delete it and notify the sender.
> **********************************************************************
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Yujun Liang
yujun.liang@acm.org

RE: calling method of a bean from JSP

Posted by "Strachan, Paul" <Pa...@det.nsw.edu.au>.
you could move the logic into the view/jsp layer...something like:
 
<c:forEach items="${item.values}" var="value">
  <c:if test="${value.attribute.id == 'id'}">
    <c:out value="${value.value}" />
  </c:if>
</c:forEach>
 
or maybe a custom tag library...
 
 
 

________________________________

From: Lixin Chu [mailto:lixin.chu@gmail.com]
Sent: Sat 16/09/2006 1:25 PM
To: Struts Users Mailing List
Subject: Re: calling method of a bean from JSP



i do not think it works.


**********************************************************************
This message is intended for the addressee named and may contain
privileged information or confidential information or both. If you
are not the intended recipient please delete it and notify the sender.
**********************************************************************

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


Re: calling method of a bean from JSP

Posted by Lixin Chu <li...@gmail.com>.
i do not think it works.

Re: calling method of a bean from JSP

Posted by Laurie Harper <la...@holoweb.net>.
Lixin Chu wrote:
>>
>>
>> What are you trying to achieve? Maybe you're trying to put logic in your
>> JSPs that more properly belongs in an action.
>>
>>
> thanks. what i am trying to do is to get the value of a field. Say I get a
> list of items:
> 
> class item {
> Set values;
> ....
> }
> 
> The item has a set of Values:
> class Value {
> Attribute attribute;
> String value;
> }
> 
> What I wanted to do is to get one particular value based on attribute 
> ID. in
> this case I have to add a method in the Item class, someting like this:
> 
> String getValue (String id) {
>  while (it.hasNext()) {
>     Value value = (value) it.next();
>     if (value.attribute.getId().toString().equals (id)
>        return value.value;
>  }
> 
> So from JSP, I would like to call this method <c:out value="${item.getValue
> (id}"/>

<c:out value="${item.value[id]}"/> ?

L.


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


Re: calling method of a bean from JSP

Posted by Lixin Chu <li...@gmail.com>.
>
>
> What are you trying to achieve? Maybe you're trying to put logic in your
> JSPs that more properly belongs in an action.
>
>
thanks. what i am trying to do is to get the value of a field. Say I get a
list of items:

class item {
Set values;
...
}

The item has a set of Values:
class Value {
Attribute attribute;
String value;
}

What I wanted to do is to get one particular value based on attribute ID. in
this case I have to add a method in the Item class, someting like this:

String getValue (String id) {
  while (it.hasNext()) {
     Value value = (value) it.next();
     if (value.attribute.getId().toString().equals (id)
        return value.value;
  }

So from JSP, I would like to call this method <c:out value="${item.getValue
(id}"/>

Re: calling method of a bean from JSP

Posted by Laurie Harper <la...@holoweb.net>.
Lixin Chu wrote:
> <c:out value="${beanName.methodName}"/>
> 
> I thought this is for getting the value of a property ?  and how to pass a

Yes.

> parameter  to the method ? I think I have tried that but does not work.

You can't invoke arbitrary bean methods with EL; it's designed for 
accessing properties, not calling arbitrary methods. The closest you can 
come is to 'fake' a map-type Foo.getBar(String key) property so you 
could write ${foo.bar[param]}, but that's a bit limitted.

What are you trying to achieve? Maybe you're trying to put logic in your 
JSPs that more properly belongs in an action.

L.


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


Re: calling method of a bean from JSP

Posted by Lixin Chu <li...@gmail.com>.
<c:out value="${beanName.methodName}"/>


I thought this is for getting the value of a property ?  and how to pass a
parameter  to the method ? I think I have tried that but does not work.

Re: calling method of a bean from JSP

Posted by Monkeyden <mo...@gmail.com>.
<c:out value="${beanName.methodName}"/>

or

<c:set var="myVar" value="${beanName.methodName}"/>



On 9/12/06, Lixin Chu <li...@gmail.com> wrote:
>
> Hi,
> would like to check if there is existing tag available to allow method
> invocation from JSP directly, something similar to this :
> "Call JavaBean methods from JSP 2.0 pages "
>
> http://www.javaworld.com/javaworld/jw-05-2003/jw-0523-calltag.html
>
> thanks
> lx
>
>