You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Rønnevik, Eivind <ei...@kadme.com> on 2007/05/31 14:23:30 UTC

Change valueBinding of t:dataTable based on condition

Hi!

 

I was just curious, is there any way I can change the value of a dataTable based on different conditions?

 

I'll try to give a simple example to explain what I want. :)

 

Let's say I use the graphicImage tag, in the value property I could either write the path to the image

<t:graphicImage value="/images/myImage.gif"

Or I can use an expression that returns a String pointing to the image

<t:graphicImage value#{myBean.pathToImage}"

 

I have the need of using the same jsp twice, but based on a boolean property the datasource for the dataTable on this page would differ.

 

Theoretically, this way of setting the value-property would represent what I would want to do:

 

<t:dataTable value="#{myBean.boolean ? '#{oneBean.dataModel}' : '#{ anotherBean.dataModel}'}"

 

This would work if the value property expected a String, but instead it expects an expression that directly points to a collection of some sort.

 

I also tried to point to a method in my bean that returns the correct value-string based on the Boolean:

 

<t:dataTable value="#{myBean.tableValue

 

where the getTableValue-method is like this:

 

public String getTableValue()

{

            if(condition)

                  return "#{oneBean.dataModel}";

            return "#{anotherBean.dataModel}";

            

}

 

But of course this fails since the dataTable expects a collection and not a String.

 

 

 

I know that I in my getTableValue-method can return the proper collection:

 

public DataModel getTableValue()

{

            if(condition)

                  return getOneBean().getDataModel();

            return getAnotherBean().getDataModel();

            

}

 

but then I would have to set the references to these other beans, and I can't do that because it would cause a cyclic reference.. 

 

So, are there other solutions to this or do I have to rethink my way of doing this? :)

 

Regards,

 

Eivind


Re: Change valueBinding of t:dataTable based on condition

Posted by Mike Kienenberger <mk...@gmail.com>.
Your  understanding of value binding syntax is incorrect.

Try this:

<t:dataTable value="#{myBean.boolean ? oneBean.dataModel :
anotherBean.dataModel}"

I can't think of any reason why this won't work.

On 5/31/07, Rønnevik, Eivind <ei...@kadme.com> wrote:
>
>
>
>
> Hi!
>
>
>
> I was just curious, is there any way I can change the value of a dataTable
> based on different conditions?
>
>
>
> I'll try to give a simple example to explain what I want. :)
>
>
>
> Let's say I use the graphicImage tag, in the value property I could either
> write the path to the image
>
> <t:graphicImage value="/images/myImage.gif"
>
> Or I can use an expression that returns a String pointing to the image
>
> <t:graphicImage value#{myBean.pathToImage}"
>
>
>
> I have the need of using the same jsp twice, but based on a boolean property
> the datasource for the dataTable on this page would differ.
>
>
>
> Theoretically, this way of setting the value-property would represent what I
> would want to do:
>
>
>
> <t:dataTable value="#{myBean.boolean ? '#{oneBean.dataModel}' : '#{
> anotherBean.dataModel}'}"
>
>
>
> This would work if the value property expected a String, but instead it
> expects an expression that directly points to a collection of some sort.
>
>
>
> I also tried to point to a method in my bean that returns the correct
> value-string based on the Boolean:
>
>
>
> <t:dataTable value="#{myBean.tableValue
>
>
>
> where the getTableValue-method is like this:
>
>
>
> public String getTableValue()
>
> {
>
>             if(condition)
>
>                   return "#{oneBean.dataModel}";
>
>             return "#{anotherBean.dataModel}";
>
>
>
> }
>
>
>
> But of course this fails since the dataTable expects a collection and not a
> String.
>
>
>
>
>
>
>
> I know that I in my getTableValue-method can return the proper collection:
>
>
>
> public DataModel getTableValue()
>
> {
>
>             if(condition)
>
>                   return getOneBean().getDataModel();
>
>             return getAnotherBean().getDataModel();
>
>
>
> }
>
>
>
> but then I would have to set the references to these other beans, and I
> can't do that because it would cause a cyclic reference..
>
>
>
> So, are there other solutions to this or do I have to rethink my way of
> doing this? :)
>
>
>
> Regards,
>
>
>
> Eivind

Re: Change valueBinding of t:dataTable based on condition

Posted by er...@novartis.com.
Use the rendered attribuet.





Rønnevik, Eivind <ei...@kadme.com> 
05/31/2007 08:24 AM
Please respond to
"MyFaces Discussion" <us...@myfaces.apache.org>


To
"MyFaces Discussion" <us...@myfaces.apache.org>
cc

