Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

UIComponent.getAttributes() and EL attributes

843844Sep 19 2007 — edited Sep 20 2007
Hi all,

Long term developer - newish to JSF - I've come across the same issue as many other people relating to EL expressions in UIComponent attributes, but can't find an answer (e.g http://forum.java.sun.com/thread.jspa?forumID=427&threadID=782895 is almost the same question but is unanswered).

The problem is this: -

I believe UIComponent.getAttributes() implements the weirdest Map I've ever used. Yes, I've read the Java Docs and bits of the various specs - but it doesn't help me understand where my EL component attributes go.

I don't believe the implementations of UIComponent.getAttributes() can be the best solution - I've tried a number of different versions/impl's and they all do similar things... I'm obviously missing something - help!

Details: - If I have a JSF as follows: -

-----
<h:form >
<c:set var="variable" value="TODAY"/>
<h:commandButton actionListener="#{bugbean.action}">
<f:attribute name="attr1" value="constant-string" />
<f:attribute name="attr2" value="#{variable}" />
</h:commandButton>
</h:form>
-----
and in the backing bean "bugbean" I have the following...

-----
public void action(ActionEvent event){

System.out.println("JSF <f:attribute/> test started");

UIComponent comp = event.getComponent();

Map stuff = new HashMap();
stuff.putAll(comp.getAttributes());
System.out.println("UIComponent.getAttributes() as a Map ["+stuff+"]");

System.out.println("UIComponent.getAttributes().size() reports ["+
comp.getAttributes().size()+"]");

System.out.println("UIComponent.getAttributes().get(\"attr1\") reports ["+
comp.getAttributes().get("attr1")+"]");

System.out.println("UIComponent.getAttributes().get(\"attr2\") reports ["+
comp.getAttributes().get("attr2")+"]");
}
-----
I get the following output: -

-----
JSF <f:attribute/> test started
UIComponent.getAttributes() as a Map [{attr1=constant-string, com.sun.facelets.MARK_ID=271e6d86}]
UIComponent.getAttributes().size() reports [2]
UIComponent.getAttributes().get("attr1") reports [constant-string]
UIComponent.getAttributes().get("attr2") reports [TODAY]
-----
Note:
1) UIComponent.getAttributes().size() reports 2. That's the "com.sun.facelets.MARK_ID" (added by JSF) and "attr1" elements of the Map.
2) There is no mention of "attr2" - but I know I put it in there...
3) I can call UIComponent.getAttributes().get("attr2") and guess what - hey presto - it works and I get my value! It appears that UIComponent.getAttributes() just hides my EL attributes somewhere else... but where and why?

The issue I have is simple: -
I have never used a Map that reports a size of "x", but actually contains "hidden" elements that I can't find unless I already know the name of the element. And the weird behavior depends only on the "value" of the element being an EL expression.

I have read the many, many threads on many sites relating to the JSF 1.1 spec being "fluffy" over the implementation of UIComponent.getAttributes() - it hasn't helped me understand what is going on.

Have I missed something or is this just the way it's supposed to work?

Thanks in advance...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 18 2007
Added on Sep 19 2007
5 comments
252 views