gpt4 book ai didi

java - 命令按钮操作不适用于自定义标记

转载 作者:行者123 更新时间:2023-12-01 05:14:50 25 4
gpt4 key购买 nike

我创建了以下自定义标签:

<h:form>
<d:formBuilder/>
</h:form>

标签渲染时不会出现如下问题:

my custom tag

标签代码:

public class FormBuilder extends TagHandler {

public FormBuilder(TagConfig config) {
super(config);
}

public void apply(FaceletContext context, UIComponent parent) throws IOException {
CommandButton command = (CommandButton) context.getFacesContext().getCurrentInstance().getApplication().createComponent( CommandButton.COMPONENT_TYPE);
command.setValue("Click");
command.setAjax(false);
MethodExpression me = context.getExpressionFactory().createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{cli.insert}", null, new Class<?>[0]);
command.setActionExpression(me);

InputText it = (InputText) context.getFacesContext().getCurrentInstance().getApplication().createComponent(InputText.COMPONENT_TYPE);
ValueExpression ve1 = context.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{cli.name}", String.class);
it.setValueExpression("value", ve1);

parent.getChildren().clear();
parent.getChildren().add(it);
parent.getChildren().add(command);
}

}

托管 bean:

@SessionScoped
@ManagedBean(name = "cli")
public class ClienteController {

private String name = "aa";

public String insert() {
name = "test";
return "clientes";
}
}

inputText 工作正常,但 commandButton 不执行 ManagedBean 的方法!怎么了?

谢谢。

最佳答案

这个答案会对你有所帮助.. why command button not getting invoked?

关于java - 命令按钮操作不适用于自定义标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11425218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com