Your suggestion worked :) I was on to it myself, but guess I mixed up a bit with my string-representation.. ;)
Thanks for sorting it out! -----Original Message----- From: Mike Kienenberger [mailto:[EMAIL PROTECTED] Sent: 31. mai 2007 15:49 To: MyFaces Discussion Subject: Re: Change valueBinding of t:dataTable based on condition 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 <[EMAIL PROTECTED]> 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

