Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 以编程方式创建的h:commandButton不调用onclick=";processInput(id)";_Jsf - Fatal编程技术网

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('');");