You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Richard Raquepo <rr...@primeorion.com> on 2004/06/07 12:55:30 UTC

converting bean:write to c:out

hi,

i am converting some of the jsp's to jstl.

how do i convert this line to jstl:

    <bean:write name="info" property="value(email)"/>

where getValue is defined as 

HashMap values = new HashMap();
.....
public String get(String name){
     String value = (String) values.get(name);
     return value;
}

hoping for your immediate response.

thanks a lot.


-richard

Re: converting bean:write to c:out

Posted by Bill Siggelkow <bi...@bellsouth.net>.
Oops -- you're right Kris -- thanks for the clarification.

Kris Schneider wrote:

> Well, sort of. In the typical example of a mapped property (like the one Richard
> provided), the map itself isn't exposed as a JavaBean property, so JSTL can't
> get at the information it contains:
> 
> private final Map values = new HashMap();
> 
> public void setValue(String key, Object value) {
>   values.put(key, value);
> }
> 
> public Object getValue(String key) {
>   return values.get(key);
> }
> 
> So, in order for JSTL to get at that information, you have to expose the map as
> a JavaBean property. For example, by adding a method like:
> 
> public Map getValues() {
>   return values;
> }
> 
> Then JSTL can be used like:
> 
> <c:out value="${info.values.email}"/>
> 
> Quoting Bill Siggelkow <bi...@bellsouth.net>:
> 
> 
>><c:out value="${info.value.email}"/>
>>  -- or --
>><c:out value="${info.value['email']}"/>
>>
>>Richard Raquepo wrote:
>>
>>>hi,
>>>
>>>i am converting some of the jsp's to jstl.
>>>
>>>how do i convert this line to jstl:
>>>
>>>    <bean:write name="info" property="value(email)"/>
>>>
>>>where getValue is defined as 
>>>
>>>HashMap values = new HashMap();
>>>.....
>>>public String get(String name){
>>>     String value = (String) values.get(name);
>>>     return value;
>>>}
>>>
>>>hoping for your immediate response.
>>>
>>>thanks a lot.
>>>
>>>
>>>-richard
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: user defined beans in form bean

Posted by Bill Siggelkow <bi...@bellsouth.net>.
<html:text property="myBean.firstName"/>
<html:text property="myBean.lastName"/>
...

Jannu Winod wrote:
> how to handle user defined beans if we are using them in form beans. see the following code. Im looking for the jsp code in struts to define the text fields
> 
> pls send me the code. 
> 
> with thnx.
> 
> class MyBean 
> {
>  private String firstName;
>  private String lastName;
> 
>  public void setFirstName(String strFirstName){
>   this.firstName=strFirstName;
>  }
>  public String getFirstName(){
>   return this.firstName;
>  }
> 
>  public void setLastName(String strLastName){
>   this.lastName=strLastName;
>  }
>  public String getLastName(){
>   return this.lastName;
>  }
> }
> 
> FormBean : 
> 
> public class MyForm extends ActionForm
> {
>  private MyBean mybean;
>  private String ssno;
> 
>  public void setMybean(MyBean mybean){
>   this.mybean=mybean;
>  }
>  public MyBean getMybean(){
>   return this.mybean;
>  }
>  public void setSsno(String ssno){
>   this.ssno=ssno;
>  }
>  public String getSsno(){
>   return this.ssno;
>  }
> }
> 
>  
> 
> JSP:
> 
> First Name : <input type="text" name="txtFirstName">
> Last Name : <input type="text" name="txtLastName">
> SSNo : <input type="text" name="txtSSNo">
> 
> 
> 		
> ---------------------------------
> Do you Yahoo!?
> Friends.  Fun. Try the all-new Yahoo! Messenger


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


user defined beans in form bean

Posted by Jannu Winod <wi...@yahoo.com>.
how to handle user defined beans if we are using them in form beans. see the following code. Im looking for the jsp code in struts to define the text fields

pls send me the code. 

with thnx.

class MyBean 
{
 private String firstName;
 private String lastName;

 public void setFirstName(String strFirstName){
  this.firstName=strFirstName;
 }
 public String getFirstName(){
  return this.firstName;
 }

 public void setLastName(String strLastName){
  this.lastName=strLastName;
 }
 public String getLastName(){
  return this.lastName;
 }
}

FormBean : 

public class MyForm extends ActionForm
{
 private MyBean mybean;
 private String ssno;

