jsf 2 - Reusing JSF2 View Scoped Bean on facelets templating -
i have common task choose 1 or more 'localizacaoto' before doing else on page.
currently logic of data retrieval/process/ajax events , on maintained on viewscoped
bean called "seletorlocalizacaomb" , i’d use multiple instances of same bean on same page.
firstly used composite component when chose node, stored on last bean on page.
if had 3 instances declared on testeseletormb:
@named @viewscoped public class testeseletormb implements serializable { @inject @getter @setter private seletorlocalizacaomb instanceone; @inject @getter @setter private seletorlocalizacaomb instancetwo; @inject @getter @setter private seletorlocalizacaomb instancethree; }
no matter component on page used, instancethree hold values.
based on research understood composite component not ideal solution problem.
so changed ui implementation , used facelets create 'template' named seletor.xhtml.
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"> <p:dialog header="busca hierarquica" id="#{id}modaltree" widgetvar="dlgselecaohierarquica" showeffect="fade" hideeffect="fade" closeonescape="true" modal="#{bloqueiamodal}" height="400px" width="500px"> <h:panelgrid columns="2"> <p:commandbutton id="#{id}btnselecao" value="selecionar e voltar" action="#{mb['selecionarlocalhierarquico']}" update="@(.#{id}-auto-complete)" oncomplete="bloqueiaautomulti();"/> <p:commandbutton value="voltar" type="button" onclick="pf('dlgselecaohierarquica').hide();" /> </h:panelgrid> <p:scrollpanel style="width:100%;height:350;" mode="native"> <p:tree id="#{id}tree" style="width:100%;height:100%;" styleclass="estilo-arvore" value="#{mb.arvorehierarquica}" var="local" selectionmode="multiple" dynamic="true" animate="true"> <p:ajax event="select" listener="#{mb['onnodeselect']}" update="@this"/> <p:treenode > <h:outputtext value="#{local.cdclasselocal}: #{local.cdlocalizacao} #{local.niveis}" /> </p:treenode> </p:tree> </p:scrollpanel> </p:dialog> </ui:composition>
test page using <ui:include>
<f:subview id="seletoralpha"> <ui:include src="/template/seletor.xhtml"> <ui:param name="mb" value="#{testeseletormb.seletoralpha}" /> <ui:param name="id" value="alpha" /> </ui:include> </f:subview> <f:subview id="seletorbravo"> <ui:include src="/template/seletor.xhtml"> <ui:param name="mb" value="#{testeseletormb.seletorbravo}" /> <ui:param name="id" value="bravo" /> </ui:include> </f:subview>
test bean holding multiple instances:
import javax.inject.named; import org.omnifaces.cdi.viewscoped; @named @viewscoped public class testeseletormb implements serializable { @inject @getter @setter private seletorlocalizacaomb seletoralpha; @inject @getter @setter private seletorlocalizacaomb seletorbravo; }
cdi bean used on 'seletor.xhtml'
import javax.inject.named; import org.omnifaces.cdi.viewscoped; @named @viewscoped public class seletorlocalizacaomb implements serializable { private list<localizacaoto> locaishierarquicosselecionados; private treenode arvorehierarquica; //postconstruct, ajax events , things :) }
in example, want testeseletormb variables (seletoralpha , seletorbravo) hold different values on lists. possible?
i tried change seletorlocalizacaomb scoped @dependent
didn't work neither. here things got confused. reading cdi api, first state says:
beans declared scope @dependent behave differently beans other >built-in scope types. when bean declared have scope @dependent:
no injected instance of bean ever shared between multiple injection >points.
it should't hold same instance, right?!
environment
- websphere application server 8.5.5.2
- apache myfaces 2.0.2
- primefaces 5.0
- omnifaces 1.7
i can provide additional data if necessary. didn't paste 'seletorlocalizacaomb' code because has many dependencies , had feeling problem not related how class handles actions.
Comments
Post a Comment