jAVA

[color=red][/color][size=xx-small][/size]package com.bean;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

@ManagedBean(name="test_bean")
@RequestScoped
public class Test_bean {

public void add(){
//1
FacesContext content=FacesContext.getCurrentInstance();
ELContext elcontent=  content.getELContext();
Application ap = content.getApplication();
String name = (String) ap.evaluateExpressionGet(content, "#{userinfoBean.u.userName }", String.class);
System.out.println( "xingm:: "+name );//adddssd
//2
ExpressionFactory ef =   ap.getExpressionFactory();
ValueExpression  e =  ef.createValueExpression(elcontent, "#{userinfoBean}",UserinfoBean.class );

UserinfoBean u = (UserinfoBean)e.getValue(elcontent);

System.out.println( "用户名:"+u.getU().getUserName() );

u.adddssd();
//3
   ef.createMethodExpression(elcontent, "#{ userinfoBean.adddssd }", void.class, null).invoke(elcontent,new Object[]{} ) ;



}

}

你可能感兴趣的:(jsf bean取值)