0

I have a jsf page where I have this form :

<h:commandButton id="submit" value="Submit">


                <h:inputText id="locationInputId" value="#{historicCtrl.historic.search}" ></h:inputText>

                <f:ajax event="click" render="resultGroup" listener="#{cSVobjectCtrl.doRender}"/>
                <label for="lat">Latitude</label>
                <h:inputText id="lat" value="#{cSVobjectCtrl.lat}"/>
                <label for ="lng">Longitude</label>
                <h:inputText id="lng" value="#{cSVobjectCtrl.lng}"/>
                <f:actionListener binding="#{historicCtrl.insertSearch(2)}"/>
            </h:commandButton >

The problem is that the line :

< f:actionListener binding="#{historicCtrl.insertSearch(2)}"/>

Is ignored and I don't know why.

I tried a easier version of the code :

<h:form>
            <h:outputText value="Lieu"/>
            <h:inputText id="login" value="#{historicCtrl.historic.search}" required="true"></h:inputText>   
            <br/>

            <h:commandButton value="Search">
               <h:outputText id ="textToInsertId" value="#{historicCtrl.insertSearch(2)}"/>
            </h:commandButton>
        </h:form>

This one is working, I can see the trace that the method is supposed to print on the console and I have the insertion in my database.

On the opposite the first code that I wrote in the message isn't working as expected. Indeed, all is working naturally except the f;actionListener as I explain above.

Why is this instruction ingnored ?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Omegaspard
  • 1,828
  • 2
  • 24
  • 52

1 Answers1

0

Your code is really confusing, but I'll concentrate on the question and provide an example of how your code should propably look like.

If you want to bind an actionListener you have to bind it to an object that implements ActionListener-Interface and not to a method, for example:

facelet

<f:actionListener binding="#{historicCtrl}" />

ActionListener

@ManagedBean
@ViewScoped
public class HistoricCtrl implements Serializable, ActionListener {

    private static final long serialVersionUID = 6307961450435094233L;

    @Override
    public void processAction(ActionEvent e) throws AbortProcessingException {
       // TODO implement
    }
}

If you use binding you can't pass an argument to your actionListener. The better approach is to use actionListener attribute of h:commandButton. In this case your code should look like this:

<h:form id="form">
     <h:inputText id="locationInputId" value="#{historicCtrl.historic.search}" />

     <br />

     <h:outputLabel for="lat" value="Latitude" />
     <h:inputText id="lat" value="#{cSVobjectCtrl.lat}"/>

     <br />

     <h:outputLabel for="lng" value="Longitude" />
     <h:inputText id="lng" value="#{cSVobjectCtrl.lng}"/>

     <br />

     <h:commandButton id="submit" value="Submit" actionListener="#{historicCtrl.insertSearch(2)}">
        <f:ajax execute="form" render="resultGroup" listener="#{cSVobjectCtrl.doRender}"/>
     </h:commandButton>
</h:form>
Alex Fire
  • 707
  • 3
  • 7