Thomas Chang wrote:
Hi all,
I use the rendered inoder to change the showing or hiding of an
inputTextField in run-time. My code look as follow:
...
...
<h:inputText id="search_item2"
value="#{myBean.searchitem2}" size="30"
rendered="#{myBean.searchLabel == 2}" />
...
...
public class MyBean{
...
private String searchitem2 = null;
...
public String getSearchitem2(){
...
}
public void setSearchitem2{
...
}
...
}
But it works not so well. Exactly to say: The inputTextField can be
shown or hidden in run time. But I can't get the value from the
inputTextField.
But if I remove the "rendererd", I can get the value but the
inputTextField can not be shown or hidden in run-time.
Who can tells me what's wrong?
I think you have a misunderstanding about the "rendered" attribute.
Setting this to false does not "make the component invisible in the
rendered html", it does not output the component into the html at all.
If you just want the field to become invisible to the user, but actually
be present in the page, then I suggest either:
(1)
<h:inputText id="search_item2"
value="#{myBean.searchitem2"
rendered="#{mybean.searchLabel == 2}"/>
<h:inputHidden id="search_item2_hidden"
value="#{myBean.searchitem2}"
rendered="#{mybean.searchLabel != 2}"/>
which ensures that if the inputText is not rendered, then a hidden field
is generated instead that contains the same value
or
(2)
<h:inputText id="search_item2" value="#{myBean.searchitem2}"
style="#{myBean.searchitem2Style}"/>
where method getSearchitem2Style returns "display:hidden" if the input
should not be visible.
Regards,
Simon