Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

b:commandButton onclick executed twice? #826

Closed
chongma opened this issue Jul 23, 2017 · 6 comments
Closed

b:commandButton onclick executed twice? #826

chongma opened this issue Jul 23, 2017 · 6 comments
Assignees
Milestone

Comments

@chongma
Copy link
Collaborator

chongma commented Jul 23, 2017

If I click the button described below it prompts me twice to confirm. Is the code being executed twice?

<b:commandButton value="Delete" iconAwesome="trash"
    action="#{testBean.delete}"
    onclick="if (! confirm('Are you sure?')) return false">
    <f:setPropertyActionListener target="#{testBean.id}"
        value="#{testItem.id}" />
    <f:ajax execute="@this" render="@form" />
</b:commandButton>

Bear in mind the code was inside a b:dataTable

@stephanrauh
Copy link
Collaborator

It seems the onclick handler is rendered twice:

                 	<b:commandButton value="Delete" iconAwesome="trash"
					    action="#{car.edit}"
					    onclick="debugger">
					    <f:ajax execute="@this" render="@form" />
					</b:commandButton>
<button type="submit" id="j_idt351:j_idt352:14:j_idt363"
	name="j_idt351:j_idt352:14:j_idt363" class="btn btn-default"
	onclick="debugger;debugger;BsF.ajax.callAjax(this, event,'j_idt351','j_idt351:j_idt352:14:j_idt363',null,null,null,null);;;return false;">
	<span><i class="fa fa-trash"></i></span> Delete
</button>

@stephanrauh
Copy link
Collaborator

stephanrauh commented Jul 25, 2017

The reproducer can be simplified to

<h:body>
  <h:form>           
    	<b:commandButton
	    onclick="debugger">
	    <f:ajax/>
	</b:commandButton>
  </h:form>
</h:body>

@stephanrauh
Copy link
Collaborator

I guess the problem is that <b:commandButton> renders the onclick attribute, and f:ajax renders it again.

stephanrauh added a commit that referenced this issue Jul 25, 2017
@stephanrauh
Copy link
Collaborator

@chongma Maybe you want to review my last change. It should do the trick, but it's kind of a hack. If you've got a better solution, just tell me (or commit it yourself :)).

@chongma
Copy link
Collaborator Author

chongma commented Jul 26, 2017

looks good to me

@stephanrauh
Copy link
Collaborator

I still can't think of a better solution, so I'll close this ticket. @chongma , thanks for testing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants