MrBool
You must be logged in to give feedback. Click here to login
[Close]

You must be logged to download.

Click here to login

[Close]

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

[Close]

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Advanced Searching with Seam framework

Seam provides some facilities of Advanced Searching. This article will discuss about Advanced Searching with Seam framework.

[close]

You didn't like the quality of this content?

Would you like to comment what you didn't like?

Seam provides some facilities of Advanced Searching. We all know that Seam is a strong component based framework. Searching is very important for any framework.

There are many frameworks, which allow implement their first crack at content searching. It works independently but does not give the search experience users expect today. However, seam can provide a specific searching component. For example, if the search query is computer software and the blog contains text or other like "what we supply both by the parameter computers and software", the normal like query that will not work, because of the word and is in the middle point. Therefore, trying to solve such kind of problems with complex type of SQL constructions becomes a nightmare and gives poor results. SEAM provides even worse and these types of like-based queries that have severe performance problems as the data set grows, because it does not use any type of indexing. It must search through the entire corpus, one character at a time.

Seam integrates many technologies like JavaScript, JSP, JSTL, Ajax, JPA, JBPM and servlet. Seam is an application development framework for Java EE that connected the component and other models of JSF and EJB 3.0 that is a strong component dependent framework, providing a streamlined searching model for web-based java and j2ee enterprise applications.

Listing 1: JSP code:


package com.domtech.domain.config;
import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
import org.jboss.seam.annotations.Name;
@Entity
@Table(name = "ADMIN_UNION")
@Name("union")
public class AdminUnion implements java.io.Serializable {
	private long unionId;
	private AdminUpazila adminUpazila;
	private String unionNameEng; 
     public AdminUnion() {
	}
public AdminUnion(long unionId, AdminUpazila adminUpazila) {
		this.unionId = unionId;
		this.adminUpazila = adminUpazila;
	}
	public AdminUnion(long unionId, AdminUpazila adminUpazila
) {
		this.unionId = unionId;
		this.adminUpazila = adminUpazila;
		this.unionNameEng = unionNameEng;	
	}
@Id@GeneratedValue
	@Column(name = "UNION_ID", unique = true, nullable = false, precision = 20, scale = 0)
	@NotNull
	public long getUnionId() {
		return this.unionId;
	}
	public void setUnionId(long unionId) {
		this.unionId = unionId;
	}
      @Column(name = "UNION_NAME_ENG", length = 250)
	@Length(max = 250)
	public String getUnionNameEng() {
		return this.unionNameEng;
	}
public void setUnionNameEng(String unionNameEng) {
		this.unionNameEng = unionNameEng;
	}	

Now we will show the ‘AdpSectorList’, which extends ‘EntityQuery’. The ‘EntityQuery’ execute a tremendous searching option with the help of xml and xhtml. The connection with entity, List property class, xml and xhtml provide the excellent facility of Advanced Searching by using SEAM framework.

Listing 2: AdpSectorList:

package com.domtech.service.adp.adpSector;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityQuery;
import com.domtech.domain.adp.AdpSector;
import com.domtech.ejb.util.Constants;
import java.util.Arrays;
@Name("adpSectorList")
public class AdpSectorList extends EntityQuery<AdpSector> {
	private static final String EJBQL = "select adpSector from AdpSector adpSector order by adpSector.serialPriority ASC";
    private static final String[] RESTRICTIONS = {
			"lower(adpSector.sectorNameEng) like lower(concat(#{adpSectorList.adpSector.sectorNameEng},'%'))",
			"lower(adpSector.sectorNameBen) like lower(concat(#{adpSectorList.adpSector.sectorNameBen},'%'))",
			"lower(adpSector.statusInfo) like lower(concat(#{adpSectorList.adpSector.statusInfo},'%'))", };

	private AdpSector adpSector = new AdpSector();
       public AdpSectorList() {
		setEjbql(EJBQL);
		setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
		setMaxResults(Constants.DEFAULT_RECORD_IN_VIEW);
	}
	public AdpSector getAdpSector() {
		return adpSector;
	}
}

We will provide a sample example how seam framework enable searching facilities. For this reason, we will provide the code sincere gradually. Seam framework generates the entities and this entity connects with ‘Entity Query’. Which provide a excellent feature of searching with the help of ‘xml’ and ‘xhtml’. We know ‘xhtml’ is a case sensitive markup language. So we should be careful when we are going to coding with it. Therefore, Seam works with JBoss and j2ee. BY using Seam framework, we can bind our EJB components directly to JSF pages, so we do not need to go through any kind of XML configuration for that.

Now we will preview the xml, which connect and make interlink with Java action and presentation layer. In addition, Seam provides all the quick outlook of it.

Listing 3: XML code:

<?xml version="1.0" encoding="UTF-8"?>
<page xmlns="http://jboss.com/products/seam/pages"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd">
<description>
   Round List: #{adminSectorList.resultList.size} of #{adminSectorList.resultCount}
  </description>
  <begin-conversation join="true"/>
   <param name="firstResult" value="#{adminSectorList.firstResult}"/>
   <param name="sort" value="#{adminSectorList.orderColumn}"/>
   <param name="dir" value="#{adminSectorList.orderDirection}"/>
   <param name="logic" value="#{adminSectorList.restrictionLogicOperator}"/>

