jsf - Get managed bean and type bound to "value" attribute -


let's suppose have following structure:

1) managed bean:

@viewscoped @managedbean public class testbean {     private test test;      //getters/setters } 

2) test class:

public class test {     private string attribute;      //gets/sets } 

3) xhtml

<p:inputtext id="test" value="#{testbean.test.atribute}" /> 

now, know there way find , component instance:

uicomponent c = view.findcomponent(s); 

from uicomponent, how type bound component?

what need full qualified class name set "value" attribute in component. like: package.test.attribute.

uicomponent offers getvalueexpression("attributename")

sample :

  uiviewroot viewroot = faces.getviewroot();             uicomponent component= viewroot.findcomponent("x");             valueexpression value = component.getvalueexpression("value");             class<?> expectedtype = value.gettype(faces.getelcontext()); 

nb:faces here omnifaces, "collection of utility methods jsf api shortcuts obtaining stuff thread local facescontext. "

excepts gettype() javadoc

public abstract class gettype(elcontext context) evaluates expression relative provided context, , returns general type acceptable object passed value parameter in future call setvalue(javax.el.elcontext. java.lang.object) method. not same getvalue().getclass(). example, in case of expression references array element, gettype method return element type of array, might superclass of type of actual element in specified array element.

for methodexpression read this.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -