< html:hidden /> html tag

< html:hidden /> html tag

Previous Home Next

 

It is render of hidden types. The struts hidden tag is populated from the specified value or the specified property of the bean which is associated with our current form. This tag nested inside a form tag body.

 
The struts hidden tag have following attributes:- 

  • styleId :- This is Identifier to be assigned to this HTML element and renders an 'id' attribute.
  • tabindex :- This is tab ascending positive integers order for this element.
  • title :- This attributes is  the advisory title for this element.
  • titleKey :-This attributes is  the advisory title for this element basically this is message resources key.
  • value :-In this attributes value to which should be initialized.
  • style :- In this element you can applied CSS style.
  • styleClass :- In this element you can applied CSS stylesheet class.
  • write :-It should the value of this field also be rendered to the response page to make it visible.

The Following are many other attributes which we can use :

  • accesskey alt
  • altKey
  • bundle
  • dir
  • disabled
  • errorKey
  • errorStyle
  • errorStyleClass
  • errorStyleId
  • indexed
  • lang
  • name
  • onblur
  • onchange
  • onclick
  • ondblclick
  • onfocus
  • onkeydown
  • onkeypress
  • onkeyup
  • onmousedown
  • onmousemove
  • onmouseout
  • onmouseover
  • onmouseup
  • property 
  • title
  • titleKey


Directory Structure of HiddenTagExample in Struts 1.3 Using MyEclipse IDE




index.jsp

<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<html>
<head>
<title>Struts html:hidden tag example</title>
</head>
<body>
<h2>Struts html:hidden tag example</h2>
<html:form action="/hiddenAction">
<bean:message key="label.name"/>:
<html:hidden property="name" name="hiddenForm" value="Mukund Singh"/><br/>
<bean:message key="label.password"/>:
<html:hidden property="password" name="hiddenForm" value="singh"/><br/>
<br/>
<html:submit><bean:message key="label.submit" /></html:submit>
</html:form>
</body>
</html>

web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
 
<web-app>
  <display-name>Maven Struts Examples</display-name> 
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>
        org.apache.struts.action.ActionServlet
    </servlet-class>
    <init-param>
        <param-name>config</param-name>
        <param-value>
         /WEB-INF/struts-config.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet> 
  <servlet-mapping>
       <servlet-name>action</servlet-name>
       <url-pattern>*.do</url-pattern>
  </servlet-mapping> 
</web-app>

struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" 
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
  <form-beans>
    <form-bean name="hiddenForm" type="org.r4r.struts.HiddenForm"/>
  </form-beans>
  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action path="/hidden" type="org.apache.struts.actions.ForwardAction" parameter="/index.jsp"/>
		<action path="/hiddenAction" type="org.r4r.struts.HiddenAction" name="hiddenForm" input="/index.jsp">	
         <forward name="success" path="/success.jsp"/>
		</action>
  </action-mappings>
  <message-resources parameter="org.r4r.struts.ApplicationResources" />
</struts-config>

HiddenForm.java

package org.r4r.struts;

import org.apache.struts.action.ActionForm;

@SuppressWarnings("serial")
public class HiddenForm extends ActionForm {
	private String name;
	private String password;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
}

HiddenAction.java

package org.r4r.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class HiddenAction extends Action {
	public ActionForward execute(ActionMapping mapping,ActionForm form,
		HttpServletRequest request,HttpServletResponse response) throws Exception{
		@SuppressWarnings("unused")
		HiddenForm paramForm=(HiddenForm)form;
		return mapping.findForward("success");
	}
}

ApplicationResources.properties

#label message
label.name = Hidden User Name 
label.password = Hidden Password
label.submit = Submit

success.jsp

<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
 
<html>
<head>
<title>Struts html:hidden tag example</title>
</head>
<body>
<h3>Struts html:hidden tag Example</h3>
<h3 style="color: red;">This OutPut is generated by Hidden Tag in Struts 1.3</h3>
<h4><bean:message key="label.name"/>:<bean:write name="hiddenForm" property="name" /></h4>
<h4><bean:message key="label.password"/>:<bean:write name="hiddenForm" property="password" /></h4>
</body>
</html>

Output




Previous Home Next