You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Thomas Möller <th...@continentale.de> on 2010/10/27 15:42:25 UTC
composite components: optional method-expression-attributes
Hi,
what is the recommended way how to deal with optional attributes that refer
to a method expression?
For example imagine a simple component that uses a commandLink and has two
attributes: "action" and "actionListener":
<cc:interface>
<cc:attribute name="action" method-signature="java.lang.String action()"
default="???" />
<cc:attribute name="actionListener" method-signature="void
actionListener(javax.faces.event.ActionEvent)" default="???" />
</cc:interface>
<cc:implementation>
<tr:commandLink action="#{cc.attrs.action}"
actionListener="#{cc.attrs.actionListener}" />
</cc:implementation>
My problems:
1) omitting the defaults results in NullPointerExceptions
2) the spec says that a default-attribute must evaluate to a
java.lang.String
What is the solution for this simple problem?
Thanks in advance.
--
View this message in context: http://old.nabble.com/composite-components%3A-optional-method-expression-attributes-tp30067392p30067392.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: composite components: optional method-expression-attributes
Posted by Mike Kienenberger <mk...@gmail.com>.
While trying to find a reference to what I wrote about, I came across
this posting.
There's a number of ideas kicked back and forth there, and the one on
using <f:attribute> for your action and actionListener might work for
you.
http://www.icefaces.org/JForum/posts/list/8006.page
On Wed, Oct 27, 2010 at 3:31 PM, Mike Kienenberger <mk...@gmail.com> wrote:
> I seem to vaguely recall from the facelets mailing lists long ago that
> you had to sometimes pass method bindings as two separate parameters.
> One for the object, and one for the method name.
>
> "#{object}.#{method}"
>
> Sorry I can't be of more help, but maybe it'll get you going in the
> right direction.
>
>
>
> On Wed, Oct 27, 2010 at 9:42 AM, Thomas Möller
> <th...@continentale.de> wrote:
>>
>> Hi,
>>
>> what is the recommended way how to deal with optional attributes that refer
>> to a method expression?
>>
>> For example imagine a simple component that uses a commandLink and has two
>> attributes: "action" and "actionListener":
>>
>> <cc:interface>
>> <cc:attribute name="action" method-signature="java.lang.String action()"
>> default="???" />
>> <cc:attribute name="actionListener" method-signature="void
>> actionListener(javax.faces.event.ActionEvent)" default="???" />
>> </cc:interface>
>>
>> <cc:implementation>
>> <tr:commandLink action="#{cc.attrs.action}"
>> actionListener="#{cc.attrs.actionListener}" />
>> </cc:implementation>
>>
>> My problems:
>> 1) omitting the defaults results in NullPointerExceptions
>> 2) the spec says that a default-attribute must evaluate to a
>> java.lang.String
>>
>> What is the solution for this simple problem?
>>
>> Thanks in advance.
>> --
>> View this message in context: http://old.nabble.com/composite-components%3A-optional-method-expression-attributes-tp30067392p30067392.html
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
>
Re: composite components: optional method-expression-attributes
Posted by Mike Kienenberger <mk...@gmail.com>.
I seem to vaguely recall from the facelets mailing lists long ago that
you had to sometimes pass method bindings as two separate parameters.
One for the object, and one for the method name.
"#{object}.#{method}"
Sorry I can't be of more help, but maybe it'll get you going in the
right direction.
On Wed, Oct 27, 2010 at 9:42 AM, Thomas Möller
<th...@continentale.de> wrote:
>
> Hi,
>
> what is the recommended way how to deal with optional attributes that refer
> to a method expression?
>
> For example imagine a simple component that uses a commandLink and has two
> attributes: "action" and "actionListener":
>
> <cc:interface>
> <cc:attribute name="action" method-signature="java.lang.String action()"
> default="???" />
> <cc:attribute name="actionListener" method-signature="void
> actionListener(javax.faces.event.ActionEvent)" default="???" />
> </cc:interface>
>
> <cc:implementation>
> <tr:commandLink action="#{cc.attrs.action}"
> actionListener="#{cc.attrs.actionListener}" />
> </cc:implementation>
>
> My problems:
> 1) omitting the defaults results in NullPointerExceptions
> 2) the spec says that a default-attribute must evaluate to a
> java.lang.String
>
> What is the solution for this simple problem?
>
> Thanks in advance.
> --
> View this message in context: http://old.nabble.com/composite-components%3A-optional-method-expression-attributes-tp30067392p30067392.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>
Re: composite components: optional method-expression-attributes
Posted by Thomas Möller <th...@continentale.de>.
My current problem is that retargeting only works using a restricted set of
special attribute names like 'action' and 'actionListener' and so on but my
real composite component contains several buttons and I want to declare for
each button e. g. an action. How do I solve this:
<cc:interface>
<cc:attribute name="action1" method-signature="String f()"
target="action1" />
<cc:attribute name="action2" method-signature="String f()"
target="action2" />
</cc:interface>
<cc:implementation>
<cc:tr:commandLink id="action1" text="Action 1" />
<cc:tr:commandLink id="action2" text="Action 2" />
</cc:implementation>
A similar problem arises if I want to support trinidad-specific listeners
like the launchListener for dialogs.
--
View this message in context: http://old.nabble.com/composite-components%3A-optional-method-expression-attributes-tp30067392p30083422.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: composite components: optional method-expression-attributes
Posted by Jakob Korherr <ja...@gmail.com>.
Hi Thomas,
Use the targets attribute of cc:attribute and it should work.
Regards,
Jakob
2010/10/27 Thomas Möller <th...@continentale.de>:
>
> Hi,
>
> what is the recommended way how to deal with optional attributes that refer
> to a method expression?
>
> For example imagine a simple component that uses a commandLink and has two
> attributes: "action" and "actionListener":
>
> <cc:interface>
> <cc:attribute name="action" method-signature="java.lang.String action()"
> default="???" />
> <cc:attribute name="actionListener" method-signature="void
> actionListener(javax.faces.event.ActionEvent)" default="???" />
> </cc:interface>
>
> <cc:implementation>
> <tr:commandLink action="#{cc.attrs.action}"
> actionListener="#{cc.attrs.actionListener}" />
> </cc:implementation>
>
> My problems:
> 1) omitting the defaults results in NullPointerExceptions
> 2) the spec says that a default-attribute must evaluate to a
> java.lang.String
>
> What is the solution for this simple problem?
>
> Thanks in advance.
> --
> View this message in context: http://old.nabble.com/composite-components%3A-optional-method-expression-attributes-tp30067392p30067392.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>
--
Jakob Korherr
blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at
Re: composite components: optional method-expression-attributes
Posted by Jakob Korherr <ja...@gmail.com>.
You're welcome.
I hardly think that there's an easy way to do this unless you return
different outcomes in your action methods.
Regards,
Jakob
2010/11/10 Thomas Möller <th...@continentale.de>:
>
> Thank you. I tried this but with this solution it is not possible to use the
> action-expression in navigation rules because for every button panel it is
> "#{cc.attrs.button1.myaction}".
>
> If I use
>
> <my:buttonPanel button1="#{mybean.button1}" />
>
> and
>
> <my:buttonPanel button1="#{mybean.anotherButton1}" />
>
> in my page I want to differentiate somehow between the actions of the button
> panels in navigation rules. The resulting expression should be something
> like "#{mybean.button1.myaction}" and "#{mybean.anotherButton1.myaction}".
>
> Is there a solution for this?
>
>
> --
> View this message in context: http://old.nabble.com/composite-components%3A-optional-method-expression-attributes-tp30067392p30178406.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>
--
Jakob Korherr
blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at
Re: composite components: optional method-expression-attributes
Posted by Thomas Möller <th...@continentale.de>.
Thank you. I tried this but with this solution it is not possible to use the
action-expression in navigation rules because for every button panel it is
"#{cc.attrs.button1.myaction}".
If I use
<my:buttonPanel button1="#{mybean.button1}" />
and
<my:buttonPanel button1="#{mybean.anotherButton1}" />
in my page I want to differentiate somehow between the actions of the button
panels in navigation rules. The resulting expression should be something
like "#{mybean.button1.myaction}" and "#{mybean.anotherButton1.myaction}".
Is there a solution for this?
--
View this message in context: http://old.nabble.com/composite-components%3A-optional-method-expression-attributes-tp30067392p30178406.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: composite components: optional method-expression-attributes
Posted by Jakob Korherr <ja...@gmail.com>.
Hi Thomas,
OK, thanks. Now it's more clear to me what you're trying to do.
Something like this should work:
<cc:interface>
<cc:attribute name="button1" type="insert.package.here.SimpleModel" />
</cc:interface>
<cc:implementation>
<h:commandButton disabled="#{cc.attrs.button1 == null}"
action="#{cc.attrs.button1.myaction}" value="Button1" />
</cc:implementation>
Regards,
Jakob
2010/11/9 Thomas Möller <th...@continentale.de>:
>
> Hi Jakob,
>
> I wanted to design the following composite component (a panel with two
> buttons):
>
> <my:buttonPanel button1="#{myBean.button1}" button2="#{myBean.button2}" />
>
> where "#{myBean.button1}" and "#{myBean.button2}" are instances of
> SimpleModel. For the button expression should apply: If it evaluates to
> null the button is disabled, if not SimpleModel.myaction() will be executed.
>
> Therefore I wanted to express with the following composite component
> attribute declaration:
>
> <cc:attribute name="button1" type="SimpleModel" >
> <cc:attribute name="myaction" targetAttributeName="action"
> targets="button" />
> </cc:attribute>
>
> that the attribute "myaction" of the instance maps to the action of the
> button. I guess that it does not work even with JSF 2.1 because it is a
> nested attribute declaration.
> --
> View this message in context: http://old.nabble.com/composite-components%3A-optional-method-expression-attributes-tp30067392p30168428.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>
--
Jakob Korherr
blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at
Re: composite components: optional method-expression-attributes
Posted by Thomas Möller <th...@continentale.de>.
Hi Jakob,
I wanted to design the following composite component (a panel with two
buttons):
<my:buttonPanel button1="#{myBean.button1}" button2="#{myBean.button2}" />
where "#{myBean.button1}" and "#{myBean.button2}" are instances of
SimpleModel. For the button expression should apply: If it evaluates to
null the button is disabled, if not SimpleModel.myaction() will be executed.
Therefore I wanted to express with the following composite component
attribute declaration:
<cc:attribute name="button1" type="SimpleModel" >
<cc:attribute name="myaction" targetAttributeName="action"
targets="button" />
</cc:attribute>
that the attribute "myaction" of the instance maps to the action of the
button. I guess that it does not work even with JSF 2.1 because it is a
nested attribute declaration.
--
View this message in context: http://old.nabble.com/composite-components%3A-optional-method-expression-attributes-tp30067392p30168428.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: composite components: optional method-expression-attributes
Posted by Jakob Korherr <ja...@gmail.com>.
Hi Thomas,
Could you explain this in a little more detail please?
Regards,
Jakob
2010/11/4 Thomas Möller <th...@continentale.de>:
>
> I found the discussion for jsf 2.1 and recognized that new attribute
> "targetAttributeName" on the attribute tag. But could somebody of the
> experts briefly answer here if I can do the following regarding to nested
> attributes:
>
> public interface SimpleModel
> {
> String myaction();
> }
>
> <my:buttonPanel button1="#{simpleModel1}" button2="#{simpleModel2}" />
>
> Is it possible to declare:
>
> <cc:interface>
> <cc:attribute name="model" type="SimpleModel" >
> <cc:attribute name="myaction" targetAttributeName="action"
> targets="button" />
> </cc:attribute>
> </cc:interface>
>
> <cc:implementation>
> <h:commandButton id="button" ... />
> </cc:implementation>
>
> How can I declare a navigation rule for all actions that arise from button1?
>
> <from-action>#{simpleModel1...}</from-action> <!-- ??? -->
>
> If I had two actions on a model I had to distinguish them from each other
> somehow.
>
> Thanks for your answers in advance!
>
>
> --
> View this message in context: http://old.nabble.com/composite-components%3A-optional-method-expression-attributes-tp30067392p30129953.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>
--
Jakob Korherr
blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at
Re: composite components: optional method-expression-attributes
Posted by Thomas Möller <th...@continentale.de>.
I found the discussion for jsf 2.1 and recognized that new attribute
"targetAttributeName" on the attribute tag. But could somebody of the
experts briefly answer here if I can do the following regarding to nested
attributes:
public interface SimpleModel
{
String myaction();
}
<my:buttonPanel button1="#{simpleModel1}" button2="#{simpleModel2}" />
Is it possible to declare:
<cc:interface>
<cc:attribute name="model" type="SimpleModel" >
<cc:attribute name="myaction" targetAttributeName="action"
targets="button" />
</cc:attribute>
</cc:interface>
<cc:implementation>
<h:commandButton id="button" ... />
</cc:implementation>
How can I declare a navigation rule for all actions that arise from button1?
<from-action>#{simpleModel1...}</from-action> <!-- ??? -->
If I had two actions on a model I had to distinguish them from each other
somehow.
Thanks for your answers in advance!
--
View this message in context: http://old.nabble.com/composite-components%3A-optional-method-expression-attributes-tp30067392p30129953.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: composite components: optional method-expression-attributes
Posted by Matthias Wessendorf <ma...@apache.org>.
I saw the discussion on the "open" jsr list. Jakob, is there any archive for
Thomas to read the mails?
-M
sent from my Android phone
On Nov 3, 2010 6:37 PM, "Jakob Korherr" <ja...@gmail.com> wrote:
> Hi Thomas,
>
> What you have encountered here is a known design problem of JSF 2.0.
> Currently we (the MyFaces team) are working hard to get all of this
> fixed for the JSF 2.1 specification, because - as you know - this
> stuff is really annoying and makes composite components unusable in
> the most scenarios.
>
> Sorry, but that is all we can do right now. Fortunately the JSF 2.1
> spec release will be very soon!
>
> Regards,
> Jakob
>
> 2010/11/3 Thomas Möller <th...@continentale.de>:
>>
>> Finally it seems to me that the "targets"-feature is only sufficient for
the
>> simplest scenarios. There are too many restrictions:
>>
>> 1) only for a restricted set of attribute names: "action",
"actionListener",
>> "validator", "valueChangeListener"
>> 2) not supported in nested attributes
>>
>> So, what is the solution in my scenario (I thought it was simple enough):
a
>> composite component that consists of a panel with two buttons and
*optional*
>> actions and actionListeners. I want to use it in the following way:
>>
>> either 1)
>>
>> <my:twoButtons action1="..." actionListener1="..." action2="..."
>> actionListener2="..." />
>>
>> or 2)
>>
>> <my:twoButtons2 button1="..." button2="..." /> relying on a button model:
>>
>> public interface Button
>> {
>> String action();
>> void actionListener(ActionEvent e);
>> }
>>
>> I tried to solve this problem without tricks like writing own tag
handlers
>> or modifying the facelets view declaration language.
>>
>> I'd really like to get an answer for this... ;-)
>> --
>> View this message in context:
http://old.nabble.com/composite-components%3A-optional-method-expression-attributes-tp30067392p30120526.html
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Jakob Korherr
>
> blog: http://www.jakobk.com
> twitter: http://twitter.com/jakobkorherr
> work: http://www.irian.at
Re: composite components: optional method-expression-attributes
Posted by Jakob Korherr <ja...@gmail.com>.
Hi Thomas,
What you have encountered here is a known design problem of JSF 2.0.
Currently we (the MyFaces team) are working hard to get all of this
fixed for the JSF 2.1 specification, because - as you know - this
stuff is really annoying and makes composite components unusable in
the most scenarios.
Sorry, but that is all we can do right now. Fortunately the JSF 2.1
spec release will be very soon!
Regards,
Jakob
2010/11/3 Thomas Möller <th...@continentale.de>:
>
> Finally it seems to me that the "targets"-feature is only sufficient for the
> simplest scenarios. There are too many restrictions:
>
> 1) only for a restricted set of attribute names: "action", "actionListener",
> "validator", "valueChangeListener"
> 2) not supported in nested attributes
>
> So, what is the solution in my scenario (I thought it was simple enough): a
> composite component that consists of a panel with two buttons and *optional*
> actions and actionListeners. I want to use it in the following way:
>
> either 1)
>
> <my:twoButtons action1="..." actionListener1="..." action2="..."
> actionListener2="..." />
>
> or 2)
>
> <my:twoButtons2 button1="..." button2="..." /> relying on a button model:
>
> public interface Button
> {
> String action();
> void actionListener(ActionEvent e);
> }
>
> I tried to solve this problem without tricks like writing own tag handlers
> or modifying the facelets view declaration language.
>
> I'd really like to get an answer for this... ;-)
> --
> View this message in context: http://old.nabble.com/composite-components%3A-optional-method-expression-attributes-tp30067392p30120526.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>
--
Jakob Korherr
blog: http://www.jakobk.com
twitter: http://twitter.com/jakobkorherr
work: http://www.irian.at
Re: composite components: optional method-expression-attributes
Posted by Thomas Möller <th...@continentale.de>.
Finally it seems to me that the "targets"-feature is only sufficient for the
simplest scenarios. There are too many restrictions:
1) only for a restricted set of attribute names: "action", "actionListener",
"validator", "valueChangeListener"
2) not supported in nested attributes
So, what is the solution in my scenario (I thought it was simple enough): a
composite component that consists of a panel with two buttons and *optional*
actions and actionListeners. I want to use it in the following way:
either 1)
<my:twoButtons action1="..." actionListener1="..." action2="..."
actionListener2="..." />
or 2)
<my:twoButtons2 button1="..." button2="..." /> relying on a button model:
public interface Button
{
String action();
void actionListener(ActionEvent e);
}
I tried to solve this problem without tricks like writing own tag handlers
or modifying the facelets view declaration language.
I'd really like to get an answer for this... ;-)
--
View this message in context: http://old.nabble.com/composite-components%3A-optional-method-expression-attributes-tp30067392p30120526.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.