DelonPrinsloo
DelonPrinsloo

Reputation: 95

Managed bean property not being set from p:inputText in composite component

Good day everyone! I hope you are all doing well

In my Java Spring boot project with Primefaces and JSF, I have a generic controller and in that controller is a List of generic objects. I have an implementation controller for that generic controller and in the implementation controller, the generic is implemented with an entity class. My problem is that the Primefaces inputText does not update a value on the implemented entity. Here is the code:

The generic controller:

public abstract class TreeSearchController<S extends TreeSearchParamsEntity<S>> {

    final private TreeSearchService<S> service;
    final private UserSession userSession;
    protected List<S> searchParamsList;
    protected String treeType;

    public TreeSearchController(TreeSearchService<S> service, String treeType, UserSession userSession) {
        this.service = service;
        this.treeType = treeType;
        this.userSession = userSession;
        getSearchParamsList();
    }

    public List<S> getSearchParamsList() {
        System.out.println("GET CALLED");
        if (Objects.isNull(searchParamsList)) {
            System.out.println("GET CALLED WITH NULL");
            searchParamsList = loadSearchParamList(treeType);           
        }
        return searchParamsList;
    }

    public void setSearchParamsList(List<S> searchParamsList) {
        System.out.println("SET CALLED");
        this.searchParamsList = searchParamsList;
    }


    protected List<S> loadSearchParamList(String treeType) {
        return service.getSearchParamList(treeType);
    }

    protected String getSearchJsonString(String operator) {
        System.out.println("SEARCH CALLED");
        /* for (var entry : searchParamsList) {
            System.out.println(entry.getLabelName());
            System.out.println(entry.getFieldValue());
        } */
        return service.getSearchJsonString(searchParamsList, operator);
    }

    // --GETTERS AND SETTERS--

    public String getTreeType() {
        return treeType;
    }


    public void setTreeType(String treeType) {
        this.treeType = treeType;
    }

    public TreeSearchService<S> getService() {
        return service;
    }

    public UserSession getUserSession() {
        return userSession;
    }
}

Here is the generic entity:

public interface TreeSearchParamsEntity<S> {
    String getTreeType();

    void setTreeType(String treeType);

    String getTableName();

    void setTableName(String fieldName);
    
    String getFieldName();

    void setFieldName(String fieldName);
    
    String getLabelName();

    void setLabelName(String labelName);
    
    String getDataType();

    void setDataType(String dataType);
    
    String getFieldValue();

    void setFieldValue(String fieldValue);
}

Here is the generic controller implementation controller:

@Named
@ViewScoped
public class FinancialTreeSearchController extends TreeSearchController<FinancialSearchFieldsClass> implements Serializable {
    private final FinancialTreeController treeController;

    @Inject
    public FinancialTreeSearchController(UserSession userSession, FinancialSearchService financialSearchService, FinancialTreeController treeController) {
        super(financialSearchService, "HIERARCHY", userSession);
        this.treeController = treeController;
    }

    public void findFinClass() {
        treeController.findFinClass(getSearchJsonString("AND"));
    } 

    public FinancialTreeController getTreeController() {
        return treeController;
    }

}

The inputText component is in a dialog and here is the dialog controller:

@Named
@ViewScoped
public class FinancialClassSearchDlgController {    
    private final FinancialTreeSearchController financialTreeSearchController;
    

     @Inject
    public FinancialClassSearchDlgController(FinancialTreeSearchController financialTreeSearchController) {        
        this.financialTreeSearchController = financialTreeSearchController;
    }

   
    public void onFind() {
        PrimeFaces.current().dialog().closeDynamic(financialTreeSearchController.getSearchParamsList());        
    }

    public void onCancel() {
        PrimeFaces.current().dialog().closeDynamic(null);
    }

    public FinancialTreeSearchController getFinancialTreeSearchController() {
        return financialTreeSearchController;
    }   
}

Here is the 2 relevant xhtml files. The main file uses a cc component and in that cc component is the inputText:

The main file:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:search="http://xmlns.jcp.org/jsf/composite/resources/components/tree-search">

<h:head>
    <f:facet name="first">
        <meta http-equiv="X-UA-Compatible"
            content="IE=edge" />
        <meta http-equiv="Content-Type"
            content="text/html; charset=UTF-8" />
        <meta name="viewport"
            content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
        <meta name="apple-mobile-web-app-capable"
            content="yes" />
    </f:facet>
    <title>Search Hierarchy</title>
</h:head>

<h:body>
    <h:form prependId="false">
        <p:toolbar styleClass="sub-toolbar">
            <p:toolbarGroup>
                <p:commandButton value="Find"
                    styleClass="p-mr-2 p-mb-2"
                    action="#{financialClassSearchDlgController.onFind}"
                    process="@form" />
                <p:commandButton value="Cancel"
                    styleClass="p-mr-2 p-mb-2"
                    action="#{financialClassSearchDlgController.onCancel}"
                    process="@this" />
            </p:toolbarGroup>
        </p:toolbar>
        <search:tree-search controller="#{financialTreeSearchController}" />
    </h:form>

    <h:outputStylesheet name="omega-layout/css/primeicons.css" />
    <h:outputStylesheet name="omega-layout/css/primeflex.min.css" />
    <h:outputStylesheet name="omega-layout/css/layout-blue.css" />
    <h:outputStylesheet name="imms-layout/css/layout-custom.css" />
</h:body>

</html>

The cc file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:p="http://primefaces.org/ui"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:cc="http://xmlns.jcp.org/jsf/composite">

<cc:interface>
    <cc:attribute name="controller"
        required="true"
        type="com.imms.components.treeSearch.TreeSearchController" />

</cc:interface>
<cc:implementation>
    <p:card>
        <p:scrollPanel>
            <p:dataTable var="entry"
                value="#{cc.attrs.controller.searchParamsList}">
                <p:column headerText="Field Name">
                    <p:outputLabel value="#{entry.labelName}:"
                        styleClass="form-label" />
                </p:column>
                <p:column headerText="Value">
                    <p:inputText id="#{entry.fieldName}"
                        value="#{entry.fieldValue}" />
                </p:column>
            </p:dataTable>
        </p:scrollPanel>
    </p:card>
</cc:implementation>

</html>

Inside the cc file, you will see the entry.fieldValue that should be set with the inputText, however upon submission, it is still null.

Does anyone please know what the problem might be? And sorry for the information overload XD

What I have tried:

Upvotes: 0

Views: 34

Answers (0)

Related Questions