Create a hashmap with jstl, how?

background:
i need to create a hashmap on my jsp, using just jstl, if possible. after this, i need to pass this hashmap to custom tag, where the custom tag will get it like this:
public void setSomeVar(Map m){ ... } 1. is this even possible?
2. can anything other then a string be passed into a tag?
thank you.

mkoryak wrote:
stevejluke wrote:
You shouldn't generate a HashMap in JSTL*. Building a HashMap is business logic and the JSP should handle just display - and JSTL makes displaying data easier.while normally i would agree with you, i need to pass some stuff to my custom tag that looks very much like a map, so i would rather pass a real map, not a string which i would have to parse in the tag anyway. That is a worse situation than passing a HashMap. If I were you, I would either make setters for the expected keys of the HashMap (if they are known) in the JavaBean, or make the JavaBean a limited implementation of the Map interface that wraps around a local (to the JavaBean) Map, so you could directly set values without having to build a HashMap.
I would also prefer to build the contents of the JavaBean in a Control servlet or in my Model layer, building it in the JSP is too much work.
Example of a Map implementation in the bean:
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class MapWrapperBean<V> implements Map<String, V> {
     /* Holds a map of properties of unknown name and type */
     private Map<String, V> localMap = new HashMap<String, V>();
     /* Examples of a few normal bean properties */
     private String name;
     private int number;
     public MapWrapperBean() {}
     /* Normal Bean Property Accessors */
     public String getName() {
          return name;
     public int getNumber() {
          return number;
     public void setName(String name) {
          this.name = name;
     public void setNumber(int number) {
          this.number = number;
     /* Map interface wrapping around the local Map */
     @Override
     public void clear() {
          localMap.clear();
     @Override
     public boolean containsKey(Object key) {
          return localMap.containsKey(key);
     @Override
     public boolean containsValue(Object value) {
          return localMap.containsValue(value);
     @Override
     public Set<java.util.Map.Entry<String, V>> entrySet() {
          return localMap.entrySet();
     @Override
     public V get(Object key) {
          return localMap.get(key);
     @Override
     public boolean isEmpty() {
          return localMap.isEmpty();
     @Override
     public Set<String> keySet() {
          return localMap.keySet();
     @Override
     public V put(String key, V value) {
          return localMap.put(key, value);
     @Override
     public void putAll(Map<? extends String, ? extends V> externalMap) {
          localMap.putAll(externalMap);
     @Override
     public V remove(Object key) {
          return localMap.remove(key);
     @Override
     public int size() {
          return localMap.size();
     @Override
     public Collection<V> values() {
          return localMap.values();
}>
thanks for the help though, and yes, i should use the jsp forum, but know that ill get my answer here faster

Similar Messages

  • Iterating an ArrayList HashMap with JSTL in a JSP? Can it be done?

    I made up the following code to iterate an ArrayList of HashMaps using JSTL Core in a JSP, but it doesn't work. However I've seen examples of similar code that works, so I'm not sure what's wrong with mine. Any help would be greatly appreciated.
    <%
         FileBrowser fb = new FileBrowser();
         ArrayList list = fb.getFiles();
         request.setAttribute("list", list);
    %>
    <c:forEach var="file" items="${request.list}">
    <c:out value="${file.path}"/>
    </c:forEach>Yes I have triple checked that FileBrowser and all methods in it work just fine.

    because the JSP is blank. but i accidentally fixed it. apparently i shoulda done ${list} instead of ${request.list} :p

  • How can I create a hashmap() with multiple values for the same key?

    I am trying to write an application that will us something like a Map() with multiple values but some have the same key. Is this possible?

    i had the same question. just create a List, add all the values u want to it, and then put the List into the map like u would a normal single value. e.g.
    List list = new ArrayList();
    list.add(value1);
    list.add(value2);
    map.put(key, list);
    i bet u r doing the same course as i am =)

  • Creating a form with WebDB - how should I start ?

    Hi,
    Since I am a beginner in this area and nobody can help me at the office (but deadline is very close:) I hope somebody can help me at this forum..
    So my problem is the followng:
    I have a table 'Entity' with columns:
    - ID// Name// Version// PreVersion and so on...
    There is already implemented a form for Defining new entity. That form introduces Version = '1.1-0' (by default) and PreVersion = 'N/A' (by default), and of course Name and others are introduced by end user.
    Now I have to implement a form for creating a new version from a specific Name and from an existing version (of course at the beginning there will exist only versions 1.1-0)
    So I don't have idea at the moment which kind of form should I start with: forms on stored procedures or forms on tables/views or other type ?
    The form should work in the following way:
    when user executes it, he/she must give the Name and Version (from which new version must be created) and then a new row must be inserted with values copied from previous row (or if it's easier with NULL values); BUT Version of the new row must be a value entered by end user and PreVersion of new row must be the value of Version of the modified (previous) row.
    For me it's difficult to imagine how can I solve a kind of parametrization in the form. I mean let say I have two columns in the form definition: Ent_name and Version where user gives the searching criteria i.e. Version and Name value of the row which must be modified, but how can I refference them in a SQL code let say added for example in 'Advanced PL/SQL Code' menu of form definition ?
    I would appreciate any good idea just to give me a kick in what way sould I start ...
    Br.
    Szilard

    Hi,
    You can reference the columns in the additional plsql code using session variables. All the columns are referred with 'A_' prefixed to the name of the column. You can make use of p_session.get_value_as_<datatype> to get values and p_session.set_value to assign values to these columns.
    Here is an example
    declare
    flightno number;
    ticketno varchar2(30);
    tdate date;
    persons number;
    blk varchar2(10) := 'DEFAULT';
    begin
    flightno := p_session.get_value_as_varchar2(
    p_block_name => blk,
    p_attribute_name => 'A_FLIGHT_NO');
    ticketno := p_session.get_value_as_varchar2(
    p_block_name => blk,
    p_attribute_name => 'A_TICKET_NO');
    tdate := p_session.get_value_as_date(
    p_block_name => blk,
    p_attribute_name => 'A_TRAVEL_DATE');
    persons := p_session.get_value_as_number(
    p_block_name => blk,
    p_attribute_name => 'A_NOF_PERSONS');
    p_session.set_value(
    p_block_name => blk,
    p_attribute_name => 'A_FLIGHTNO',
    p_value => to_char(NULL)
    p_session.set_value(
    p_block_name => blk,
    p_attribute_name => 'A_TICKETNO',
    p_value => to_char(NULL)
    p_session.set_value(
    p_block_name => blk,
    p_attribute_name => 'A_TRAVEL_DATE',
    p_value => to_char(NULL)
    Hope this helps.
    Thanks,
    Sharmila

  • Files created in DW with slices, how can I email the html files to someone

    Hello,
    I was wondering if someone could help me please? I created my first website in DW CS4. I used Illustrator to create it, added slices, then did the rest in DW. My site is not live yet - I have not yet uploaded the files to the web host. However, I need to email the .html file to someone so that they can see what I have created so far for the site. But when I attach the .html files, the person I send them to cannot view them - when they open the file it is just a bunch of placeholders where the slices are and you can't see the web page at all. I am a newbie to web design so this is probably quite an ignoramus question. I appreciate any help anyone can give me!!

    The best practice is to upload the site to a TEST folder on your  remote server for debugging purposes.  (yourdomain.com/TEST/index.html)
    Then send your client an email with the URL so they can see the site.  When you're done testing & debugging, remove the TEST folder from remote server.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    www.alt-web.com/
    www.twitter.com/altweb
    www.alt-web.blogspot.com

  • Creating temporary tables with JSTL

    I need to create temporary tables in my DB (MySQL), and later call it in a query.
    I try this:
    <sql:update var="temp1" dataSource="${conn}">
    CREATE TEMPORARY TABLE temp1
    SELECT data1 FROM table1 WHERE condition = 1
    </sql:update>
    <sql:query var="query1" dataSource="${conn}">
    SELECT * FROM temp1
    </sql:query>

    I haven't done enough with MySQL recently to know.
    Break your problem up into two parts.
    First there's the query portion. Create a permanent table and make sure that your query works fine with taht.
    Next is the creation of the temporary table. Once you KNOW the query is working, then you can concentrate on that.
    I'll assume that you've already GRANTed table creation permission to the user that your JSP app uses to log into the database.
    Are there any messages written to the servlet/JSP engine log file that might help you figure out what's wrong? Do you have a JSP error page that's displayed if any exceptions are thrown? - MOD

  • How do you run a boolean on a hashmap using JSTL?

    I am trying to test a hashmap to see if it has a certain value using JSTL.
    <jsp:useBean> id="something_map" class="java.util.HashMap" />
         <c:set target="${something_map}" property="submitted" value="goodbye" />
         ${something_map.submitted}
         <c:if test="{something_map.submitted == goodbye}">
         worked
         </c:if>
    I am creating a hashmap with the jsp:useBean tag. i set the maps name to "something_map."
    Then I made a key called submitted and set its value to goodbye.
    When I display "something_map.submitted", it successfully displays "goodbye", but when I run the <c:if> and test to see if "something_map.submitted" is equal to "goodbye", it doesn't work. How do I run a boolean on the value of a hashmap?
    p.s., i already tried using scope variables, but they don't work so well when they are updated several times over many pages.

    cotton.m wrote:
    >
    Also, to the person who said that I left out a $, that was I typo. I have it in on the original code and it didn't make a difference.Well it's not the equals bit. JSTL is a scripting language not Java.Sorry for the red herring. It's been a geologic age since I've done anything JSP-ish. I wasn't sure how closely JSTL aligns with the Java to which it compiles.

  • How to create a node with attributes at runtime in webdynpro for ABAP?

    Hi Experts,
             How to create a node with attributes at runtime in webdynpro for ABAP? What classes or interfaces I should use? Please provide some sample code.
    I have checked IF_WD_CONTEXT_NODE_INFO and there is ADD_NEW_CHILD_NODE method. But this is not creating any node. I this this creates only a "node info" object.
    I even check IF_WD_CONTEXT_NODE but i could not find any method that creates a node with attribute.
    Please help!
    Thanks
    Gopal

    Hi
       I am getting the following error while creating a dynamic context node with 2 attributes. Please help me resolve this problem.
    Note
    The following error text was processed in the system PET : Line types of an internal table and a work area not compatible.
    The error occurred on the application server FMSAP995_PET_02 and in the work process 0 .
    The termination type was: RABAX_STATE
    The ABAP call stack was:
    Method: IF_WD_CONTEXT_NODE~GET_STATIC_ATTRIBUTES_TABLE of program CL_WDR_CONTEXT_NODE_VAL=======CP
    Method: GET_REF_TO_TABLE of program CL_SALV_WD_DATA_TABLE=========CP
    Method: EXECUTE of program CL_SALV_WD_SERVICE_MANAGER====CP
    Method: APPLY_SERVICES of program CL_SALV_BS_RESULT_DATA_TABLE==CP
    Method: REFRESH of program CL_SALV_BS_RESULT_DATA_TABLE==CP
    Method: IF_SALV_WD_COMP_TABLE_DATA~MAP_FROM_SOURCE_DATA of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMP_TABLE_DATA~MAP_FROM_SOURCE of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMP_TABLE_DATA~UPDATE of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_VIEW~MODIFY of program CL_SALV_WD_C_TABLE_V_TABLE====CP
    Method: IF_SALV_WD_COMPONENT~VIEW_MODIFY of program CL_SALV_WD_A_COMPONENT========CP
    My code is like the following:
    TYPES: BEGIN OF t_type,
                CARRID TYPE sflight-carrid,
                CONNID TYPE sflight-connid,
             END OF t_type.
      Data:  i_struc type table of t_type,
      dyn_node   type ref to if_wd_context_node,
      rootnode_info   type ref to if_wd_context_node_info,
      i_node_att type wdr_context_attr_info_map,
      wa_node_att type line of wdr_context_attr_info_map.
          wa_node_att-name = 'CARRID'.
          wa_node_att-TYPE_NAME = 'SFLIGHT-CARRID'.
          insert wa_node_att into table i_node_att.
          wa_node_att-name = 'CONNID'.
          wa_node_att-TYPE_NAME = 'SFLIGHT-CONNID'.
          insert wa_node_att into table i_node_att.
    clear i_struc. refresh i_struc.
      select carrid connid into corresponding fields of table i_struc from sflight where carrid = 'AA'.
    rootnode_info = wd_context->get_node_info( ).
    rootnode_info->add_new_child_node( name = 'DYNFLIGHT'
                                       attributes = i_node_att
                                       is_multiple = abap_true ).
    dyn_node = wd_context->get_child_node( 'DYNFLIGHT' ).
    dyn_node->bind_table( i_struc ).
    l_ref_interfacecontroller->set_data( dyn_node ).
    I am trying to create a new node. That is
    CONTEXT
    - DYNFLIGHT
    CARRID
    CONNID
    As you see above I am trying to create 'DYNFLIGHT' along with the 2 attributes which are inside this node. The structure of the node that is, no.of attributes may vary based on some condition. Thats why I am trying to create a node dynamically.
    Also I cannot define the structure in the ABAP dictionary because it changes based on condition
    Message was edited by: gopalkrishna baliga

  • I am new to IPAD and I want o use facetime, how can I use it to communicate with my mac at home, do I need to create another account with a different email account

    I am new to IPAD and I want o use facetime, how can I use it to communicate with my mac at home, do I need to create another account with a different email account

    do I need to create another account with a different email account
    Yes, the email addresses need to be unique to each device. You may use the same Apple ID on each device, but the email address used by each device needs to be different.

  • How to create a report with survey data

    Hi All,
    I need to create a report with survey data in below format. Can anyone help me how to display the summary in this format.
    Swapna

    Hi Swapna,
    According to your description, you want to create a report with survey data and display the summary.
    Reporting Services is used for rendering the report with data retrieved from datasource. In Reporting Services, we can retrieve data from the datasource then design a report, after the report processed, data is fixed on the report. So it’s not supported
    to have the end users selection and do summary. For your requirement, it’s can’t be achieved currently.
    If you have any question, please feel free to ask.
    Best regards,
    Qiuyun Yu
    Qiuyun Yu
    TechNet Community Support

  • How to create a report with data using the Crystal Reports for Java SDK

    Hi,
    How do I create a report with data that can be displayed via the Crystal Report for Java SDK and the Viewers API?
    I am writing my own report designer, and would like to use the Crystal Runtime Engine to display my report in DHTML, PDF, and Excel formats.  I can create my own report through the following code snippet:
    ReportClientDocument boReportClientDocument = new ReportClientDocument();
    boReportClientDocument.newDocument();
    However, I cannot find a way to add data elements to the report without specifying an RPT file.  Is this possible?  I seems like it is since the Eclipse Plug In allows you to specify your database parameters when creating an RPT file.
    is there a way to do this through these packages?
    com.crystaldecisions.sdk.occa.report.data
    com.crystaldecisions.sdk.occa.report.definition
    Am I forced to create a RPT file for the different table and column structures I have? 
    Thank you in advance for any insights.
    Ted Jenney

    Hi Rameez,
    After working through the example code some more, and doing some more research, I remain unable to populate a report with my own data and view the report in a browser.  I realize this is a long post, but there are multiple errors I am receiving, and these are the seemingly essential ones that I am hitting.
    Modeling the Sample code from Create_Report_From_Scratch.zip to add a database table, using the following code:
    <%@ page import="com.crystaldecisions.sdk.occa.report.application.*"%>
    <%@ page import="com.crystaldecisions.sdk.occa.report.data.*"%>
    <%@ page import="com.crystaldecisions.sdk.occa.report.document.*"%>
    <%@ page import="com.crystaldecisions.sdk.occa.report.definition.*"%>
    <%@ page import="com.crystaldecisions.sdk.occa.report.lib.*" %>
    <%@ page import = "com.crystaldecisions.report.web.viewer.*"%>
    <%
    try { 
                ReportClientDocument rcd = new ReportClientDocument();
                rcd.newDocument();
    // Setup the DB connection
                String database_dll = "Sqlsrv32.dll";
                String db = "qa_start_2012";
                String dsn = "SQL Server";
                String userName = "sa";
                String pwd = "sa";
                // Create the DB connection
                ConnectionInfo oConnectionInfo = new ConnectionInfo();
                PropertyBag oPropertyBag1 = oConnectionInfo.getAttributes();
                // Set new table logon properties
                PropertyBag oPropertyBag2 = new PropertyBag();
                oPropertyBag2.put("DSN", dsn);
                oPropertyBag2.put("Data Source", db);
                // Set the connection info objects members
                // 1. Pass the Logon Properties to the main PropertyBag
                // 2. Set the Server Description to the new **System DSN**
                oPropertyBag1.put(PropertyBagHelper.CONNINFO_CRQE_LOGONPROPERTIES, oPropertyBag2);
                oPropertyBag1.put(PropertyBagHelper.CONNINFO_CRQE_SERVERDESCRIPTION, dsn);
                oPropertyBag1.put("Database DLL", database_dll);
                oConnectionInfo.setAttributes(oPropertyBag1);
                oConnectionInfo.setUserName(userName);
                oConnectionInfo.setPassword(pwd);
                // The Kind of connectionInfos is CRQE (Crystal Reports Query Engine).
                oConnectionInfo.setKind(ConnectionInfoKind.CRQE);
    // Add a Database table
              String tableName = "Building";
                Table oTable = new Table();
                oTable.setName(tableName);
                oTable.setConnectionInfo(oConnectionInfo);
                rcd.getDatabaseController().addTable(oTable, null);
        catch(ReportSDKException RsdkEx) {
                out.println(RsdkEx);  
        catch (Exception ex) {
              out.println(ex);  
    %>
    Throws the exception
    com.crystaldecisions.sdk.occa.report.lib.ReportSDKException: java.lang.NullPointerException---- Error code:-2147467259 Error code name:failed
    There was other sample code on SDN which suggested the following - adding the table after calling table.setDataFields() as in:
              String tableName = "Building";
                String fieldname = "Building_Name";
                Table oTable = new Table();
                oTable.setName(tableName);
                oTable.setAlias(tableName);
                oTable.setQualifiedName(tableName);
                oTable.setDescription(tableName) ;
                Fields fields = new Fields();
                DBField field = new DBField();
                field.setDescription(fieldname);
                field.setHeadingText(fieldname);
                field.setName(fieldname);
                field.setType(FieldValueType.stringField);
                field.setLength(40);
                fields.add(field);
                oTable.setDataFields(fields);
                oTable.setConnectionInfo(oConnectionInfo);
                rcd.getDatabaseController().addTable(oTable, null);
    This code succeeds, but it is not clear how to add that database field to a section.  If I attempt to call the following:
    FieldObject oFieldObject = new FieldObject();
                oFieldObject.setDataSourceName(field.getFormulaForm());
                oFieldObject.setFieldValueType(field.getType());
                // Now add it to the section
                oFieldObject.setLeft(3120);
                oFieldObject.setTop(120);
                oFieldObject.setWidth(1911);
                oFieldObject.setHeight(226);
                rcd.getReportDefController().getReportObjectController().add(oFieldObject, rcd.getReportDefController().getReportDefinition().getDetailArea().getSections().getSection(0), -1);
    Then I get an error (which is not unexpected)
    com.crystaldecisions.sdk.occa.report.lib.ReportDefControllerException: The field was not found.---- Error code:-2147213283 Error code name:invalidFieldObject
    How do I add one of the table.SetDataFields()  to my report to be displayed?
    Are there any other pointers or suggestions you may have?
    Thank you

  • After downloading Mozilla Firefox 4.0 Beta to my desktop I restarted the computer, but I do not receive any prompts to create an account with a Secret Password. How do I set up the account if the prompt never show up?

    Several months ago I installed the Firefox Home app on my iPhone to sync the bookmarks that I had on my Windows XP home computer. It has worked just fine until a few days ago. Just recently I was notified that the app would no longer work because of changes that have been made. I have tried to follow the instructions that were emailed to me regarding how to setup the new Firefox Sync add-on, but I am having a problem. After downloading Mozilla Firefox 4.0 Beta to my desktop and restarting my computer, I do not receive any prompts to create an account with a password and a secret phrase, as the instructions specify. How do I set up the account if the prompt never shows up?

    Click on the Firefox button then select Options to open the Options dialog. Now go to the Sync panel for the option to setup a new account.

  • How to create excise invoice with reference thorugh credit memo

    Hi All,
    Please provide any solution for the following qurey:
    How to create excise invoice with reference thorugh credit memo

    Hi murali,
    i am unable to understand your requirement i think there is no like this scenario requirement for any client
    if any requirement is there kindly explain detail
    cheers

  • How to create device IDs with same name

    i am using SE 3310 and its creating different device ids for each node sharing it . since I will be building a RAC enviornment I need these IDs/name to be same .
    for example  on one node the lun id is /dev/rdsk/c3t0d0s6  but the same lun id on node 2 is /dev/rdsk/c2t0d0s6.
    In past with an old storage array I fixed this issue by creating links  in /dev/rdsk for  c3t0d0s6 --->  c2t0d0s6.
    my question is : is there a way in SE3310 that device ids get created with same name or do i still have to rely on creating these soft links ?
    thanks
    Note: since i need the answer to this quickly i will wait a while and then post this question in other forums and i will update the question here with the answer .

    This could be a Solaris (I presumed) O.S. question rather than SE3310 or storage question.  
    The logical device (/dev/[r]dsk/*) is the work of the O.S. when it first configures the device,  in this case the LUN from your SE3310.   I can go in depth on how the cX number happens (due to device probe order, driver differences, history of device discovery due to need of persistent device naming, etc...) but ... it's a really long story and is really quite irrelevant and most people should not be interested...
    If you have COMPLETELY identical servers, i.e. identical hardware down to specific HBA in specific slot are the same,   and if you make sure that luns are presented to all servers exactly the same way, same order, and any changes are seen by all servers in the same sequence,  in theory,  all /dev/rdsk/* devices will be consistent across servers.
    But that's still rather irrelevant.    Application that is designed to work in a redundant environment should not be dependent on logical devices like /dev/rdsk being the same.
    So ... in effect this is also not a question for the Solaris forum,  but rather a question for those familiar with RAC,  how to configure such that device access is done "safely" through actually identifying the lun rather than assuming /dev/rdsk are consistent.

  • How to create a chart with dates?

    I've created a table with projects I have to deliver and the date they were delivered. I would like to create a chart from this data - however I can't figure out how to use date in the chart.
    Ideally the chart would work with the date (lets say from jan 01 to april 5) on the x-axis and the project on the y-axis. And a line that goes from time A (which marks the initial part of the project) to the time B (which marks the delivery date) defined on the table.
    Is it possible?
    heres a pic of what i mean:
    /Users/judavies/Desktop/Screen shot 2011-01-14 at 11.36.12 AM.png
    Message was edited by: jujudavies

    Hi Jerry,
    I'm ALMOST there! If you could help me with one last thing it would be amazing. I've uploaded my number project and you can downloaded it on the link bellow, if you prefer.
    I managed to do the same idea chart as you have. However I would like to have two bars for every JOB (y-axis). On my table i've inputed for every job 4 values = START DATE that was scheduled / Duration period scheduled (this happens prior to the job itself // START DATE Delivered / Duration Period Delivered (this is the actual time the JOB took place). This way I can see at the end of a JOB if I worked during the period I planned.
    using your example on the chart above (your reply) Could Proposal have a bar 1.0 / 4.0 - and bellow this bar have another one (with different colours) that went from 2.0 / 5.0 - for example? - the first one representing the "scheduled dates"and the second one representing what actually happened.
    I managed to do the four bars but couldnt manage to have them bellow each other.
    Tks again for your help
    files.me.com/jujudavies/wgugl1.numbers.zip
    x'jul.

Maybe you are looking for