I didn't know anything about this workaround for a long time and now I even can't remember where I had finally read it. But anyway it can help you if you want to call some function on JSF page with parameter(or even with several parameters) when page is being rendered.
So let's imagine that you want to perform some simple transformation on data which you just got from a bean.
Most likely you want to write an expression like this:
#{myBean.performTransform(myBean.data)}
But this won't work in JSF 1.2. It will work in JSF 2.0 of course but what if you already have a giant application on JSF 1.2.
So finally I found a little bit strange but still very helpful trick. You should write a class which implements java.util.Map interface and you should leave all method except of get method empty. This get method should implement a transform you want to perform. And then you can create an instance of this class and use it in JSF EL on jsp pages. My own code is below:

I didn't know anything about this workaround for a long time and now I even can't remember where I had finally read it. But anyway it can help you if you want to call some function on JSF page with parameter(or even with several parameters) when page is being rendered.

So let's imagine that you want to perform some simple transformation on data which you just got from a bean.

Most likely you want to write an expression like this:

#{myBean.performTransform(myBean.data)}

But this won't work in JSF 1.2. It will work in JSF 2.0 of course but what if you already have a giant application on JSF 1.2.

So finally I found a little bit strange but still very helpful trick. You should write a class which implements java.util.Map interface and you should leave all method except of "T get(Object key)" method empty. This "T get(Object key)" method should implement a transform you want to perform. And then you can create an instance of this class and use it in JSF EL on jsp pages like this:

 

#{myBean.performTransform[myBean.data]}

 

My own code is below:

 

 

DummyMap.java:

 

 

import java.util.Collection;

import java.util.Map;

import java.util.Set;

 

public abstract class DummyMap<T> implements Map<String, T> {

 

    @Override

    public abstract T get(Object key);

 

    @Override

    public int size() {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

    @Override

    public boolean isEmpty() {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

    @Override

    public boolean containsKey(Object key) {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

    @Override

    public boolean containsValue(Object value) {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

    @Override

    public T put(String key, T value) {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

    @Override

    public T remove(Object key) {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

    @Override

    public void putAll(Map<? extends String, ? extends T> m) {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

    @Override

    public void clear() {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

    @Override

    public Set<String> keySet() {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

    @Override

    public Collection<T> values() {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

    @Override

    public Set<Entry<String, T>> entrySet() {

        throw new UnsupportedOperationException("Not supported yet.");

    }

 

}

 

 

MyBean.java:

 

 

public class MyBean {

 

    private String data = "123";

 

    private DummyMap<String> performTransform = new DummyMap<String>() {

        @Override

        public String get(Object key) {

            if (key != null) {

                return "Hello " + key + "!";

            } else {

                return null;

            }

        }

    };

 

    public DummyMap<String> getPerformTransform() {

        return performTransform;

    }

 

    public void setPerformTransform(DummyMap<String> performTransform) {

        this.performTransform = performTransform;

    }

 

    public String getData() {

        return data;

    }

 

    public void setData(String data) {

        this.data = data;

    }

 

}

 

 

So this workaround does not looks right but it can help a lot especially when you have an iteration tag like h:dataTable and you want to perform some simple transfrom on data of current row. I also don't suggest anybody to use a complicated logic or access to DB in your get method either.

 

If someone has any other ideas or approaches for JSF 1.2 which can call functions with parameters from a jsp page, please, write it in comments.

 

P.S. I guess that the same is possible with custom EL functions but I've never seen articles about their creation.