Building JSF 1.2 Custom Components Using Unified EL and Standard Components

Hi all,

I have built custom components in jsf 1.1 with great success but i am finding replicating the same functionality in jsf 1.2 very difficult. I have some conditions for my new custom component.

- Using jsf 1.2

- Must use unified EL, i am using a UIComponentELTag

- iam using jsf standard html components from javax.faces.component.html here in particular i wont HtmlCommandLink.

Essentially i am constructing a real time command menu. I have a backing bean from which i get command names and descriptions values. I wont to then in real time construct a table of links (using HtmlCommandLink) - all this work is to be processed by a custom component. Basically the HtmlCommandLink issues a command in my backing bean, a parameter (param) is passed with the commandLink, this is later picked up in the backing bean method.

I can generate the table, and all the HtmlCommandLinks, i have simply looped throught and encoded each of them.

What i can do: i can see the table and the HtmlCommandLinks, but the links dont perform any action when i press them.

What i want help with:

I want to encode a HtmlCommandLink in my custom component with a param, traditionally i would set the action but this is now deprecated, and i need to use the setActionExpression method. I have tried to do this but the actions are note fired its simply doesnt function.

Note:

In jsf 1.1 I use to loop through all the HtmlCommandLink and peform their processDecodes method within my custom components very own processDecodes. The same in jsf 1.2 doesnt seem to yield any results.

Can someone give me an example or solution to this? I have read articles on the net and they seem to all discuss jsf 1.1 which i have done and it works, but i am using unifed EL and jsf 1.2 now.

Many Thanks,

Kev

[1861 byte] By [KevOnJa] at [2007-11-26 17:56:05]
# 1

I have given below some ruff code, its not usable but it demonstrates simply what i have done. I would give you the full code except i program of a very very old machines, i dont have the ability to move my work over to this one! Sorry! There maybe some typoes here just ignore them i quickly wrote this up as an aid for you guys.

here goes:

package imports etc.....

public class SomeComponent extends UIComponentBase {

private ArrayList<HtmlCommandLink> links;

public SomeComponent() {

//populate links

//all links are created using the createLink method below

//i can verify that all method and names from backing beans

//are received correctly here so i do not need to test this.

//i can assume that this work safely.

...

}

public void decode(FacesContext context) {

super.processDecodes(context);

}

public void processDecodes(FacesContext context) {

if(links != null) {

for(Object o: this.links) {

HtmlCommandLink link = (HtmlCommandLink)obj;

link.processDecodes(context);

}

}

}

public void encodeBegin(FacesContext context) throws IOException {

ResponseWriter writer = context.getResponseWriter();

...

...

if(links != null) {

for(Object o: this.links) {

HtmlCommandLink link = (HtmlCommandLink)obj;

link.encodeBegin(context);

...

link.encodeEnd(context);

}

}

...

}

public String getFmaily() {

return "SomeComponent";

}

public HtmlCommandLink createLink(Faces Context, String id, String value, String action, UIParameter[] params) {

...

//action is the method binding expression i.e.

// "#{backingBean.method}"

//value is the name of the link i.e. "view"

HtmlCommandLink link = (HtmlCommandLink)application.createComponent(HtmlCommandLink.COMPONENT_TYPE);

link.setType(id);

ValueExpression expression = expressionFactory.createValueExpression(context.getELContext(),value,String.class);

link.setValueExpression("value",expression);

link.setTransient(true);

link.setType("submit");

if(action != null) { //where action is the method in the backing bean method to be called

MethodExpression actionExpression = expressionFactory.createMethodExpression(context.getELContext(),action,String.class,new Class<?>[0]);

link.setActionExpression(actionExpression);

}

if(params != null) {

add params ....

}

link.setParents(this);

return link;

}

}

You may safely assume that all other work and classes needed have been done, this would generate a list of command links! But the actions they should call are not being called infact they do nothing - THE PROBLEM.

Some thoughts:

Is there a problem with the link creation? Is the action not being picked up, i.e the mouse click is not processed? Surely processDecodes solves that, or is there something wrong with the processDecodes method? Remember this is JSF 1.2 and unified EL using setActionExpression.

Is this even possible, i know its quiet new and seems trivial. I can tell you that this in pure jsf 1.1 is easy.

Hope this helps you help me!

KevOnJa at 2007-7-9 5:09:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi,

just to fill you guys in, the code actually works i was using jsf 1.2 support libraries provided by Netbeans 5.5. This is an older version of jsf 1.2 with a few, alot, of bugs.

When i upgraded my libraries to jsf 1.2_03 everything seemed to work fine.

Netbeans should really repackage there product with the latest jsf release.

This one had me pulling my hair out for ages, all i needed was the new updated libraries.

KevOnJa at 2007-7-9 5:09:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Ah yes, I had to learn this lesson with IBM's WSAD. Never trust the IDE's pre-packaged JSF implementation. Always download the version and use it instead.Glad you got it worked out.CowKing
IamCowKinga at 2007-7-9 5:09:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...