I want to call one method via a link from Facelets:
My Facelets code is as follows:
<h:commandButton value="A" actionListener="#{customerData.searchedCustomerListA}" /> <h:commandLink value="A" actionListener="#{customerData.searchedCustomerListA}"/>
The reverse bean code is as follows:
public void searchedCustomerListA(ActionEvent ae){ customerName = "A"; leftCustomerListAvailable.clear(); if(customerDataBean.getSearchedCustomerList(customerName)!= null) leftCustomerListAvailable =customerDataBean.getSearchedCustomerList("A"); }
The same code works for <h:commandButton>, but does not work for <h:commandLink>. How is this caused and how can I solve it?
<h:commandButton>
<h:commandLink>
<h:commandLink> <h:commandButton> , JavaScript . , , , , JavaScript , jsf.js, , ( , JS JS ).
jsf.js
, , , JS , <h:head> HTML <head> , JSF , jsf.js.
<h:head>
<head>
, - , , JS, <h:commandButton> CSS, (, , , , ..).
, .
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"> <h:form> <h:commandLink type="button" action="#{testBean.tsetLink}"> <h:outputText value="A" /> </h:commandLink> </h:form> </html>
@ManagedBean @RequestScoped public class TestBean { public void tsetLink(){ System.out.println("Link clicked!!!!!!!!!!!!"); } }
. , commandLink , commandButton. Link , . "" = "" commandLink.
<h:form> …… <div class="control-group"> <div class="controls"> <h:commandButton value="Login" action="#{usrCtrl.login}" class="btn btn-primary"/> <h:commandLink action="#{usrCtrl.register}" value="test" immediate="true"/> </div> </div> </h:form>
Read the JSF and the “immediate” attribute - Command Components to see why it works.
In my case, the cause of this problem was a poorly configured URL rewrite filter. One of the filter patterns is inadvertently mapped http://localhost:8080/mysite/javax.faces.resource/jsf.js.xhtml?ln=javax.faces, which prevents jsf.js from loading. Check this answer: Pressing h: commandLink raises an Uncaught ReferenceError: mojarra not defined .
http://localhost:8080/mysite/javax.faces.resource/jsf.js.xhtml?ln=javax.faces