 public void setMybean(MyBean mybean){
  this.mybean=mybean;
 }
 public MyBean getMybean(){
  return this.mybean;
 }
 public void setSsno(String ssno){
  this.ssno=ssno;
 }
 public String getSsno(){
  return this.ssno;
 }
}

 

JSP:

First Name : <input type="text" name="txtFirstName">
Last Name : <input type="text" name="txtLastName">
SSNo : <input type="text" name="txtSSNo">


		
---------------------------------
Do you Yahoo!?
Friends.  Fun. Try the all-new Yahoo! Messenger

Re: converting bean:write to c:out

Posted by Richard Raquepo <rr...@primeorion.com>.
thanks.

i just modified my code to expose the Map, then viola...

i can now start converting some of my jsp's to JSTL.

thanks again guys...

-Richard

----- Original Message -----
From: "Kris Schneider" <kr...@dotech.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Tuesday, June 08, 2004 1:42 AM
Subject: Re: converting bean:write to c:out


> Well, sort of. In the typical example of a mapped property (like the one
Richard
> provided), the map itself isn't exposed as a JavaBean property, so JSTL
can't
> get at the information it contains:
>
> private final Map values = new HashMap();
>
> public void setValue(String key, Object value) {
>   values.put(key, value);
> }
>
> public Object getValue(String key) {
>   return values.get(key);
> }
>
> So, in order for JSTL to get at that information, you have to expose the
map as
> a JavaBean property. For example, by adding a method like:
>
> public Map getValues() {
>   return values;
> }
>
> Then JSTL can be used like:
>
> <c:out value="${info.values.email}"/>
>
> Quoting Bill Siggelkow <bi...@bellsouth.net>:
>
> > <c:out value="${info.value.email}"/>
> >   -- or --
> > <c:out value="${info.value['email']}"/>
> >
> > Richard Raquepo wrote:
> > > hi,
> > >
> > > i am converting some of the jsp's to jstl.
> > >
> > > how do i convert this line to jstl:
> > >
> > >     <bean:write name="info" property="value(email)"/>
> > >
> > > where getValue is defined as
> > >
> > > HashMap values = new HashMap();
> > > .....
> > > public String get(String name){
> > >      String value = (String) values.get(name);
> > >      return value;
> > > }
> > >
> > > hoping for your immediate response.
> > >
> > > thanks a lot.
> > >
> > >
> > > -richard
>
> --
> Kris Schneider <ma...@dotech.com>
> D.O.Tech       <http://www.dotech.com/>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: converting bean:write to c:out

Posted by Kris Schneider <kr...@dotech.com>.
Well, sort of. In the typical example of a mapped property (like the one Richard
provided), the map itself isn't exposed as a JavaBean property, so JSTL can't
get at the information it contains:

private final Map values = new HashMap();

public void setValue(String key, Object value) {
  values.put(key, value);
}

public Object getValue(String key) {
  return values.get(key);
}

So, in order for JSTL to get at that information, you have to expose the map as
a JavaBean property. For example, by adding a method like:

public Map getValues() {
  return values;
}

Then JSTL can be used like:

<c:out value="${info.values.email}"/>

Quoting Bill Siggelkow <bi...@bellsouth.net>:

> <c:out value="${info.value.email}"/>
>   -- or --
> <c:out value="${info.value['email']}"/>
> 
> Richard Raquepo wrote:
> > hi,
> > 
> > i am converting some of the jsp's to jstl.
> > 
> > how do i convert this line to jstl:
> > 
> >     <bean:write name="info" property="value(email)"/>
> > 
> > where getValue is defined as 
> > 
> > HashMap values = new HashMap();
> > .....
> > public String get(String name){
> >      String value = (String) values.get(name);
> >      return value;
> > }
> > 
> > hoping for your immediate response.
> > 
> > thanks a lot.
> > 
> > 
> > -richard

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: converting bean:write to c:out

Posted by Bill Siggelkow <bi...@bellsouth.net>.
<c:out value="${info.value.email}"/>
  -- or --
<c:out value="${info.value['email']}"/>

Richard Raquepo wrote:
> hi,
> 
> i am converting some of the jsp's to jstl.
> 
> how do i convert this line to jstl:
> 
>     <bean:write name="info" property="value(email)"/>
> 
> where getValue is defined as 
> 
> HashMap values = new HashMap();
> .....
> public String get(String name){
>      String value = (String) values.get(name);
>      return value;
> }
> 
> hoping for your immediate response.
> 
> thanks a lot.
> 
> 
> -richard


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org