0

i want to test the spring bean's injection into jsf managed bean by passing a prefilled list , it's giving me nullpointer exception .. the jsf is rendered and showing no records found ...

JSF page :

    <p:dataTable value="#{testController.list}" var="type">
        <p:column headerText="Lib">
            <h:outputText value="#{type}">
            </h:outputText>
        </p:column>
    </p:dataTable>

JSF bean :

@ManagedBean
@SessionScoped
public class TestController {   
    @ManagedProperty(value = "#{documentService}")
    DocumentService documentService;

    private List<String> list = new ArrayList<String>();

public List<Rhnom> getList() {      
    try {
        list = documentService.getTypesDocuments();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return list;
    }   //setter

Spring Service :

@Service
public class DocumentServiceImpl implements DocumentService {

    @SuppressWarnings("serial")
    @Override
    public List<String> getStaticList (){
        List<String> list2 = new ArrayList<String>() {{
            add("s1");
            add("s2");
            add("s3");
        }};
        return list2;
    }

Faces config :

org.springframework.web.jsf.el.SpringBeanFacesELResolver
  • can you load the code in guthub to check it? – Alejandro Gonzalez Jun 29 '20 at 22:28
  • 2
    @AlejandroGonzalez: Please never ask to upload 'the code' in Github or any other external source. Questions should contain a [mcve] inline and in many, many cases can. – Kukeltje Jun 30 '20 at 06:48
  • This question is not good in several ways: 1) The title is wrong.It has nothing do do with a list but with the **service** that provides the list. That service is (most likely) not injected 2) OP should post **where** the NPE occurs. Otherwise it is a duplicate of https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it 3) The `p:dataTable` code is not related, a `h:outputText` would result in the same problem. Effectively OP is asking: _"My Spring managed service is not injected in my JSF managed bean"_. For this, several questions exists in Stackoverflow – Kukeltje Jun 30 '20 at 06:50
  • Does this answer your question? [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 Jun 30 '20 at 06:55
  • Oh and the fact the the NPE makes it show ' No results' is because you catch it... So that is not related either... ;-) – Kukeltje Jun 30 '20 at 07:30

0 Answers0