Jsf 以编程方式创建的h:commandButton不调用onclick=";processInput(id)";
下面是我如何以编程方式创建Jsf 以编程方式创建的h:commandButton不调用onclick=";processInput(id)";,jsf,Jsf,下面是我如何以编程方式创建: 单击按钮时,我需要执行processInput(id)功能。但是,当我单击该按钮时,什么也没有发生。Onclick函数将processInput添加为JavaScript函数。您需要在Java方法中传递id,如下所示: setOnClick("processInput(" + id + ")"); 要添加动作方法,需要使用setActionExpression HtmlCommandButton button = new HtmlCommandButton();
:
单击按钮时,我需要执行
processInput(id)
功能。但是,当我单击该按钮时,什么也没有发生。Onclick函数将processInput添加为JavaScript函数。您需要在Java方法中传递id,如下所示:
setOnClick("processInput(" + id + ")");
要添加动作方法,需要使用setActionExpression
HtmlCommandButton button = new HtmlCommandButton();
FacesContext fc = FacesContext.getCurrentInstance();
ELContext ctx = fc.getELContext();
String expression = "#{processInput('id')}";
Class[] parameterTypes = new Class[1];
parameterTypes[0]=String.class;
MethodExpression me = fc.getApplication().getExpressionFactory().
createMethodExpression(ctx,
expression, returnType, parameterTypes);
button.setActionExpression(me);
button.setOnclick("alert('');");
@奇怪的是,当我点击按钮时,什么都没有发生。请在你的问题中写下这句话,以便其他人能清楚地理解问题。你在JavaScript控制台中看到任何错误吗?JavaScript函数中的
id
参数是什么?是processInput()
JavaScript函数(如您的问题所示)还是Java支持bean方法(如实际问题所示;换句话说,您混淆了JavaScript和Java)?
HtmlCommandButton button = new HtmlCommandButton();
FacesContext fc = FacesContext.getCurrentInstance();
ELContext ctx = fc.getELContext();
String expression = "#{processInput('id')}";
Class[] parameterTypes = new Class[1];
parameterTypes[0]=String.class;
MethodExpression me = fc.getApplication().getExpressionFactory().
createMethodExpression(ctx,
expression, returnType, parameterTypes);
button.setActionExpression(me);
button.setOnclick("alert('');");