want to insert values in drop down menu in struts1.3

Ads
 

want to insert values in drop down menu in struts1.3

I am using DynaValidatorForm.please help me with inserting values in color drop down menu. I have tried belowwith arraylist but was not able to find solution.

add.jspx

<?xml version="1.0" encoding="UTF-8"?>
<!--
    Document   : add
    Created on : Mar 4, 2012, 7:00:38 PM
    Author     : Administrator
-->
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
          xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
          xmlns:c="http://java.sun.com/jsp/jstl/core"
          xmlns:html="http://struts.apache.org/tags-html"
          xmlns:fn="http://java.sun.com/jsp/jstl/functions"
          xmlns:bean="http://struts.apache.org/tags-bean" version="2.0">
    <jsp:directive.page  contentType="text/html" pageEncoding="UTF-8"/>
    <html:xhtml/>
    <html:html >
        <head>
            <title>
               <bean:message key="add.title"/>
             </title>
         </head>
        <body>
            <h1>  
                <bean:message key="global.heading"/>
                <jsp:text></jsp:text>
             <bean:message key="add.heading"/>
             </h1>
             <html:errors/>
             <html:form  action="/addSubmit">
                 <table class="addedit" >
                     <tr>
                         <td>
                             <bean:message key="pointForm.prompt.x"/>
                          </td>
                          <td><html:text name="pointForm" property="x"/></td>
                      </tr>
                      <tr>
                          <td>
                             <bean:message key="pointForm.prompt.y"/>
                          </td>
                          <td><html:text name="pointForm" property="y"/></td>
                      </tr>
                      <tr>
                          <td>
                              <bean:message key="pointForm.prompt.color"/>
                           </td>
                            <td>
                            <html:select property="color">
                                <html:options   property="colors"  />
                            </html:select>
                            </td>
                         </tr>
                         <tr>
                           <td>
                               <html:submit>
                                   <bean:message  key="pointForm.add.submit"/>
                               </html:submit>
                           </td>
                         </tr>

                    </table>
            </html:form>

        </body>
    </html:html>
</jsp:root>

struts-config.xml

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">


<struts-config>
    <form-beans>
     <form-bean  name="pointForm"
    type="org.apache.struts.validator.DynaValidatorForm">
    <form-property  type="int"
    name="id"  initial="-1"/>
    <form-property  type="double"
    name="x"  initial="0"/>
    <form-property  type="double"
    name="y"  initial="0"/>
    <form-property  type="java.lang.String"
    name="color"  />
    <form-property  type="java.util.ArrayList"
    name="colors"  />
    </form-bean>
    </form-beans>

    <global-exceptions>

    </global-exceptions>

    <global-forwards >

    </global-forwards>

    <action-mappings>
       <action name="pointForm" path="/add" scope="request" type="com.myapp.sruts.NewAction" validate="false">
       <forward name="success" path="/WEB-INF/add.jspx"/>
       </action>
       <action path="/addSubmit" name="pointForm" scope="request" inpu="/add.do" type="com.myapp.struts.AddAction"/>
    </action-mappings>

    <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

    <message-resources parameter="com/myapp/struts/messages"/>

    <!-- ========================= Tiles plugin ===============================-->
    <!--
    This plugin initialize Tiles definition factory. This later can takes some
    parameters explained here after. The plugin first read parameters from
    web.xml, thenoverload them with parameters defined here. All parameters
    are optional.
    The plugin should be declared in each struts-config file.
    - definitions-config: (optional)
    Specify configuration file names. There can be several comma
    separated file names (default: ?? )
    - moduleAware: (optional - struts1.1)
    Specify if the Tiles definition factory is module aware. If true
    (default), there will be one factory for each Struts module.
    If false, there will be one common factory for all module. In this
    later case, it is still needed to declare one plugin per module.
    The factory will be initialized with parameters found in the first
    initialized plugin (generally the one associated with the default
    module).
    true : One factory per module. (default)
    false : one single shared factory for all modules
    - definitions-parser-validate: (optional)
    Specify if xml parser should validate the Tiles configuration file.
    true : validate. DTD should be specified in file header (default)
    false : no validation

    Paths found in Tiles definitions are relative to the main context.
    -->
    <plug-in className="org.apache.struts.tiles.TilesPlugin" >
        <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />      
        <set-property property="moduleAware" value="true" />
    </plug-in>

    <!-- ========================= Validator plugin ================================= -->
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
        <set-property
            property="pathnames"
            value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
    </plug-in>

</struts-config>

NewAction.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.myapp.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.DynaValidatorForm;
import java.util.HashMap;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import java.util.ArrayList;
/**
 *
 * @author Administrator
 */
public class NewAction extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        DynaValidatorForm pointForm = (DynaValidatorForm) form;
        ArrayList colorList = new ArrayList();

        return mapping.findForward(SUCCESS);
    }
}

messages.properties

global.heading=Points:
global.title=Points:
add.heading=Add
add.title=Add
add.submit=Add Point
pointForm.prompt.x=X:
pointForm.prompt.y=Y:
pointForm.prompt.color=Color:
pointForm.add.submit=add

AddAction.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.myapp.struts;

import org.apache.commons.beanutils.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.DynaValidatorForm;

/**
 *
 * @author Administrator
 */
public class AddAction extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";


    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        DynaValidatorForm pointForm= (DynaValidatorForm) form;
       String x1=pointForm.get("x").toString();
        double x=Double.parseDouble(BeanUtils.getProperty(pointForm,"x"));
        double y=Double.parseDouble(BeanUtils.getProperty(pointForm,"y"));
        String color=(BeanUtils.getProperty(pointForm,"color"));
        System.out.println("x is "+ x1);
        return mapping.findForward(SUCCESS);
    }
}
View Answers

Ads









Related Tutorials/Questions & Answers:
want to insert values in drop down menu in struts1.3
want to insert values in drop down menu in struts1.3  I am using DynaValidatorForm.please help me with inserting values in color drop down menu. I have tried belowwith arraylist but was not able to find solution. add.jspx
drop down menu
drop down menu  drop down menu using html
Advertisements
Add values of drop down menu( select option) to mysql table
Add values of drop down menu( select option) to mysql table   Here is my code <?php echo $row['valveName'].'<td>'.$row['valveId'].'<td>'; echo '<select name="onoff">'; echo '<
Drop down menu
Drop down menu  I have created a drop down list of links which links to a table but if i click the link the table display in the other page i want to display it in the same page.Please tell me the solution
Get values in drop down list
Get values in drop down list  Pls provide me jsp code to get values in drop down list from another table's field. my project has customer... in drop down box in front end..... pls provide me code.. thanx
Drop down menu
Drop down menu  I have drop down list of some 14 links which links to the table,If i click each link the table should display below the link and again if i click the link the table should not appear. please help me
JSP Dependent Drop Down Menu
JSP Dependent Drop Down Menu  Hey Guy/Gals! I need someone help to guide me in creating a drop down menu, where the first menu affects the second menu and it's selection. So in my database I have a category table that has a ID
html menu button drop down
html menu button drop down  How to create a menu button in HTML?   <select id="category"> <option value="1">One</option> <option value="2">Two</option> </select> <select id
store values of drop down list box in database
store values of drop down list box in database  how to store values of drop down list box in oracle database in jsp?I have information inserting form where i have date of birth as drop down list box
how to import values from database to the drop down box
how to import values from database to the drop down box   hi iam... employee page i kept a drop down box for employee Ids i want all employee IDs will display in the drop down box please help me with the code
How to insert multiple drop down list data in single column in sql database using servlet
How to insert multiple drop down list data in single column in sql database using servlet  i want to insert date of birth of user by using separate drop down list box for year,month and day into dateofbirth column in sql server
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc...) {*/ //String sql="insert into form1a values
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc...) {*/ //String sql="insert into form1a values
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc...) {*/ //String sql="insert into form1a values
insert data using drop down box in java into database postgresql
insert data using drop down box in java into database postgresql  can... data into database using an drop down box .....as i m using eclipse as jdbc...) {*/ //String sql="insert into form1a values
Pls provide me jsp code to get values in drop down list from another table's field....
Pls provide me jsp code to get values in drop down list from another table's... in customer registration page and should be shown in drop down box in front end... pages..... when i insert data in company registration .. it ll have company id
Drop Down
Drop Down  How to insert date into database using dropdown like facebook
how to store multiple values from drop down in database where i am using java struts 1.3
how to store multiple values from drop down in database where i am using java struts 1.3  hii, i am coding a form where i need a keyskills attribute... is displaying.. i need code in java so that it takes multiple values
I want to display the quantity of the selected item of a drop down list in a textbox. The data is stored in database.
I want to display the quantity of the selected item of a drop down list in a textbox. The data is stored in database.  The code for retrieving data from database into Drop Down List. <% DataSource data = new
Drop Down Box
Drop Down Box  In a Drop Down box I want to show the user All the Country In the World. And when he type A-z,then each of the type Show those country which start with those word. Like I For-India
Dynamic Dropdown Menu
records from your database in a drop down menu/list box. You can apply... a table in your desired database,  you can create and insert values using... values like this: insert into car_list values(0, 'aston martin'); and so on. Note
drop down
drop down  how can i add data from choice/dropdown component of java awt to myaql table
drop down php mysql - PHP
drop down php mysql  PHP Script required to show the similar drop down item in each menu without refreshing the page. Is it possible if yes how
dynamic drop down list
dynamic drop down list  I want to create 2 drop down list, where it takes value from database and the two list are dependent..means if I select... on the value chosen from the previous. want code in javascript and jsp, Can you help
Drop Down reload in IE
Drop Down reload in IE  Hi i was using two drop down box..One for Displaying date followed by another for Dispalying Month..If i Select/Change Month from the 2nd drop down then the 1st drop down ( which is date) automatically
Ajax drop down and textbox
Ajax drop down and textbox  hie frnds I have a dropdown menu in the 3... menu consisting of options 1,2,3. When the user select any option from...;And one more thing how to insert to the database dynamically
Login With Drop Down
Login With Drop Down   Hi all, I am doing a project using JSP. My... a drop down list consisting of Customs and Accounts. I have user accounts of both the departments. Now, my intention is to select the department from the drop down
Drop down for search textbox like google search
Drop down for search textbox like google search  I want drop down like google search (ie, when we type one letter then the word start with that are displayed). when the drop down list appear, then we can select one of word as our
i want to update values
i want to update values  in my form i have 2 submit buttons one for edit and another for update on page load all my details need to fetch from database and it need to insert automatically in to disabled text boxs and once i press
Excel Cell Drop Down List
Excel Cell Drop Down List In this section, you will learn how to validate data entered in a cell and provide a drop down list of possible values to the user... into cell A1 is restricted to the following : 10,20,30. The drop down is also
pyspark dataframe drop null - how to drop row with null values
pyspark dataframe drop null - how to drop row with null values  Hi, I have a data frame with following values: Name,address,age I want to drop all the rows having address is NULL. how to do this? thanks   Hi, you

Ads