I'm trying to develop a reusable data picker. It will be used to lookup to related data and set in managed bean property.
What I'm trying to archieve is something like this:
1) A composite with an input text and lookup button:
2) When user clicks on search button, it opens a new page.
3) This page allows to search for a specific record
4) Once it is found, user clicks on a button and chooses it
5) When user clicks on check button (last column in the table above), it sets value in field bound to input (#1).
The search is always done in the same entity because it is a data picker for such entity but the destination is not known because it is a reusable component.
How do I make connection between search results, what user chooses and destination object (which is a managed bean's property)?
I have no idea on how to proceed.
Thanks in advance,
EDIT
MORE INFO: After some research I found a way to pass managed bean and property/actionListener. I'll explain what I did and later describe what is the problem now.
1) Created a sample page (sample1.xhtml). It is a composition/fragment:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<ui:fragment xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:b="http://bootsfaces.net/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:bt="http://xmlns.jcp.org/jsf/composite/tags/bt"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough">
<ui:composition template="/templates/pages/form.xhtml">
<ui:param name="title" value="Manage Value Object Category" />
<ui:define name="toolbar">
</ui:define>
<ui:define name="form-fields">
<c:set var="variable" value="#{valueObjectBean}" scope="request" />
<p:commandButton actionListener="#{valueObjectBean.doTest()}"
value="test" update="@form" />
</ui:define>
<ui:define name="bar-cmd">
</ui:define>
</ui:composition>
</ui:fragment>
Please note:
a) c:set sets to a request scoped variable the managed bean to call.
b) valueObjectBean.doTest() just replaces the composition to be shown.
2) This is destination page:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<ui:fragment xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:b="http://bootsfaces.net/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:bt="http://xmlns.jcp.org/jsf/composite/tags/bt"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough">
<ui:composition template="/templates/pages/form.xhtml">
<ui:param name="title" value="Manage Value Object Category" />
<ui:define name="toolbar">
</ui:define>
<ui:define name="form-fields">
<h:outputText value="Hello: #{variable}" />
<p:commandButton id="call" actionListener="#{variable['doTest'](null)}"
value="Execute" />
<p:commandButton id="set" value="Set">
<f:setPropertyActionListener value="true"
target="#{variable['actAddCatItem']}"></f:setPropertyActionListener>
</p:commandButton>
</ui:define>
<ui:define name="bar-cmd">
</ui:define>
</ui:composition>
</ui:fragment>
Please note:
a) commandButton with id "call" calls an action listener from managed bean set in #1a: {variable'doTest'}. Call method 'doTest' from managedBean passed as variable to 'variable'.
b) Just to mention but it's not important now. Another commandButton with id "set" just sets a property to managed bean set in #1a. I won't explore this option yet.
Now, what is happening:
1) When # c:set is request scoped (scope="request"), second page "sees" the managed bean passed as parameter:
a) As you can see, it outputs toString of managed bean but when I click on command button with id "call", I get this error:
16:59:24,901 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-39) /WEB-INF/lib/infra-wm-1.0.jar/META-INF/resources/infra/valueobject/sample2.xhtml @24,44 target="#{variable['actAddCatItem']}": Target Unreachable, identifier 'variable' resolved to null: javax.el.PropertyNotFoundException: /WEB-INF/lib/infra-wm-1.0.jar/META-INF/resources/infra/valueobject/sample2.xhtml @24,44 target="#{variable['actAddCatItem']}": Target Unreachable, identifier 'variable' resolved to null
If I change c:set scope to 'view' this approach works well. But I can't use this scope because there might be more than one composite using same approach in the page (in the end it is a composite component).
The question now is: Why sample 2 recognise 'variable' when it is view scope and doesn't when it's request scoped despite value is passed correctly and it is not NULL?
Thanks,