Subject
Change valueBinding of t:dataTable based on condition






Hi!
 
I was just curious, is there any way I can change the value of a dataTable 
based on different conditions?
 
I?ll try to give a simple example to explain what I want. :)
 
Let?s say I use the graphicImage tag, in the value property I could either 
write the path to the image
<t:graphicImage value="/images/myImage.gif"
Or I can use an expression that returns a String pointing to the image
<t:graphicImage value#{myBean.pathToImage}"
 
I have the need of using the same jsp twice, but based on a boolean 
property the datasource for the dataTable on this page would differ.
 
Theoretically, this way of setting the value-property would represent what 
I would want to do:
 
<t:dataTable value="#{myBean.boolean ? '#{oneBean.dataModel}' : '#{ 
anotherBean.dataModel}'}"
 
This would work if the value property expected a String, but instead it 
expects an expression that directly points to a collection of some sort.
 
I also tried to point to a method in my bean that returns the correct 
value-string based on the Boolean:
 
<t:dataTable value="#{myBean.tableValue
 
where the getTableValue-method is like this:
 
public String getTableValue()
{
            if(condition)
                  return "#{oneBean.dataModel}";
            return "#{anotherBean.dataModel}";
            
}
 
But of course this fails since the dataTable expects a collection and not 
a String.
 
 
 
I know that I in my getTableValue-method can return the proper collection:
 
public DataModel getTableValue()
{
            if(condition)
                  return getOneBean().getDataModel();
            return getAnotherBean().getDataModel();
            
}
 
but then I would have to set the references to these other beans, and I 
can?t do that because it would cause a cyclic reference.. 
 
So, are there other solutions to this or do I have to rethink my way of 
doing this? :)
 
Regards,
 
Eivind

_________________________

CONFIDENTIALITY NOTICE

The information contained in this e-mail message is intended only for the 
exclusive use of the individual or entity named above and may contain 
information that is privileged, confidential or exempt from disclosure 
under applicable law. If the reader of this message is not the intended 
recipient, or the employee or agent responsible for delivery of the 
message to the intended recipient, you are hereby notified that any 
dissemination, distribution or copying of this communication is strictly 
prohibited. If you have received this communication in error, please 
notify the sender immediately by e-mail and delete the material from any 
computer.  Thank you.

RE: Change valueBinding of t:dataTable based on condition

Posted by he...@dnbnor.no.
Hi
 
You should look at Clay in the Shale project. This is a piece of cake using symbols in Clay.
 
Hermod

-----Original Message-----
From: Rønnevik, Eivind [mailto:eivind@kadme.com]
Sent: Thursday, May 31, 2007 2:24 PM
To: MyFaces Discussion
Subject: Change valueBinding of t:dataTable based on condition



Hi!

 

I was just curious, is there any way I can change the value of a dataTable based on different conditions?

 

I'll try to give a simple example to explain what I want. :)

 

Let's say I use the graphicImage tag, in the value property I could either write the path to the image

<t:graphicImage value="/images/myImage.gif"

Or I can use an expression that returns a String pointing to the image

<t:graphicImage value#{myBean.pathToImage}"

 

I have the need of using the same jsp twice, but based on a boolean property the datasource for the dataTable on this page would differ.

 

Theoretically, this way of setting the value-property would represent what I would want to do:

 

<t:dataTable value="#{myBean.boolean ? '#{oneBean.dataModel}' : '#{ anotherBean.dataModel}'}"

 

This would work if the value property expected a String, but instead it expects an expression that directly points to a collection of some sort.

 

I also tried to point to a method in my bean that returns the correct value-string based on the Boolean:

 

<t:dataTable value="#{myBean.tableValue

 

where the getTableValue-method is like this:

 

public String getTableValue()

{

            if(condition)

                  return "#{oneBean.dataModel}";

            return "#{anotherBean.dataModel}";

            

}

 

But of course this fails since the dataTable expects a collection and not a String.

 

 

 

I know that I in my getTableValue-method can return the proper collection:

 

public DataModel getTableValue()

{

            if(condition)

                  return getOneBean().getDataModel();

            return getAnotherBean().getDataModel();

            

}

 

but then I would have to set the references to these other beans, and I can't do that because it would cause a cyclic reference.. 

 

So, are there other solutions to this or do I have to rethink my way of doing this? :)

 

Regards,

 

Eivind

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

This email with attachments is solely for the use of the individual or
entity to whom it is addressed. Please also be aware that the DnB NOR Group
cannot accept any payment orders or other legally binding correspondence with
customers as a part of an email. 

This email message has been virus checked by the anti virus programs used
in the DnB NOR Group.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *