user3447390
user3447390

Reputation: 1

Action bean not being called

I have problem using JSF 2.0. The command button doesn't call the bean, I have already read the balusc answer commandButton/commandLink/ajax action/listener method not invoked or input value not updated but I don't think I'm encountering those cases, this is the code I'm using:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:c="http://java.sun.com/jstl/core">


    ....   

<ui:repeat var="skill" value="#{skillsView.skills}">
    <h:form>


            <h:commandButton value="#{skill}"
                action="#{skillsController.removeSkillFromPublication}"  ajax="true">
                <f:param name="theskill" value="#{skill}" />
            </h:commandButton>


    </h:form>
</ui:repeat>

</ui:composition>

UPDATE 1 :

this my controller

@Controller
@Scope(value = WebApplicationContext.SCOPE_REQUEST)
public class SkillsController extends BController {

    private static final Logger logger = LoggerFactory
            .getLogger(SkillsController.class);

    public void removeSkillFromPublication() {
        logger.info("Deleting : " + getParameter("theskill"));
        publicationService.removeSkillFromPublication(publicationDetailView
                .getPublicationFullView().getId(), getParameter("theskill"));
        skillsView.setSkills(publicationService
                .getSkillsFromPublication(publicationDetailView
                        .getPublicationFullView().getId()));
    }



}

i don't get the the logger neither the task is executed , i already tested with actionlistner with controller with actionevent and this doesent work

UPDATE 2 :

It's working with changing the SCOPE of the skillsView To WebApplicationContext.SCOPE_SESSION , anybody know why ?!!

@Controller
@Scope(value = WebApplicationContext.SCOPE_SESSION)
public class SkillsView {

    List<String> skills;
    private String currentSkill;


    public List<String> getSkills() {
        return skills;
    }
    public void setSkills(List<String> skills) {
        this.skills = skills;
    }
    public String getCurrentSkill() {
        return currentSkill;
    }
    public void setCurrentSkill(String currentSkill) {
        this.currentSkill = currentSkill;
    }

Upvotes: 0

Views: 117

Answers (1)

Vogel612
Vogel612

Reputation: 5647

The h:commandButton attribute action requires you to return a String

Taken from the jsf-toolbox:

action
The action attribute accepts a method-binding expression for a backing bean action method to invoke when this component is activated by the user. An action method must be a public method with no parameters that returns a String. The returned string represents the logical outcome of the action (eg. "success", "failure", etc. ) and is used by the JavaServer Faces MVC framework to determine which view to display next. [bolding by me]

Instead use the actionListener property:

<h:commandButton actionListener="${skillsController.removeSkillFromPublication()}" ajax="true">
    <f:param name="theskill" value="#{skill}" />
</h:commandButton>

Keep in mind you will have to change the method-signature to have an ActionEvent as parameter:

public void removeSkillFromPublication(ActionEvent e) {
   //...

See the toolbox:

actionListener
The actionListener attribute accepts a method-binding expression for a backing bean action listener method that will be notified when this component is activated by the user. An action listener method must be a public method with an ActionEvent parameter and a void return type.


Alternatively you could have your removeSkillFromPublication() return a String. But that seems to be the wrong approach here.

Upvotes: 1

Related Questions