我创建了以下自定义标记:
<h:form>
<d:formBuilder/>
</h:form>
标签呈现没有这样的问题:
代码:
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的方法!怎么了?
感谢。
答案 0 :(得分:0)
这个答案可以帮助你...... why command button not getting invoked?
答案 1 :(得分:0)
按钮使用代码:
ExpressionFactory ef = context.getFacesContext().getCurrentInstance().getApplication().getExpressionFactory();
MethodExpression me = ef.createMethodExpression(ec, "#{cli.insert}", null, new Class[]{ActionEvent.class});
MethodExpressionActionListener meal = new MethodExpressionActionListener( me );
command.addActionListener(meal);
command.setType( "submit" );
答案 2 :(得分:0)
P.S:Primefaces 3.4