{"id":365,"date":"2013-09-27T07:43:39","date_gmt":"2013-09-27T07:43:39","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=365"},"modified":"2013-09-27T07:43:39","modified_gmt":"2013-09-27T07:43:39","slug":"how-to-set-form-bean-values-in-struts-config-xml-struts2","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/how-to-set-form-bean-values-in-struts-config-xml-struts2\/","title":{"rendered":"How to set form bean values in struts-config.xml Struts2"},"content":{"rendered":"<p>For setting the Bean value in struts-config.xml we should use the form-beans tag.The form-beans tag might contain any number of bean property defined within form-bean as below.<\/p>\n<p><strong>Defining a Simple Bean Property<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;form-beans&gt;\r\n &lt;form-bean name=&quot;userBean&quot; type=&quot;org.apache.struts.action.DynaActionForm&quot;&gt;\r\n   &lt;form-property name=&quot;userName&quot; initial=&quot;This is Bean Value&quot; type=&quot;java.lang.String&quot; \/&gt;\t\r\n &lt;\/form-bean&gt;\r\n&lt;\/form-beans&gt;\r\n<\/pre>\n<p>In the above code I am creating a userBean and setting its value is initialized to <strong>This is Bean Value<\/strong>.<\/p>\n<p>Now in the action mapping part of the struts-config.xml I am going to map the above created bean to path as said below<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;action-mappings&gt;\r\n &lt;action path=&quot;\/showBeanValue&quot; type=&quot;org.apache.struts.actions.ForwardAction&quot; parameter=&quot;\/showBeanValue.jsp&quot;\/&gt;\t\t\t\t\r\n &lt;action name=&quot;userBean&quot; path=&quot;\/Login&quot; \/&gt;\t\t\r\n&lt;\/action-mappings&gt;\r\n<\/pre>\n<p>In the first line I am defining action path as <strong>showBeanValue<\/strong> and it is going to forward to page <strong>showBeanValue.jsp<\/strong> when some one access the  <strong>showBeanValue.do<\/strong> in url.<\/p>\n<p>In the second statement I am creating a dummy form since the the html form action should not be empty.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\"> \r\n  &lt;%@ taglib uri=&quot;http:\/\/struts.apache.org\/tags-html&quot; prefix=&quot;html&quot;%&gt;\r\n  &lt;%@ taglib uri=&quot;http:\/\/struts.apache.org\/tags-bean&quot; prefix=&quot;bean&quot;%&gt;     \r\n  &lt;html:form action=&quot;\/Login&quot;&gt;\r\n    &lt;bean:write name=&quot;userBean&quot; property=&quot;userName&quot;&gt;&lt;\/bean:write&gt;\r\n    &lt;bean:write name=&quot;userBean&quot; property=&quot;userAge&quot;&gt;&lt;\/bean:write&gt;\r\n  &lt;\/html:form&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>For setting the Bean value in struts-config.xml we should use the form-beans tag.The form-beans tag might contain any number of bean property defined within form-bean as below. Defining a Simple Bean Property &lt;form-beans&gt; &lt;form-bean name=&quot;userBean&quot; type=&quot;org.apache.struts.action.DynaActionForm&quot;&gt; &lt;form-property name=&quot;userName&quot; initial=&quot;This is Bean Value&quot; type=&quot;java.lang.String&quot; \/&gt; &lt;\/form-bean&gt; &lt;\/form-beans&gt; In the above code I am creating a userBean&hellip; <a href=\"https:\/\/codethataint.com\/blog\/how-to-set-form-bean-values-in-struts-config-xml-struts2\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-365","post","type-post","status-publish","format-standard","hentry","category-struts2"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/365","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=365"}],"version-history":[{"count":1,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/365\/revisions"}],"predecessor-version":[{"id":366,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/365\/revisions\/366"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}