user3682520
user3682520

Reputation: 71

Not able to call jsf action through h:commandbutton in chrome

Having a Question on JSF j:commandButton's action, chrome browser and JSF 1.1

Calling JavaScript function on click of command link as below

<h:dataTable>
<h:column>
<h:panelGroup rendered="#{expression which returns true}">
<f:verbatim rendered="#{someView.agentEdit}"> </f:verbatim>
<h:commandLink id= "editId" styleClass="commandLinkClass"rendered="#policyHistory.agentEdit}" onclick="return performPolicyHistoryAction('Edit', id);" value="Edit"/>
</h:panelGroup>
</h:column>
</h:dataTable>

With the above code I am getting the Link and it's able to call js function 'performPolicyHistoryAction'

In js function

function performPolicyHistoryAction(cntrlValue, cntrlId){
  DWREngine.setAsync(false);
  if (cntrlValue == 'Edit')  {
  document.getElementById("someString:lnkViewOnlyrefresh").click();
 }
}

and someString:lnkViewOnlyrefresh is declared as

&lt;h:commandButton action="#{someBean.viewOnlyAction}"
        id="lnkViewOnlyrefresh" value="refresh" styleClass="hide" title="refresh"&gt;&lt;/h:commandButton&gt;

here in chrome, not calling commandButton's action method. It's working fine in IE and FF

Note:If I put alert in <h:commandButton>'s onClick I am getting the alert.

Upvotes: 0

Views: 1072

Answers (2)

Axel Osorio
Axel Osorio

Reputation: 39

Thank you very much for your answer it helps me very much. In my case I was calling a click() action in the command button from Jquery. All this called from an input type image. But the page only refresh in chrome when submit and never called the datosTraficoJS in the managed bean, and for this reason the page never redirect to the next. Only in chrome and IE not works, FF works well. I put the ";return false" after the onclick and it works very well.

The input type:

<input type="image" src="../resources/clock.png" onclick="editaTrafico(401); return false;"/>

The function:

function editaTrafico(idEmbarque) {
    var fieldIdEmbarque = $("#consultaDespachosTraficoForm\\:hdnIdEmbarque");
    fieldIdEmbarque.val(idEmbarque);
    var botonTraf = $("#consultaDespachosTraficoForm\\:hdnBtn");
    botonTraf.click();
    }

The command button:

<h:commandButton id="hdnBtn" type="submit"     action="#consultaDespachosTraficoBean.datosTraficoJS}" 
value="#{msg.gen_filtrar}" />

Hope it helps to someone else.

Upvotes: 0

user3682520
user3682520

Reputation: 71

Changed to onclick="return performPolicyHistoryAction('ViewOnly', id); " is changed to onclick="performPolicyHistoryAction('ViewOnly', id); return false;"

in belowcode

<h:dataTable>
<h:column>
<h:panelGroup rendered="#{expression which returns true}">
<f:verbatim rendered="#{someView.agentEdit}"> </f:verbatim>
<h:commandLink id= "editId"  styleClass="commandLinkClass"rendered="#policyHistory.agentEdit}" onclick="performPolicyHistoryAction('Edit', id); return false;" value="Edit"/>
</h:panelGroup>
</h:column>
</h:dataTable>

Working fine...

Upvotes: 0

Related Questions