Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get data from bean to a string?

 
Jan Munkhammar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
 
James Clinton
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
lali virdi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Please use code blocks in future
 
James Clinton
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jan
This seems to have little relation to your orginal post or Main error!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic