1

I created the following custom tag:

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

The tag renders without problems like this:

my custom tag

Tag code:

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);
    }

}

The managed bean:

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

    private String name = "aa";

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

The inputText works correctly but the commandButton doesn't perform the method of managedBean! what is wrong?

Thanks.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Silvano Lohn
  • 41
  • 1
  • 2

3 Answers3

0

This answer will help you.. why command button not getting invoked?

Community
  • 1
  • 1
Karthikeyan
  • 757
  • 3
  • 11
  • 25
0

the button worked with code:

   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" );
Silvano Lohn
  • 41
  • 1
  • 2
0

curiosly, i had the same problem, but i was using EL expression. I resolved the problem removing the tag "type=button". I know, there is no logic, but only work removing the tag.

P.S: Primefaces 3.4

Cateno Viglio
  • 407
  • 11
  • 25