I am facing a similar problem described in this SO thread Why does JSF null out a nested class successfully instantiated in the backing bean? I am having a simple form (JSF-2.2) to create an object with multiple nested objects and their respective properties. Instantiation happens successfully and I can see all objects and their children being not null but for some reason, when I submit the form, the entire object tree is getting set to null again. In the below example, the value template would result in
javax.el.PropertyNotFoundException: Target Unreachable, 'null' returned null.
because for some reason ArticleListConfiguration is being set to null right befor submit happens.
<ui:composition template="../template/template.xhtml">
<ui:define name="content">
<h:form id="createArticleListForm">
<p:panel styleClass="content-panel">
<h:panelGrid
columns="2"
styleClass="borderless-grid"
columnClasses="create-article-list-panel, create-article-list-panel">
<p:panel
id="listValuesPanel">
<p:inputText
id="articleListName"
value="#{createArticleListController.articleList.name}"/>
<p:inputText
id="articleListSize"
maxlength="3"
value="#{createArticleListController.articleListSize}">
</p:inputText>
<p:selectBooleanCheckbox
id="saveArticleListConfigurationAsTemplate"
value="#{createArticleListController.articleList.articleListConfiguration.template}"/>
<h:panelGrid
columns="1">
<p:fileUpload
id="upload"
widgetVar="fileUploadWidget"
fileUploadListener="#{createArticleListController.uploadImages}"
multiple="true"
onstart="submitSelection()"
oncomplete="handleMultiFileUploadRequest(PF('fileUploadWidget'));"
allowTypes="/(\.|\/)(jpg|png)$/"
styleClass="ui-widget"/>
<p:remoteCommand
name="submitSelection"
process="@this"/>
</h:panelGrid>
</p:panel>
</h:panelGrid>
<br/>
<p:commandButton
id="createArticleListButton"
process="@this @form"
value="#{contentController.getContent('createArticleList')}"
actionListener="#{createArticleListController.onCreate()}"/>
</p:panel>
</h:form>
</ui:define>
And here is the backing bean
@ManagedBean
@ViewScoped
public class CreateArticleListController extends AbstractController {
@Inject
private ArticleListService articleListService;
private ArticleList articleList;
private Integer articleListSize;
private List<Pair<String, InputStream>> files;
@PostConstruct
public void init() {
//The constructor of ArticleList creates and attaches instances of all necessary nested objects
articleList = new ArticleList();
files = new ArrayList<>();
}
public void onCreate() throws IOException {
articleListService.create(articleList, files);
navigateTo("articleListOverview");
}
public void uploadImages(FileUploadEvent event) {
try {
files.add(Pair.of(event.getFile().getFileName(), event.getFile().getInputstream()));
} catch (IOException e) {
LOGGER.log(Level.ERROR, "Error uploading files");
JsfMessageUtils.sendErrorMessageToUser("Error uploading files");
}
}
public ArticleList getArticleList() {
return articleList;
}
public void setArticleList(ArticleList articleList) {
this.articleList = articleList;
}
public Integer getArticleListSize() {
return articleListSize;
}
}