Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting dynamic value in <f:attribute  RSS feed

 
Fawad Ali
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I am trying to set a dynamic value to an <f:attribute> as

<f:attribute name="queryString" value="#{viewAllInvoicesBean.queryString}" />

but the value is never set. When I write it like

<f:attribute name="queryString" value="hello" />

it works then. But I need to take the value from managed bean. Is there anyway of doing so?
 
Fawad Ali
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,
I did a bit of work around on this and I came to know about a strange thing about <f:attribute>. If I the following lines of code

<h:commandButton value="Submit" actionListener="#{viewAllInvoicesBean.action}">
<f:attribute name="queryString" value="#{viewAllInvoicesBean.queryString}" />
</h:commandButton>

Before rendering, I set the value of queryString. When this code is rendered, the <f:attribute>'s value is not set to the one in managed bean. On clicking the command button, a new instance of viewAllInvoicesBean is created. Its action is called and it is in here when we write something like

String value1 = (String)event.getComponent().getAttributes().get("queryString");

Then first value is set to <f:attribute> from viewAllInvoicesBean and after that to value1. But remember a new instance of viewAllInvoicesBean has been created by clicking the commandButton and hence there is no value for viewAllInvoicesBean.queryString and hence no value for <f:attribute> and hence a null value is set to value1.

Well I dont know what is the logic behind this. But it does not work for me. If you guys have any suggestions for me. Please post them. I will be grateful.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!