   <param name="from"/>
   <param name="sectorNameEng" value="#{adminSectorList.adminSector.sectorNameEng}"/>
   <param name="sectorNameBen" value="#{adminSectorList.adminSector.sectorNameBen}"/>
   <param name="statusInfo" value="#{adminSectorList.adminSector.statusInfo}"/>
</page>	

Now we present the presentation layer of advanced Searching, which come to be true by the help of XHTML page that call a markup language page.

Listing 4: Presentation layer of advanced Searching:

<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a4j="http://richfaces.org/a4j"
    template="#{moduleSelect.nowSelectedBody}"> 

<ui:define name="body">
<a4j:form id="Search" ajaxSubmit="true"  reRender="dataPanel">
<a4j:commandButton value="Create Sector" action="#{sectorManager.createSector}" oncomplete="javascript:Richfaces.showModalPanel('editPanel')"
reRender="frmDiv" style="width:100px"> 
	</a4j:commandButton>
 <a4j:outputPanel id="dataPanel" ajaxRendered="true">
        <rich:simpleTogglePanel label=" Sector Search Filter" switchType="ajax">
        <f:facet name="openMarker" >
        	<h:graphicImage url="/img/down.gif"/>
        </f:facet>
        <f:facet name="closeMarker" >
        	<h:graphicImage url="/img/up.gif"/>
        </f:facet>
        <h:outputText id="del" style="font-color:red;" styleClass="delLabel" value="#{sectorManager.msg}"/>
       <rich:panel>
		<h:panelGrid columns="3" columnClasses="searchCol1,searchCol2,searchCol3">
<h:outputLabel value="Sector Name (English)"/>
			<h:outputLabel value=":"/>
            <h:inputText id="sectorNameEng" styleClass="inputField" value="#{adminSectorList.adminSector.sectorNameEng}"/>
<h:outputLabel value="Sector Name (Bangla)"/>
			<h:outputLabel value=":"/>
            <h:inputText id="sectorNameBen" styleClass="inputField" value="#{adminSectorList.adminSector.sectorNameBen}"/>
<h:outputText value="Match"></h:outputText>
		<h:outputText value=":"></h:outputText>
             <h:selectOneRadio id="logic" value="#{adminSectorList.restrictionLogicOperator}" styleClass="radio">
               <f:selectItem itemLabel="All" itemValue="and"/>
               <f:selectItem itemLabel="Any" itemValue="or"/>
            </h:selectOneRadio>
<script>makePhoneticEditor('Search:sectorNameBen')</script>
</h:panelGrid>
        </rich:panel>
        </rich:simpleTogglePanel>
<ui:include src="/includes/searchButtons.xhtml"/>  
<rich:panel>
        <f:facet name="header"> Sector Search Results (#{empty adminSectorList.resultList ? 0 : (adminSectorList.paginated ? adminSectorList.resultCount : adminSectorList.resultList.size)})</f:facet>
    <div class="results" id="adminSectorList">
<h:outputText value="Sector search returned no results."
               rendered="#{empty adminSectorList.resultList}"/>
<rich:dataTable id="adminSectorList"
                var="adminSector"
              value="#{adminSectorList.resultList}"
           rendered="#{not empty adminSectorList.resultList}">
       <h:column>
            <f:facet name="header">
                <ui:include src="/includes/sort.xhtml">
                    <ui:param name="entityList" value="#{adminSectorList}"/>
                    <ui:param name="propertyLabel" value="Sector  (English)"/>
                    <ui:param name="propertyPath" value="adminSector.sectorNameEng"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{adminSector.sectorNameEng}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <ui:include src="/includes/sort.xhtml">
                    <ui:param name="entityList" value="#{adminSectorList}"/>
                    <ui:param name="propertyLabel" value="Sector  (Bangla)"/>
                    <ui:param name="propertyPath" value="adminSector.sectorNameBen"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{adminSector.sectorNameBen}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <ui:include src="/includes/sort.xhtml">
                    <ui:param name="entityList" value="#{adminSectorList}"/>
                    <ui:param name="propertyLabel" value="Status"/>
                    <ui:param name="propertyPath" value="adminSector.statusInfo"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{adminSector.statusInfo}"/>
        </h:column>
       <rich:column styleClass="action">
            <f:facet name="header">Action</f:facet>
			
			<a4j:commandLink ajaxSingle="true" id="editlink1"
								oncomplete="#{rich:component('editPanel2')}.show()"
								action="#{sectorManager.editSectorForm(adminSector)}"  reRender="editPanel,editButton,saveButton"
								styleClass="formLabel">						
			<h:outputText value="View" />
			</a4j:commandLink>
            #{' '}
<a4j:commandLink ajaxSingle="true" id="editlink18"
								oncomplete="#{rich:component('editPanel2')}.show()"
								action="#{sectorManager.editSectorForm_1(adminSector)}"  reRender="editPanel,editButton,saveButton"
								styleClass="formLabel">						
			<h:outputText value="Edit" />
			</a4j:commandLink>
</rich:column>
    </rich:dataTable>
</div>
    <ui:include src="/includes/pagination.xhtml">
          <ui:param name="entityList" value="#{adminSectorList}"/> 
    </ui:include> 
    </rich:panel>
    </a4j:outputPanel>
</a4j:form>
<rich:modalPanel height="200" id="editPanel" autosized="true" width="600">

			<f:facet name="header">
				<h:outputText value="Sector" styleClass="textTopMenu" />
			</f:facet>
			
			<f:facet name="controls">
				<h:panelGroup>
					<h:graphicImage value="/images/modal/close.png" id="hidelink"
						styleClass="hidelink" />
					<rich:componentControl for="editPanel" attachTo="hidelink"
						operation="hide" event="onclick" />
				</h:panelGroup>
			</f:facet>
		<h:form id="frmDiv">
			<h:outputText value="Mandatoryfield ( * )" styleClass="enMandatory"/><br/><br/>
			<rich:panel>
			 <a4j:outputPanel ajaxRendered="true">
			
				 <h:panelGrid columns="5" columnClasses="colModal1,colModal2, colModal3, colModal4, colModal5" >                  
                   	                     
	                    <h:outputLabel for="engName" value="Sector (English)" styleClass="formLabel"/>
	                    <h:outputText value=":"  />
	                    <h:outputLabel value="*" for="engName" style="color:red"/>	
	                    <h:inputText id="engName" value="#{sector.sectorNameEng}"
	                    	required="true" requiredMessage="#{messages.entervalue}" styleClass="inputField"/>
	                     <rich:message for="engName" style="color:red; font-style:italic;"/>
	                    
	                    <h:outputLabel for="banName" value="Sector (Bangla)" styleClass="formLabel"/>
	                    <h:outputText value=":"  />
	                    <h:outputLabel value="*" for="banName" style="color:red"/>	
	                    <h:inputText id="banName" value="#{sector.sectorNameBen}"
	                    	required="true" requiredMessage="#{messages.entervalue}" styleClass="inputField"/>
	                     <rich:message for="banName" style="color:red; font-style:italic;"/>  
                        <h:outputLabel for="activation" value=" Status" styleClass="formLabel"/>
	                    <h:outputText value=":"  />
	                    <h:outputText value="" /> 
	                      <h:selectOneRadio id="activation" value="#{sector.statusInfo}" styleClass="formLabel" style="width:180px;">
	                    	<f:selectItem id="item1" itemLabel="Active" itemValue="Active"/>
  							<f:selectItem id="item2" itemLabel="Inactive" itemValue="Inactive" />
	                    </h:selectOneRadio>	
	                    <h:outputText value="" />
	                     <script>makePhoneticEditor('frmDiv:banName')</script>     
                </h:panelGrid>  
                                               
				</a4j:outputPanel>

				<div align="center">
				
				<a4j:commandButton value="Save" 
					action="#{sectorManager.addSector(sector)}"	reRender="dataPanel"
					oncomplete="if (#{facesContext.maximumSeverity==null})  #{rich:component('editPanel')}.hide();return false;"
					  />
				<a4j:commandButton value="Close" immediate="true" 	
			 			onclick="#{rich:component('editPanel')}.hide();return false;" />					
				</div>
				</rich:panel>
				</h:form>
				</rich:modalPanel>
</ui:define>
</ui:composition>

By the combination of all of this code combination we can able to achieve the feature of advanced searching. By the using of advanced searching option, we can retrieve the data from any database depend on our requirement. This is helpful for any web application of website.

So, the integration of advanced searching option is very powerful scenario of SEAM framework that provides a fast searching among the databases.

Provide screen short of SEAM advanced searching

Figure 1: Provide screen short of SEAM advanced searching.

This is all for this article. See you next time.



My main area of specialization is Java and J2EE. I have worked on many international projects like Recorders,Websites,Crawlers etc.Also i am an Oracle Certified java professional as well as DB2 certified

What did you think of this post?
Services
Know how to keep MrBool Online
SUPPORT US
SUPPORT US
With your help, we can keep providing free content and helping you to be a better professional
support us
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually � in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits � in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login