Hi there

I am very new in useing jsp but here is my first problem. I registered a bean in the applicationContext.xml with the id myBean. Now I want to call a function like this

${myBean.myFct}

but the function does not exist and it should not. In PHP there exists a Method __call which will be executed with the method name and args where the invoked method does not exist. It's something like a fallback before the error occures (http://www.garfieldtech.com/blog/php-magic-call). Is there may something similar in JSP? I looked at the source (http://kickjava.com/src/org/apache/myfaces/el/PropertyResolverImpl.java.htm) but i dont finde something like that.

Thanx for every answer!

Dominic

I found a way that works for me.. I saw in ResolverImpl.java that if the Bean is a Map, the Method get will be invoked.

public Object JavaDoc getValue(Object JavaDoc base, Object JavaDoc property) throws EvaluationException, PropertyNotFoundException
{
  try
  {
    if (base == null || property == null || property instanceof String JavaDoc && ((String JavaDoc)property).length() == 0) {
      return null;
    }
    if (base instanceof Map JavaDoc)
    {
      return ((Map JavaDoc) base).get(property);
    }
    // If none of the special bean types, then process as normal Bean return getProperty(base, property.toString());
  }
  catch (RuntimeException JavaDoc e)
  {
    log.error("Exception getting value of property " + property + " of bean " + base != null ? base.getClass().getName() : "NULL", e);
    throw e;
  }
}

Because of that i inherite my Bean from a Map and override that Method. It's a hack i know but it seems to work. But anyway your replies are still very interesting. There should be a better way.

Dominic

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.