Use the rendered attribuet.




Rønnevik, Eivind <[EMAIL PROTECTED]> 
05/31/2007 08:24 AM
Please respond to
"MyFaces Discussion" <users@myfaces.apache.org>


To
"MyFaces Discussion" <users@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.

Reply via email to