Frameworks| Hibernate| Struts| JSF| JavaFX| Ajax| Spring| DOJO| JDO| iBatis| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Logic Match Tag (...) 
 

Match tag - We use this tag to evaluate the contents contained in the nested body parts of this tag if the specified value is an appropriate substring of the requested variable.

 

Logic Match Tag (<logic:match >...</logic:match >) 

                         

match tag - We use this tag to evaluate the contents contained in the nested body parts of this tag if the specified value is an appropriate substring of the requested variable.

This tag matches the variable specified as a String against the specified constant value. If the value is a substring  then the nested body content of this tag is evaluated.

Attributes of match Tag

 

 

 

 

Attribute Name Description
cookie

The variable to be matched is the value of the cookie whose name is specified by this attribute.

header

The variable to be matched is the value of the header whose name is specified by this attribute. The name match is performed in a case insensitive manner.

location

If not specified, a match between the variable and the value may occur at any position within the variable string. If specified, the match must occur at the specified location (either start or end) of the variable string.

name

The variable to be matched is the JSP bean specified by this attribute, if property is not specified, or the value of the specified property of this bean, if property is specified.

parameter

The variable to be matched is the first, or only, value of the request parameter specified by this attribute.

property

The variable to be matched is the property (of the bean specified by the name attribute) specified by this attribute. The property reference can be simple, nested, and/or indexed.

scope

The bean scope within which to search for the bean named by the name property, or "any scope" if not specified.

value

The constant value which is checked for existence as a substring of the specified variable.

 

Logic notMatch  Tag (<logic:notMatch  >...</logic:notMatch  >) 

notMatch - We use this tag to evaluate the contents contained in the nested body parts of this tag if the specified value is not a substring of the requested variable.

This tag matches the variable specified by one of  attributes (as a String) against the specified constant value. If the value is not a substring  the nested body content of this tag is evaluated.


Attributes of notMatch  Tag

Attribute Name Description
cookie

The variable to be matched is the value of the cookie whose name is specified by this attribute.

header

The variable to be matched is the value of the header whose name is specified by this attribute. The name match is performed in a case insensitive manner.

location

If not specified, a match between the variable and the value may occur at any position within the variable string. If specified, the match must occur at the specified location (either start or end) of the variable string.

name

The variable to be matched is the JSP bean specified by this attribute, if property is not specified, or the value of the specified property of this bean, if property is specified.

parameter

The variable to be matched is the first, or only, value of the request parameter specified by this attribute.

property

The variable to be matched is the property (of the bean specified by the name attribute) specified by this attribute. The property reference can be simple, nested, and/or indexed.

scope

The bean scope within which to search for the bean named by the name property, or "any scope" if not specified.

value

The constant value which is checked for existence as a substring of the specified variable.

 

Example Illustrating the use of the Match <logic:match > and the notMatch  <logic:notMatch  > logic tags.

Here you will learn to use the Struts  Logic tags. We will cover an example that will show  a comparison between  the two logic tags (ie..<logic:match > and the <logic:notMatch>).

Example code

Creating an Action  Class

Develop a simple action class LogicAction.java.

package roseindia.net;

import java.io.*;
import java.util.*;

/**

* @author Amit Gupta
* @Web http://www.roseindia.net
* @Email struts@roseindia.net

**/
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import org.apache.struts.action.*;

public class LogicAction extends Action 
{
  public ActionForward execute(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws IOException, ServletException {

      

        return mapping.findForward("success");
    }
}

Creating Form Bean

Our form bean class contains only one property text. Here is the code of FormBean (LogicForm.java)

package roseindia.net;

import org.apache.struts.action.*;

/**

* @author Amit Gupta
* @Web http://www.roseindia.net
* @Email struts@roseindia.net

**/

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class EmptyForm extends ActionForm 
{
    
    private String text = "";
       
  public String getText() 
    {
        return text;
    }
    
    public void setText(String text) 
    {
    this.text=text;
  }
   
    
  
    
}

Defining form Bean in struts-config.xml file

Add the following entry in the struts-config.xml file for defining the form bean

<form-bean name="LogicForm"  type="roseindia.net.LogicForm" />

 Developing the Action Mapping in the struts-config.xml

Here, Action mapping helps to select the method from the Action class for specific requests.

<action path="/LogicAction"
type="roseindia.net.LogicAction"
name="LogicForm"
scope="request"
input="/pages/InputLogic.jsp">
<forward name="success" path="/pages/output.jsp"/>
</action>

Developing the InputLogic.jsp page

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>

<html:html>
<head>
<title>Using &lt;logic&gt; Tags</title>
</head>

<body>
<h1>Using &lt;logic&gt; Tags</h1>

<html:form action="/LogicAction" method ="post">

<h2>Enter text:</h2>
<html:text property="text"/>

<br>
<h4>The &lt;logic:match&gt;tag works if the entered </h4>
<h4>text contains "amit"</h4>
<h4>The &lt;logic:notMatch&gt;tag always evaluate the </h4>
<h4>entered text against the"abc" value</h4>
<br>

<html:submit value="Submit"/>


<html:cancel/>
</html:form>
</body>
</html:html>

Developing the output.jsp page

Notice the values

<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>

<HTML>
<HEAD>
<TITLE>Here's Your Data...</TITLE>
</HEAD>

<BODY>
<H4>Here's Your Data...</H4>

<h4>The text entered is:

<bean:write name="LogicForm" property="text"/></h4>


<logic:match name="LogicForm" property="text" value="amit">
<h5>Using the tag &lt;logic:match &gt; </h5> 
Result : entered text contains "amit"
</logic:match>



<logic:notMatch name="LogicForm" property="text" value="abc">
<h5>Using the tag&lt;logic:notMatch&gt;</h5> 
Result: entered text does not contains "abc"
</logic:notMatch>

</BODY>
</HTML>

Add the following line in the index.jsp to call the form.

<li>
<html:link page="/pages/InputLogic.jsp">Struts File Upload</html:link>
<br>
Example demonstrates  how LogicAction Class works.
</li>

Building and Testing the Example 

To build and deploy the application go to Struts\Strutstutorial directory and type ant on the command prompt. This will deploy the application. Open the browser and navigate to the InputLogic.jsp page. Your browser displays the following  page.

Writing text including "amit" and excluding "abc" to the InputLogic.jsp page displays the working of  the  match Logic tag <logic:match > and the notMatch Logic tag <logic:notMatch > .

It displays the following to the out.jsp page

Writing text including "amit" and  "abc" to the InputLogic.jsp page displays the working of  the  match Logic tag <logic:match > and the notMatch Logic tag <logic:notMatch > .

The <logic:notEqual > evaluated here displays the output.jsp as

                         

» View all related tutorials
Related Tags: c com ant lua variable sed nested const compare content value tag eval ria this ai if ie constant sse

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

2 comments so far (
post your own) View All Comments Latest 10 Comments:

hi ,
in my screen i am handling next and pre buttons using struts tags.
i am able to hide the prev buttons using greatertahn tag.But wheni came to last page at that time i need to hid the next buuton.its possible to use the any struts tag.i need to need to set the total page value to logic lessthan tags how.any idea??

Posted by divakaran on Sunday, 11.16.08 @ 22:33pm | #81729

EmptyForm extends ActionForm

<action path="/LogicAction"
type="roseindia.net.LogicAction"
name="LogicForm"( in struts-config.xml )

both emptyForm and name are not matching as part of Logic:match and logic:notMatch

please update the information

Posted by kru on Tuesday, 08.21.07 @ 14:49pm | #23838

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
Search Tutorials:

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.