aspose file tools*
The moose likes JSP and the fly likes How to get data from bean to a string? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to get data from bean to a string?" Watch "How to get data from bean to a string?" New topic
Author

How to get data from bean to a string?

Jan Munkhammar
Greenhorn

Joined: Feb 11, 2004
Posts: 4
I want to read some data from a bean and put it in a string so I can ripp off some useless info from it. The code below prints "jan@isp1" on my page but how can I put this into a string that I can work with?
<jsp:useBean id="userInfo" scope="request" class="model.UserInfo" />
<bean:write name="userInfo" property="info(publicDhcpUserName)"/>
I'm total newbie on this may I add, thanks \\Jan


Member # 66564
James Clinton
Ranch Hand

Joined: Jun 23, 2003
Posts: 190
I am assuming you want to manipulate the string in the JSP, if so, try something like this:
Solution 1:
Jan Munkhammar
Greenhorn

Joined: Feb 11, 2004
Posts: 4
Well, that's the way I did it before using Apache/Tomcat. The new application uses J2EE and JBoss. It just complains that "Main has been deprecated" when trying the "old" syntax. I don't have any "imports" on my pages just a bunch of "taglibs".
Any ideas?

Thanks, \\Jan
James Clinton
Ranch Hand

Joined: Jun 23, 2003
Posts: 190
You are using J2EE in the first instance. J2EE is simply the Enterprise APIs.
The first instance should work on any app server. Where is the error being thrown, in the JSPs?
Provide some JSP and Class code.
lali virdi
Greenhorn

Joined: Feb 09, 2004
Posts: 19
<jsp:useBean id="userInfo" scope="request" class="model.UserInfo" />
your bean may have getter and setter method
String name(anything) = userInfo.getterMethod(); which you want to access
i think it will work fine
or use
<jsp:getProperty name="ab" property="fieldName which you want to access" />
James Clinton
Ranch Hand

Joined: Jun 23, 2003
Posts: 190
I believe something more is going on here, than a simple getXXX call.
"Main has been deprecated"
Def interested in see your code.
Jan Munkhammar
Greenhorn

Joined: Feb 11, 2004
Posts: 4
This is the UserInfo.java. I have no source if the ReadResult.
package model;
import java.util.*;
import ReadResult;
public class UserInfo {
private String name=null;
private boolean unauthenticated=true;
private boolean anonymous=true;
private boolean subscribed=false;
private Map info = new HashMap();
public static class Values {
private String [] values;
public Values(String [] values) {
this.values = values;
}
public String getValue(int index) {
if (index >= values.length || index < 0)
return null;
return values[index];
}
public Iterator getIter() {
return Arrays.asList(values).iterator();
}
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("[");
for (int i=0; i<values.length; i++) {
sb.append(values[i]);
if (i < values.length-1)
sb.append(", ");
}
sb.append("]");
return sb.toString();
}
}
public UserInfo() { }
UserInfo (ReadResult res) {

for (int i=0; i<res.attributes.length; i++) {
Values val = new Values(res.attributes[i].values);
info.put(res.attributes[i].name, val);
}

Values values = getInfo("name");
if (values != null)
name = values.getValue(0);

values = getInfo("unauthenticated");
if (values != null)
unauthenticated = ! "false".equalsIgnoreCase(values.getValue(0));
else
unauthenticated = true;
values = getInfo("anonymous");
if (values != null)
anonymous = ! "false".equalsIgnoreCase(values.getValue(0));
else
anonymous = true;
subscribed = res.result.length > 0;
}
public Values getInfo(String key) {
return (Values)info.get(key);
}

public String getName() {
return this.name;
}

public boolean isUnauthenticated() {
return this.unauthenticated;
}
public boolean isAnonymous() {
return this.anonymous;
}
public boolean isSubscribed() {
return this.subscribed;
}
}// UserInfo
James Clinton
Ranch Hand

Joined: Jun 23, 2003
Posts: 190
Please use code blocks in future
James Clinton
Ranch Hand

Joined: Jun 23, 2003
Posts: 190
Jan
This seems to have little relation to your orginal post or Main error!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

"Main has been deprecated"

Probably has nothing whatsoever to do with your pages, but with your server setup. Can you get the container-provided examples running?
I think I've seen errors something along these lines when the container was unable to start up the compiler.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jan Munkhammar
Greenhorn

Joined: Feb 11, 2004
Posts: 4
I managed to solve this a long time ago but someone might have use of the info.

<code>
<bean efine id="isp_login_obj" name="userInfo" property="info publicDhcpUserName)"/>
<%
String isp_login = isp_login_obj.toString();
%>
<td class="tablecell"><html:text property="userName" value="<%=isp_login%>" readonly="true" size="30"/></td>
</code>

cheers, \\Jan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get data from bean to a string?
 
Similar Threads
Strange problem in retrieving the table data in a jsp
How to access Bean
Basic useBean question
get data from Document object
Mapping file for table that has two classes for maintained for attribute mapping