0

I am trying to integrating spring and JSF(Primefaces).I configured the spring controller as component using @component annotation to be worked as JSF bean but it is not calling the action method of commandbutton.

XHTML File:

<h:form id="productForm" >
                <h:panelGrid columns="1">
                    <p:outputLabel for="name" value="Name: " />
                    <p:inputText id="name" value="#{cust.customerForm.name}" />
                    <p:outputLabel for="address" value="address" />
                    <p:inputNumber id="address" value="#{cust.customerForm.address}" />
                    <p:outputLabel for="email" value="Email: " />
                    <p:inputNumber id="email" value="#{cust.customerForm.email}" />
                    <p:outputLabel for="mobile" value="Mobile: " />
                    <p:inputNumber id="mobile" value="#{cust.customerForm.mobile}" />
                    <p:commandButton value="Save" action="#{cust.save}" />
                </h:panelGrid>
        </h:form> 

Spring controller used as JSF Bean:

@Scope(value="session")
@Component(value = "cust")
@ELBeanName(value = "cust")
@Controller
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerRepository customerRepo;

    private List<Customer> customerList;

    private Customer customerForm;

      public List<Customer> getCustomerList() {
        return customerList;
    }



      public Customer getCustomerForm() {
        return customerForm;
    }



    public void setCustomerForm(Customer customerForm) {
        this.customerForm = customerForm;
    }

    public String save(){
        System.out.println("save called:::::::::::");
         return("Customer");
    }
}

kindly help me out in figuring out what wrong I am doing.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Nishant Varshney
  • 685
  • 2
  • 14
  • 34
  • Did you try to put the title of the question in google? https://stackoverflow.com/questions/18387993/spring-jsf-integration-how-to-inject-a-spring-component-service-in-jsf-managed – Kukeltje Aug 13 '18 at 08:56
  • Possible duplicate of [Spring JSF integration: how to inject a Spring component/service in JSF managed bean?](https://stackoverflow.com/questions/18387993/spring-jsf-integration-how-to-inject-a-spring-component-service-in-jsf-managed) – Kukeltje Aug 13 '18 at 08:56
  • @Kukeltje I am using spring managed beans and the method which I need to call by commandbutton is a spring controller method.... So is there any way to call the method of spring managed bean used as controller as well from JSF commandButton.. – Nishant Varshney Aug 13 '18 at 10:32
  • What did you try from the duplicate? – Kukeltje Aug 13 '18 at 10:45
  • From the duplicate I tried component annotation to use a class as JSF backing bean in spring... – Nishant Varshney Aug 13 '18 at 10:57
  • Tried the resolver? And if not, why not (it is the most mentioned solution on the internet) – Kukeltje Aug 13 '18 at 11:08
  • @Kukeltje already tried the el-resolver in the faces config... – Nishant Varshney Aug 13 '18 at 11:10
  • Thank you for **not** mentioning that. So you run your jsf application in development mode, and don't have any errors but it does not do anything either. Did you try adding a `p:messages`? http://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value – Kukeltje Aug 13 '18 at 11:14
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/177941/discussion-between-nishant-varshney-and-kukeltje). – Nishant Varshney Aug 13 '18 at 11:52

1 Answers1

0

You need to configure the org.springframework.web.jsf.el.SpringBeanFacesELResolver in your faces-config.xml. Otherwise JSF can't find spring beans.

When combining JSF and Spring Boot, you should definetl try Joinfaces which does exaclty this (and some other helpfull stuff)

larsgrefer
  • 2,735
  • 19
  • 36