Add to MasterEditor.java:
private static final String EJB_QL = "SELECT d FROM Detail d " +
"WHERE d.master = ?1 AND d.detailDescription like ?2";
private Query detailQuery;
private String filterDescription;
public String getFilterDescription() { return this.filterDescription; }
public void setFilterDescription(String filterDescription) { this.filterDescription = filterDescription; }
@SuppressWarnings("unchecked")
public String filterDetails() {
detailQuery.setParameter(1, getInstance());
detailQuery.setParameter(2, this.filterDescription + "%");
detailListFromMaster = (List) detailQuery.getResultList();
return "success";
}
Add to the front-end:
<rich:panel>
<f:facet name="header">Detail Filter</f:facet>
<s:decorate id="detailDescriptionFilterField" template="layout/edit.xhtml">
<ui:define name="label">Detail Description</ui:define>
<h:inputText id="detailDescriptionFilter"
size="100"
maxlength="100"
value="#{masterEditor.filterDescription}">
<a:support event="onblur" reRender="detailDescriptionFilterField" bypassUpdates="true" ajaxSingle="true"/>
</h:inputText>
</s:decorate>
<div class="actionButtons">
<a:commandButton id="doFilter"
value="Search"
action="#{masterEditor.filterDetails()}"
reRender="detailListTable">
<s:conversationId />
</a:commandButton>
</div>
</rich:panel>
The "wire()" function links the detailListFromMaster to the embedded list of Detail instances from within the Master that we're editing. This can be problematic, because wire() is called as a page action. This means every resubmission will re-trigger the wire() function, effectively overwriting the filtering that we've done. In order to stop this, change the XXX.page.xml to use on-postback = false:
<action execute="#{masterEditor.wire}" on-postback="false"/>
- Yeah, with your blog, I will learn a lot about Seam, because of I can talk with you about practical, real-life problem solutions. I will study you example, and we will see later...with a couple of questions, of course :-).. thanks for that,
ReplyDelete- best regards,....