Unable to update parent window from modalPanel
sam-user Jun 30, 2009 6:41 AMHello,
I have a page with couple of input fields. For one of the fields(say FLD1) I need to perform additional searches(lookup). If I find 1 match I need to populate some of the other fields (say FLD2 and FLD3) with the values returned from the search. If more than one matches are found I need to open a modal panel and allow the user to select an item. That triggers one more search and the result should update the same fields (FLD2 and FLD3) on the parent panel.
I was able to implement the searches and the modalPanel, but I cannot make the modalPanel update the parent with the results of the second search.
Here is a what I have :
My main page contains this
...
<a:region id="locRegion">
<s:decorate id="alLocaField" template="layout/edit.xhtml">
<ui:define name="label">Loca</ui:define>
<h:inputText id="alLoca" value="#{alHome.instance.alLoca}" >
<a:support event="onblur" reRender="alLoca" eventsQueue="locLookup"/>
</h:inputText>
<a:commandButton value="SRequest" image="img/search.GIF" ajaxSingle="true" eventsQueue="locLookup"
id="searchImg" action="#{LocaSearch.search}" reRender="LocaPickList"
oncomplete="alert('Search returns #{!LocaSearch.found}');
if (#{!LocaSearch.found})
{
Richfaces.showModalPanel('locaPickList');
}
else
{
updLoc('#{LocaSearch.locCD.GU}','#{LocaSearch.locCD.MR}');
}" >
<a:support event="onclick" reRender="alLoca" eventsQueue="locLookup"/>
<a:actionparam name="alLoca" value="#{alHome.instance.alLoca}" assignTo="#{LocaSearch.locSearchString}" />
</a:commandButton>
<a:jsFunction name="updLoc" reRender="alDetailsPanel" >
<a:actionparam name="param1" assignTo="#{alHome.instance.alGU}" />
<a:actionparam name="param2" assignTo="#{alHome.instance.alMR}" />
</a:jsFunction>
</s:decorate>
<s:decorate id="alGUField" template="layout/edit.xhtml">
<ui:define name="label">GU</ui:define>
<h:inputText id="alGU" value="#{alHome.instance.alGU}">
<a:support event="onblur" reRender="alGUField" bypassUpdates="true" ajaxSingle="true"/>
</h:inputText>
</s:decorate>
<s:decorate id="alMRField" template="layout/edit.xhtml">
<ui:define name="label">MR</ui:define>
<h:inputText id="alMR" value="#{alHome.instance.alMR}">
<a:support event="onblur" reRender="alMRField" bypassUpdates="true" ajaxSingle="true"/>
</h:inputText>
</s:decorate>
</a:region>
....
<f:subview xmlns="http://www.w3.org/1999/xhtml"
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:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<a:outputPanel id="pickListPanel" layout="none">
<rich:modalPanel id="locaPickList" >
<f:facet name="header">
<h:panelGroup>
<h:outputText value="Loca Search Result"/>
</h:panelGroup>
</f:facet>
<f:facet name="controls">
<h:panelGroup>
<h:graphicImage value="/images/modal/close.png" styleClass="hidelink" id="hidelink"/>
<rich:componentControl for="locaPickList" attachTo="hidelink" operation="hide" event="onclick"/>
</h:panelGroup>
</f:facet>
<ui:include src="LocaSearchResult.xhtml" />
</rich:modalPanel>
</a:outputPanel>
</f:subview>My LocaSearchResult.xhtml contains the following
<rich:panel >
<h:form>
<rich:dataTable id="pl" var="_pl" value="#{pickList}" >
<h:column>
<f:facet name="header">
<h:outputText value="Criteria"/>
</f:facet>
<h:outputText value="#{_pl.criteria}"/><br/>
</h:column>
<h:column >
<f:facet name="header">
<h:outputText value="Description"/>
</f:facet>
<h:outputText value="#{_pl.description}"/><br/>
</h:column>
<h:column >
<a:commandButton value="Select" action="#{locaSearch.search}"
ajaxSingle="true" reRender="alDetailsPanel"
oncomplete="if (#{locationSearch.found})
{
alert('Found:' +#{locationSearch.locCD.GU}');
updLocP('#{locationSearch.locCD.GU}','#{locationSearch.locCD.MR}');
}" >
<a:actionparam name="alLocation" value="#{_pl.criteria}"
assignTo="#{alHome.instance.alLocation}" />
</a:commandButton>
<a:jsFunction name="updLocP" reRender="alDetailsPanel"
oncomplete="alert('js:'+'#{locationSearch.locCD.GU}');
alert('js1:' + param1);
Richfaces.hideModalPanel('locationPickList');" >
<a:actionparam name="param1" assignTo="#{alHome.instance.alGU}" />
<a:actionparam name="param2" assignTo="#{alHome.instance.alMR}" />
</a:jsFunction>
</h:column>
</rich:dataTable>
</h:form>
</div>
</rich:panel>I put some alerts to check what values do I get and I got a strange result.
The first alert says: "Found xxxxx" and this is what I would expect.
The second alert says: "js:". So the value of locationSearch.locCD.GU is null and I don't understand why.
The third alert says: "js1:xxxxx". Again the result I would expect.
The two fields of the main form, though, remain blank.
Could someone please give me a hint what am I doing wrong. Why aren't the two fields updated appropriately?
Thanks in advance.