JSF ui issue: composition and component

I am trying to find out if this is a JSF / EL problem or something is wrong.

Basically, I wanted to pass the item object as ui: param for the composition ui: and you have a button inside (for example, boot buttons, so they are actually html links, so use commandLink) and execute the action using the parameter param. Here ui: the composition of item.xhtml is passed to some parameters.

<ui:include src="comp/item.xhtml"> <ui:param name="item" value="#{itemVM.item}"/> <ui:param name="desc" value="#{true}"/> </ui:include> 

Now I want this button to be a component of "bt: button", however, it seems that the problem is related to the "item" parameter. To confirm this, I pulled out the command link from the component and placed it on the page, and of course it worked. Also, if I move the bt: button outside of ui: it works too. Finally, if I modify an element as a string using single quotes of the โ€œtestโ€ type, it also works (for testing purposes, my action method takes an object). Based on these three cases, it seems that the composite component has problems resolving the parameter of the element passed to the composition.

Here's an example of a 1st test (i.e., a composite component erases a regular JSF command link) inside item.xhtml:

 <!- This composite component doesn't Work --> <bt:button id="cmpBtn" active="#{user.compares[item.id]}" disabled="#{user.compares[item.id] != null and itemsCtr.numOfCompares >= 100}" styleClass="btn-item-compare btn-small" style="margin-bottom:5px" action="#{itemsCtr.compare(item)}"> <i class="#{user.compares[item.id] != null ? 'icon-minus' : 'icon-plus'}"/> <h:outputText value="#{user.compares[item.id] != null ? 'Comparing' : 'Compare'}"/> <f:ajax render="@this"/> </bt:button> <!-- This regular jsf component works --> <h:commandLink action="#{itemsCtr.compare(item)}" value="Test"> <f:ajax render="@this"/> </h:commandLink> 

And here is my composite definition of the bt button component:

 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:cc="http://java.sun.com/jsf/composite" xmlns:f="http://java.sun.com/jsf/core"> <cc:interface componentType="LinkComponent"> <cc:attribute name="action" targets="button"/> <cc:attribute name="value" type="java.lang.String"/> <cc:attribute name="active" type="java.lang.Boolean"/> <cc:attribute name="title" type="java.lang.String"/> <cc:attribute name="styleClass" type="java.lang.String"/> <cc:attribute name="disabled" type="java.lang.Boolean"/> <cc:attribute name="style" type="java.lang.String"/> </cc:interface> <cc:implementation> <h:commandLink id="button" binding="#{cc.link}" styleClass="btn #{cc.attrs.active ? 'active' : ''} #{cc.attrs.disabled ? 'disabled' : ''} #{cc.attrs.styleClass}" title="#{cc.attrs.title}" style="#{cc.attrs.style}" disabled="#{cc.attrs.disabled}" value="#{cc.attrs.value}"> <cc:insertChildren/> </h:commandLink> </cc:implementation> </html> 

My question is this is a JSF problem, or is something wrong here? Perhaps in defining a composite component?

+7
source share
3 answers

I had the same need as you did, and I made a composite component into which I inserted the child elements with the view parameters as attributes just like you, and the value was always zero, so I think this is a JSF problem.

0
source

try replacing

 disabled="#{user.compares[item.id] != null and itemsCtr.numOfCompares >= 100}" 

from

 disabled="#{user.compares[item.id] != null and itemsCtr.numOfCompares ge 100}" 
0
source

I'm not sure, but I guess you should try replacing

 #{user.compares[item.id]} 

from

 #{user.compares[item]['id']} 
0
source

All Articles