• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How to get data from bean to a string?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am assuming you want to manipulate the string in the JSP, if so, try something like this:
Solution 1:
 
Jan Munkhammar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<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
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please use code blocks in future
 
James Clinton
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jan
This seems to have little relation to your orginal post or Main error!
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

"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.
 
Jan Munkhammar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic