Contact Us
  
 
 
    SearchSearch   RegisterRegister   Log inLog in 

Radio button pre selected in struts

Radio button pre selected in struts

 
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans
View previous topic :: View next topic  
Author Message
admin
Site Admin


Joined: 24 Aug 2006
Posts: 30

PostPosted: Mon Jun 02, 2008 10:59 am    Post subject: Radio button pre selected in struts Reply with quote




Hi,

Many people have problem in struts to automatically or pre selected radio button through <html:radio > tag.
In Struts radio button and other checkbox are static by nature.
We can do with action form and dynaform with setting value, once we set value it takes as selected that radio button

I have 2 buttons in struts
Code:

Yes <html:radio property="cRefund" value="R" />
 No <html:radio property="cRefund" value="N" />


in
struts-config.xml


Code:
<form-property name="cRefund" type="java.lang.String" initial="N"/>


In this case, No radio button will be selected automatically
Back to top
View user's profile Send private message Send e-mail
struts10



Joined: 21 Jun 2007
Posts: 3

PostPosted: Fri Nov 28, 2008 1:07 pm    Post subject: Reply with quote

Hi
Automatically selected radio button and check box in struts, you have to initial in form bean of struts-config.xml

Quote:
<struts-config>
<data-sources />


<form-beans >
<form-bean name="myForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="cRefund" type="java.lang.String" initial="N"/>
</form-bean>
</form-beans>


<action-mappings>

<action
name="myForm"
input="input"
path="/url"
scope="request"
type="com.actions.ActionInfo"
validate="true">
<forward name="input" path="test.jsp" />
<forward name="success" path="test.jsp"/>
</action>

</action-mappings>


</struts-config>


can do in JSP file

Quote:
<html>
<body>
<html:form action="/url">
Yes <html:radio property="cRefund" value="R" />
No <html:radio property="cRefund" value="N" />
</html:form>
</body>
</html>


Now value with N radio box will be pre selected in struts form.
Back to top
View user's profile Send private message
juniormember



Joined: 28 Jun 2008
Posts: 154

PostPosted: Wed Jul 01, 2009 4:47 pm    Post subject: Reply with quote

nice one ...short solution

Thanx
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans All times are GMT
Page 1 of 1

 
Jump to:  
  Quick Post a Reply Topic
     
  Name (required)  
     
  Email Address (will not be published) (required)  
     
  Subject of topic (required)  
     
   
     
   
     
  Advertisement  
     
 
     


  More Links  
 
JSP Introduction
JSP Setup
Simple JSP Example
JSP Variable
Array Declaration in JSP
JSP Forms and User Input
Form Validation
JSP Cookies
JSP Session Object
Loop, content collection, iterator, conditional check in JSP
JSP Application Object
JSP Include
JSP Response Object
JSP Request Object
JSP Error Handling
JSP File Handling Object
JSP Action Tag
JSP Implicit Objects
JSP Declaration
JSP Directive
JDBC Introduction
JDBC Driver
JDBC Connection
JDBC Prepared/Statement
JDBC ResultSet
JDBC Close Connection object
JDBC Insert
JDBC Display Records
JDBC Update
JDBC Delete
JDBC Sorting
JDBC Query
JDBC Exception
JDBC Add Batch
JDBC Transaction/RollBack