How to use ArrayList?
i'm not quite sure how to use ArrayList, i read the api documentation but it would be better if someone could explain it to me
i have a helper method that returns a random number within a given range that picks an index at random but it won't work, here is my code:
public String getIndex ()
a1.get(getRandomIndex(int));
private static int getRandomIndex (int range)
return ((int) (Math.random () * range));
}
You are calling he method incorrectly. You do not use the variable type declaration when calling a method. Do this
import java.util.*;
public class TestClass{
ArrayList<String> words = new ArrayList<String>();
Random rand = new Random();
public TestClass(){
words.add("hello");
words.add("world");
public String randomSelection(){
int index = rand.nextInt(words.size());
return words.get(index); //notice that I am calling the method with a variable that is an integer, but I don't use "int" when I call it
public static void main(String args[]) {
TestClass myTest = new TestClass();
for(int i=0;i<30;i++){
System.out.println(myTest.randomSelection());
}The API documentation will list the variable type but that is only for you information. It is there so that you know what type of variable top use when calling a particular method.
Similar Messages
-
How to use ArrayList to represent muti-dimension array?
For example, how to use ArralyList to represent array likes this:
a[0][0] = xxx
a[1][1] = xxx
a[2][2] = xxx
.....ThanksFor example, how to use ArralyList to represent array likes this:
> a[0][0] = xxx
a[1][1] = xxx
a[2][2] = xxx
.....Use an ArrayList populated with ArrayLists?
kind regards,
Jos -
How to use JSTL varriable in to XML
1. how to use JSTL varriable into Xml Tag.
for example :
java value I am passing to XML.
<eztag:companytag pgm_sname="<%= strpgm_name%>" dbase="<%= strd%>"
dbpass="<%= strp%>" dburl="<%= stru%>" session="<%= session%>" />
After modified in JSTL
<eztag:companytag pgm_sname="${pgm_name}" dbase="${strd}"
dbpass="${strp}" dburl="${stru}" session="${session}" />
but its Not working. How to use this
2.How to use ArrayLIst in JSTL
For example
IN Java scriplet code in JSP
<%for(int i=0;i<alist.size();i++) {
String str = String.valueOf(alist.get(i));
String str1 = String.valueOf(alist.get(i+1));
%>
<TD>STR - <%=str%> </TD>
<TD>STR1 - <%=str1%> </TD>
<% } %>
This code How to Use in JSTL.
thanks in advancethanks for reply
But in this article it describes how to passing the value of function.
I need how to assign the JSTL varriable to xml tag attribute.
for example
In my TLD File
<tag>
<name>companytag</name>
<tag-class>bas.CompanyTag</tag-class>
<attribute>
<name>dbase</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>dbpass</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>dburl</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>pgm_sname</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>session</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
</tag>
Html code
old code :
<%@ taglib uri="/ezerptags.tld" prefix="eztag" %>
<eztag:companytag pgm_sname="<%= strpgm_name%>" dbase="<%= strd%>"
dbpass="<%= strp%>" dburl="<%= stru%>" session="<%= session%>" />
After modified in JSTL
<%@ taglib uri="/ezerptags.tld" prefix="eztag" %>
<eztag:companytag pgm_sname="${pgm_name}" dbase="${strd}"
dbpass="${strp}" dburl="${stru}" session="${session}" />
but its Not working. How to use this
the "eztag" and "companytag" are the customtag. these tages available in eztaglib.tld file. I am passing the value through XML Tag.
Please suggest me . how to use.
is there any article describes how to pass jstl varriable to XML Tag attribute.
thanks in advance -
How to use the html:link with a arraylist
Hi everyone:
I want to display the data using struts html:link.
I query the database and place all the data to javabean,later place all the javabean to ArrayList.In Action,I use the "request.setAttribute("lovetable",articlelist) to set request to jsp page.
I want to pass a parameter "id" use the hyperlink so I can get the parameter when I click the hyperlink.
But how to use html:link to display it?
I use <html:link action="viewtopic.do" paramId="id" paramName="lovetable" paramProperty="id"/>,it can't work and Tomcat report error :
org.apache.jasper.JasperException: No getter method for property id of bean lovetable
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
The lovetable is a ArrayList and it don't have a getter or setter method.
How to use it pass parameter? :( ThksThank you.
I use the bean:define successful.And display all the data to jsp.My jsp code is:
<logic:iterate id="love" name="lovetable">
<bean:define id="idbean" name="love"/>
<tr bgcolor="<%=color%>">
<td><bean:write name="love" property="id"/></td>
<td><html:link forward="viewtopic" paramId="id" paramName="idbean" paramProperty="id"><bean:write name="love" property="title"/></html:link></td>
<td><bean:write name="love" property="name"/></td>
<td><bean:write name="love" property="time"/></td>
</tr>
</logic:iterate>
In Action : request.setAttribute("lovetable",articlelist)
ResutlSet rs=.............
List articlelist=new ArrayList();
while(rs.next()){
articlebean bean=new articlebean();
bean.setName(rs.getString("name"));
bean.setTitle(rs.getString("title"));
articlelist.add(bean);
The above code will work property.
The Tag "html:link" need bean to work other than arraylist so I iterate all the bean out.
The Tag "logic:iterate" need collection to work so I make Action return a List.
right?
Any idea? :) -
How to use Vector or other ArrayList etc to store my JTree??
How to use Vector or other ArrayList etc to store my JTree??
Dear friends,
I have following I posted before, but not get satisfactory answer, so I modify and repost again here.
I have following code can add classes and students in the JTree,
in class Computer Science, it has student Bill Brien,
in Math, no,
Then I I add Student Nancy, Laura, Peter into Computer Science Class,
add AAAA, BBB, CCC into Math class,
I create a new class called Chemistry, then I add DDD int Chemistry;
so this JTree is dynamically changed,
[1]. How can I dynamically save my current JTree with all above tree structure and its nodes in a Vector or ArrayList(not sure which one is best)??
see code below:
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
public class ModelJTreeTest extends JFrame {
private JTree tree;
private DefaultTreeModel model;
private DefaultMutableTreeNode rootNode;
public ModelJTreeTest() {
DefaultMutableTreeNode philosophersNode = getPhilosopherTree();
model = new DefaultTreeModel(philosophersNode);
tree = new JTree(model);
JButton addButton = new JButton("Add Class/Students");
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
addPhilosopher();
JButton removeButton = new JButton("Remove Selected Class/Students");
removeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
removeSelectedPhilosopher();
JPanel inputPanel = new JPanel();
inputPanel.add(addButton);
inputPanel.add(removeButton);
Container container = getContentPane();
container.add(new JScrollPane(tree), BorderLayout.CENTER);
container.add(inputPanel, BorderLayout.NORTH);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400, 300);
setVisible(true);
private void addPhilosopher() {
DefaultMutableTreeNode parent = getSelectedNode();
if (parent == null) {
JOptionPane.showMessageDialog(ModelJTreeTest.this, "Select Class", "Error",
JOptionPane.ERROR_MESSAGE);
return;
String name = JOptionPane.showInputDialog(ModelJTreeTest.this, "Add Class/Students:");
model.insertNodeInto(new DefaultMutableTreeNode(name), parent, parent.getChildCount());
private void removeSelectedPhilosopher() {
DefaultMutableTreeNode selectedNode = getSelectedNode();
if (selectedNode != null)
model.removeNodeFromParent(selectedNode);
private DefaultMutableTreeNode getSelectedNode() {
return (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
private DefaultMutableTreeNode getPhilosopherTree() {
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Students");
DefaultMutableTreeNode ancient = new DefaultMutableTreeNode("Computer Science");
rootNode.add(ancient);
ancient.add(new DefaultMutableTreeNode("Bill Brian"));
DefaultMutableTreeNode math = new DefaultMutableTreeNode("Maths");
rootNode.add(math);
DefaultMutableTreeNode physics = new DefaultMutableTreeNode("Physics");
rootNode.add(physics);
return rootNode;
public static void main(String args[]) {
new ModelJTreeTest();
}the actual Tree dynamically created somehow looks like following:
| 1.Peter
|---CS--- 2. Nancy
| 3. Laura
| 4.Brian
|
Root(University): -------|---Math- 1.AAA
| 2.BBB
| 3.CCC
|
|
|---Chemistry- 1. DDDThanks a lot
Good weekendsyou can't directly store a tree in a list.Ummm... Just to be contrary... Yes you CAN store a tree in a table.... In fact that's how the windows file system works.
Having said that... you would be well advised to investigate tree data-structures before resorting to flattening a tree into a list.
So... Do you have a specific requirement to produce a List? Your umming-and-erring about Vector vs ArrayList makes it sound like you're still at the stage of choosing a datastructure.
Cheers. Keith. -
How to create ADF selectManyChoice dynamically using arrayList?
Hi,
I am using JDEVADF_11.1.1.3.PS2_GENERIC_100408.2356.5660. I want to dynamically create selectManyChoice through my backing using and populating the same using ArrayList. Can anyone provide me sample code for the same?
Thanks,
VikasDuplicate
-
FETCHING DATA FROM A TABLE USING ARRAYLIST
how can we fetch data from database using arraylist????
Hi ,
This is the way to fetch data into 2d array , you can customize to fetch in array list .
we will assume that we have stm as Statement and rs as ResultSet
rs = stm.executeQuery("select * from emp");
int noOfColumns = rs.getMetaData.getColumnCount();
rs.last();
int noOfRows = rs.getRow;
rs.befpreFirst();
String [][] result = new String[noOfRows][noOfColumns];
for(int i = 0 ; i<noOfColumns;i++){
rs.next();
for(int y = 0;y<noOfColumns;y++){
result[i][y]=rs.getString(y+1);
rs.close; -
How to use logic:present tag in struts el tag
Hi
I am trying to use struts el tags in the jsp page.I am struggling with the following exception: Cannot find bean: "result" in any scope.I couldn't understand why this error is coming even i had the property "result" in my ActionForm.
ActionForm:
package com.finocus.cam.struts.bean;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import com.finocus.cam.common.ValidateFormat;
public class DetailsForm extends org.apache.struts.action.ActionForm {
private final static String LOG_TAG = DetailsForm.class.getName() + ".";
private static final long serialVersionUID = 1L;
// VARIABLES DECLARATION
private String name = null;
private String searchField = null;
private String searchCriteria = null;
private String phonenumber = "";
private String email = "";
private List results = null;
private String adminUserName = "";
private String adminUserEmail = "";
public DetailsForm() {
// GETTER AND SETTER METHODS
public String getName() {
return name;
public void setName(String name) {
this.name = name;
public String getSearchCriteria() {
return searchCriteria;
public void setSearchCriteria(String searchCriteria) {
this.searchCriteria = searchCriteria;
public String getSearchField() {
return searchField;
public void setSearchField(String searchField) {
this.searchField = searchField;
public String getEmail() {
return email;
public void setEmail(String email) {
this.email = email;
public List getResults() {
return results;
public void setResults(List results) {
this.results = results;
public String getPhonenumber() {
return phonenumber;
public void setPhonenumber(String phonenumber) {
this.phonenumber = phonenumber;
public String getAdminUserEmail() {
return adminUserEmail;
public void setAdminUserEmail(String adminUserEmail) {
this.adminUserEmail = adminUserEmail;
public String getAdminUserName() {
return adminUserName;
public void setAdminUserName(String adminUserName) {
this.adminUserName = adminUserName;
// DUMPING THE VALUES IN THE CONSOLE
public void dumpValues() {
StringBuffer sb = new StringBuffer();
sb.append("Name'");
sb.append(name);
sb.append("SearchField");
sb.append(searchField);
sb.append("searchCriteria");
sb.append(searchCriteria);
sb.append("'");
sb.append(" ");
System.out.println(sb.toString());
// RESET() METHOD IS USED FOR STORE FORM'S CURRENT VARIABLES DECLARATION
public void reset(ActionMapping actionMapping, HttpServletRequest request) {
System.out.println("reset() method is called");
this.email = null;
this.searchCriteria = null;
this.searchField = null;
this.results = null;
// VALIDATE() METHOD IS USED TO VALIDATE THE FORM DATA
public ActionErrors validate(ActionMapping actionMapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
System.out.println("Validate()is called");
// Determine if name has been entered.
if (getName() == null || getName().length() == 0
|| getName().equals(" ")) {
errors.add("accountText", new ActionError("searchText.error"));
} else if ((getSearchField().equals("name") == true)
&& (ValidateFormat.isValidText(getName()) == false)) {
errors.add("validAccountName", new ActionError("validName.error"));
if (getSearchField() == null || getSearchField().length() == 0) {
errors.add("accountSearchField", new ActionError(
"searchField.error"));
} else if ((getSearchField().equals("email") == true)
&& (ValidateFormat.isValidEmail(getName()) == false)) {
errors
.add("validAccountEmail", new ActionError(
"validEmail.error"));
} else if ((getSearchField().equals("phonenumber") == true)
&& (ValidateFormat.isValidPhoneNoFormat(getName()) == false)) {
errors.add("validPhoneFormat", new ActionError(
"validPhoneFormat.error"));
if ((getSearchField().equals("searchallfields"))
&& ((ValidateFormat.isValidText(getName()) == false)
&& (ValidateFormat.isValidEmail(getName()) == false) && (ValidateFormat
.isValidPhoneNoFormat(getName()) == false))) {
errors.add("validNameEmail",
new ActionError("validNameEmail.error"));
return errors;
Action class:
package com.finocus.cam.struts.action;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.finocus.cam.db.CAMDbAccess;
import com.finocus.cam.struts.bean.DetailsForm;
public class DetailsAction extends org.apache.struts.action.Action implements
com.finocus.cam.common.CAMConstants {
private final static String LOG_TAG = DetailsAction.class.getName() + ".";
// Global Forwards
public static final String GLOBAL_FORWARD_search = "login";
// Local Forwards
public static final String SUCCESS_search = "success";
private boolean dumpRequestParams = true;
public DetailsAction() {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("SearchAccount execute() is called");
HttpSession session = request.getSession(true);
ArrayList results = null;
DetailsForm search = (DetailsForm) form;
String name = search.getName();
String searchField = search.getSearchField();
String searchCriteria = search.getSearchCriteria();
// Dumping the values of input patameters
if (dumpRequestParams == true) {
request.setAttribute("SearchCriteria", searchCriteria);
request.setAttribute("SearchField", searchField);
request.setAttribute("Text", name);
search.dumpValues();
// Perform search based on what criteria and search Field was entered.
CAMDbAccess dbAccess = CAMDbAccess.getInstance();
if (null != searchCriteria && searchField != null) {
System.out.println("Search Criteria =" + searchCriteria
+ "Selected Option =" + searchField);
if (searchCriteria.equals(Search_Account) && searchField != null) {
results = dbAccess.searchByAccountInfo(name, searchCriteria,
searchField);
System.out.println(" Search criteria :Exact Match was selected.<BR>");
// Place search results in SearchForm for access by JSP.
search.setResults(results);
// Forward control to this Action's input page.
return mapping.findForward(SUCCESS_search);
My jsp page:
<%@ taglib uri="/WEB-INF/tld/struts-bean" prefix="bean" %>
<%@ taglib prefix="logic" uri="http://struts.apache.org/tags-logic-el" %>
<%@ taglib uri="/WEB-INF/tld/struts-html" prefix="html" %>
<html:html>
<head>
<title>Search Page</title>
</head>
<body colorants="LightGreen">
<table width="100%" bgcolor="LightGreen">
<tr>
<td align="left"><font color="brown"><h3><b>Search Info</b></h3></font><hr></td>
</tr>
<tr>
<td align="left"><h4><font color="brown"><b>Search Text:</b></font><%=request.getAttribute("Text")%></h4></td>
</tr><tr>
<td align="left"><h4><font color="brown"><b>Search Field:</b></font><%=request.getAttribute("SearchField")%></h4></td>
</tr><tr>
<td align="left"><h4><font color="brown"><b>Search Criteria:</b></font><%=request.getAttribute("SearchCriteria")%></h4></td>
</tr><tr>
<html:form action="/results.do">
<td><center><html:submit value="AllSearchOptions " /></center></td>
</html:form>
</tr>
<tr>
<td align="left"><font color="brown"><hr><h2><b>Search Results</b></h2></font></td>
</tr>
<tr>
<td>
<table border="1" cellspacing="1" cellpadding="3" width="70%"
bgcolor="white">
<logic:present name="searchbyaccount" property="results">
Results exists
<c:if test="${size==0 }">
<center><font color="red"><b>No Results Found</b></font></center>
</c:if>
<br>
<c:if test="${size>0}">
Size is greater than ZERO
<table border="1" cellspacing="1" cellpadding="3" width="70%"
bgcolor="white">
<tr>
<th>Customerid</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>phone Number</th>
<th>Details</th>
</tr>
<c:forEach var="result" items="${results}">
<c:out value="${result}"/>
<tr>
<td><bean:write name="result" property="customerid"></bean:write></td>
<td><bean:write name="result"
property="accountAdminFirstName"></bean:write></td>
<td><bean:write name="result"
property="accountAdminLastName" /></td>
<td><bean:write name="result" property="accountability" /></td>
<td><bean:write name="result" property="accountAdminPhone" /></td>
<td><html:form action="/accountDetails.do">
<html:submit value="Details" />
</html:form></td>
</tr>
</c:forEach>
</table>
</c:if>
</logic:present>
</table>
</td>
</tr>
</table>
</body>
</html:html> Please refer me where i done a mistake.Thanks in Advancehi all,
I am doing programs in sturts. My program
My program purpose is to retrieve data from the
database.My database is MySql. I know that we can
write connection code in Action Class, it is ok for
some less prog's if i want to use the sane connection
code in more Action Classes it is vasting time and
so.I don't think it's a good idea to put database code in Action classes. (That's one of the biggest drawbacks of Struts - it's completely tied to Actions, HTTP, and the Web.) Better to move that code into plain old Java objects and let the Actions call them.
You'll be able to test them without the container or Struts, and you'll be able to reuse those objects in other, non-Web contexts.
So i want to use <data-sources> tag that is available
in struts-config.xml. I know that thre is tag withThis is the wrong place to configure a connection pool, too. Struts should have nothing to do with it. What if you change Web frameworks to WebWork or Spring? The connection pool should be configured in the container that hosts your app, not Struts.
this name, but the problem is i don't know how to use
this tag. If any budy know how to use this please
tell me the syntax or any example.
plese... reply soon..Don't do it. Think about doing it in your container, not Struts.
% -
Not sure how to use protected method in arraylisy
Hi,
Im wondering how to use the removeRange method in java arraylist, its a protected method which returns void.
http://java.sun.com/j2se/1.3/docs/api/java/util/ArrayList.html#removeRange(int,%20int)
So if my class extends Arraylist i should be able to call the method but the compiler states that it still has protected access in arraylist. Does this mean im still overriding the method in arraylist ? A little explanation of whats happeneing would be appreciated as much as an answer
thanksIn this codefinal class myClass extends java.util.ArrayList {
private ArrayList array = new ArrayList();
public myClass(ArrayList ary){
for(int i=0;i<7;i++) {
array.add(ary.get(i));
ary.removeRange(0,7)
}You are defining a class called myClass which extends ArrayList.
You have a member variable called array which is an ArrayList
You have a constructor which takes a parameter called ary which is an ArrayList
Since ary is an ArrayList, you cannot call it's removeRange() method unless myClass is in the java.util package. Do not put your class in the java.util package.
It seems like what you want to do is to move the items in one ArrayList to another ArrayList rather than copying them. I wrote a program to do this. Here it isimport java.util.*;
public class Test3 {
public static void main(String[] args) {
MyClass myClass = new MyClass();
for (int i=0; i<5; i++) myClass.add("Item-"+i);
System.out.println("------ myClass loaded -------");
for (int i=0; i<myClass.size(); i++) System.out.println(myClass.get(i));
MyClass newClass = new MyClass(myClass);
System.out.println("------ newClass created -------");
for (int i=0; i<newClass.size(); i++) System.out.println(newClass.get(i));
System.out.println("------ myClass now contains -------");
for (int i=0; i<myClass.size(); i++) System.out.println(myClass.get(i));
class MyClass extends java.util.ArrayList {
public MyClass() {}
public MyClass(MyClass ary){
for(int i=0;i<ary.size();i++) add(ary.get(i));
ary.removeRange(0,ary.size());
}You should notice now that I don't create an ArrayList anywhere. Everything is a MyClass. By the way, class names are normally capitalized, variable names are not. Hence this line
MyClass myClass = new MyClass();
In the code above I create an empty MyClass and then populate it with 5 items and then print that list. Then I create a new MyClass using the constructor which takes a MyClass parameter. This copies the items from the parameter list into the newly created MyClass (which is an ArrayList) and then removes the items from the MyClass passed as a parameter. Back in the main() method, I then print the contents of the two MyClass objects.
One thing which may be a little confusing is this line.
for(int i=0;i<ary.size();i++) add(ary.get(i));
the add() call doesn't refer to anything. What it really refers to is the newly created MyClass object which this constructor is building. This newly created object is the 'this' object. So the line above could be rewritten as
for(int i=0;i<ary.size();i++) this.add(ary.get(i));
Hopefully this helps a little. The problems you seem to be having are associated with object oriented concepts. You might try reading this
http://sepwww.stanford.edu/sep/josman/oop/oop1.htm -
Cannot pass parameters from action class to jsp using arraylist
hi all,
Im using datasource for jdbc connection.now i want to pass the selected values in action class from database to a jsp page.I want to use arraylist.But im not familar with arraylist.can anybody help .plzzzzzzzzzzzYou can use plain javabeans to transfer the data. Check out the jsp:usebean tag. If you don't know how to do, check out the Java EE tutorial: http://java.sun.com/javaee/5/docs/tutorial/doc/ Using javabeans in JSP pages starts halfway chapter 4.
-
How to use h:selectOneRadio tag inside h:dataTable tag
Hi All,
Can any one tell me how to use <h:selectOneRadio> tag inside <h:dataTable> tag and how to get selected radio button value in bean ?JSF<h:selectOneMenu value="#{myBean.selectedItem}">
<f:selectItems value="#{myBean.selectItems}" />
</h:selectOneMenu>MyBeanprivate String selectedItem;
public String getSelectedItem() {
return selectedItem;
public void setSelectedItem(String selectedItem) {
this.selectedItem = selectedItem;
public List getSelectItems() {
List selectItems = new ArrayList();
selectItems.add(new SelectItem("key1", "value1"));
selectItems.add(new SelectItem("key2", "value2"));
selectItems.add(new SelectItem("key3", "value3"));
return selectItems;
}String selectedItem should contain the key (key1, key2 or key3) when selected. The values (value1, value2 and value3) are the options as shown in the list. -
How to Use SOAPArray to Exchanged Data with a Web Service
The method of a prototype Web service I created is defined to take many parameters
and return an object of a user defined class. Furthermore, the user defined class
includes data elements of another user defined class and the Java ArrayList class.
This works with a Java client referencing the WebLogic created client.jar file
but I don't know how well it will work with a non-Java client. In particular,
with Perl which is the language that will be used by the developer who first will
test with the prototype.
In posts to this newsgroup use of "language-specific, generic containers" has
been discouraged and the "language-agnostic" SOAPArray recommended. I have searched
this newgsroup and the Web for examples of how to use a SOAPArray in a Web service
EJB to receive parameters and return results but found none.
Will someone refer me to an example or give an overview of how a Java Web service
EJB running in WebLogic 6.1 would use SOAPArray to get parameter values and return
results?
Also, I would like confirmation that it is best to use SOAPArray to exchange data
with a Web service to achieve the goal of a service accessible by any language.
Thank you.Replies in-line:
How are the structures, e.g. gltrans-workType, defined in the Web service?The structure is made up of nested Java Beans, but this does not mean that the
client for your web service has to be written in Java. The WSDL that I sent contains
everything that a .NET-based (or Perl-based, or Python-based, or VB-based, or
C++ based) Web Service Stack needs to correctly create all the data types in the
web services' signature! That's the beauty of XML Schema! It's programming language
independent :-)
In
other words, what definition in Java resulted in the WSDL statements?The WSDL wasn't produced by WLS 6.1, but it (WLS 6.1) can consume it.
What is the signature of method submitGLTransWorkAsJavaBean() in the
Web service?public void submitGLTransWorkAsJavaBean(GlTransactionsCpyType glTransactionsCpyType)
GlTransactionsCpyType is the outer-most Java Bean. WLS 6.1 does not generate
Java Beans for you, but it will use ones that you defined. See the Java Bean tutorial
on the Javasoft sitem for details on how to create a Java Bean.
Was the WSDL generated using the WL tools for creating a Web service?No.
Conclusion:
You asked for someone to provide you with an example of how to use SOAP array
in a WSDL, which is what the attached file contained :-) What you want to do now
is find a tool that can generate Java Bean code from this WSDL (Apache Axis has
a wsdl2java tool that should work), or create the Java Beans yourself. Afterwards,
create a WLS 6.1 Web Service a expose it for a Perl or .NET client.
Regards,
Mike Wooten
"Jeff Carey" <[email protected]> wrote:
>
Please elaborate.
How are the structures, e.g. gltrans-workType, defined in the Web service?
In
other words, what definition in Java resulted in the WSDL statements?
What is the signature of method submitGLTransWorkAsJavaBean() in the
Web service?
Was the WSDL generated using the WL tools for creating a Web service?
Thank you.
"Michael Wooten" <[email protected]> wrote:
Hi Jeff,
Sounds like a pretty cool prototype :-)
I have attached a WSDL (at the bottom of this post) that contains a<schema>
that
uses a SOAPArray to create an array of a <complexType>.
HTH,
Mike Wooten
"Jeff Carey" <[email protected]> wrote:
The method of a prototype Web service I created is defined to take
many
parameters
and return an object of a user defined class. Furthermore, the user
defined class
includes data elements of another user defined class and the Java ArrayList
class.
This works with a Java client referencing the WebLogic created client.jar
file
but I don't know how well it will work with a non-Java client. Inparticular,
with Perl which is the language that will be used by the developerwho
first will
test with the prototype.
In posts to this newsgroup use of "language-specific, generic containers"
has
been discouraged and the "language-agnostic" SOAPArray recommended.
I have searched
this newgsroup and the Web for examples of how to use a SOAPArray in
a Web service
EJB to receive parameters and return results but found none.
Will someone refer me to an example or give an overview of how a Java
Web service
EJB running in WebLogic 6.1 would use SOAPArray to get parameter values
and return
results?
Also, I would like confirmation that it is best to use SOAPArray toexchange
data
with a Web service to achieve the goal of a service accessible by any
language.
Thank you. -
How to use lists or vectors and things?
Hello !
I started to code with java about year ago and the first jdk that i used was 1.5.0. Since 1.5.0, generics have been supported and I think that linkedlists, arraylists and whatever have been made differently. I can't use these generics in my mobile applications so I don't how to use vectors and stacks etc, different way in my applications.
When I used (for instance) arrayists with jdk 1.5.0 or 6, I did it like this:
ArrayList <AL> al = new ArrayList <AL>();
void something(){
for(AL a : al){
//do something
But how do I do these with mobile things, and whats the most similar thing compared to linkedlist and arraylist, vector? I really don't know how to add and remove things with these. If someone can point a good tutorial or thread, I would really appreciate that.
Edited by: RandomNero, for a third time in a row, on Dec 13, 2007 1:42 PMHello,
there's no typed vectors on J2ME,
please check out this link : http://java.sun.com/javame/reference/apis/jsr118/java/util/Vector.html
to know more about J2ME vectors. -
How to convert arraylist into array
how to convert arraylist into array?
If you are using generics, I would use this version of toArray:
List < X > list = ...
X[] array = list.toArray(new X[list.size()]);If you are not using generics, that same thing looks like:
List list = ...
X[] array = (X[]) list.toArray(new X[list.size()]); -
How to use SKU Bundle Links?
Hi,
I'm trying to create a bundle with 2 sku skulinks in crs, but I am not able to make the purchase of the items contained in skulinks in my bundle sku by crs.
The manual that follows this http://docs.oracle.com/cd/E22630_01/Platform.1002/pdf/ATGCommStoreGuide.pdf page 19.
Anyone know how to use skulink and skubundle?Hi <h:selectOneMenu is not working properly for my. My code is as follow
JSP code
<h:selectOneMenu styleClass="selectOneMenu" id="slcAccountIDList" value="#{pc_AccountSelectionPortletView.defaultAccountID}" >
<f:selectItems id="itmsAccountID" value="# pc_AccountSelectionPortletView.accountIDList}"/>
<h:selectOneMenu
view bean code
private String defaultAccountID = "1";
List accountIDList = new ArrayList();
accountIDList.add(new SelectItem("123244", "123244"));
accountIDList.add(new SelectItem("101", "1011"));
accountIDList.add(new SelectItem("102", "1022"));
View bean has a session scope. I am not able to get the selected value.i,e in drop down when i select 101 and clicks on submit button i am not able to get the 101 value in defaultAccountID variable. Please tell where is the problem.
Thanks
Monu
Maybe you are looking for
-
I want to compare the sales values like Incoming order value.Returns value,Billing value,No. of order items,No. of return items,Returns qty,Billed Qty values of BW with R/3 in which tables or t-codes can I check these
-
Adobe v9 on W7 and office 2007. cannot create PDF from MS word using Adobe. But can from Excel, PPT and other MS office apps. Reinslalled Adobe, updated Office, and Adobe no help! Also I can create a pdf from the MS Word and it is using the Adobe 9.
-
Hi, I am writing a Powershell script locally on my machine to aggregate data from SharePoint 2010 and Active Directory. All groups in our SP environment are Active Directory Domain Groups (AD DG). Accessing group members via SharePoint is not possi
-
Issue with Transporting Trans and Comm Structure
Hi Experts, Recently we moved an Infosource ( with Transfer structure and Comm stucture) from D to Q. After movement we checked teh Transport log and we see a warning that says " R3TRROUT458SEFRDF2PUBJRIZGZAOPSNB not found, object also deleted in tar
-
After update 10.9 noise
I noticed that after upgrading the OS to 10.9 vesão appeared one noise in speakers even with the sound off. What can it be?