You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rajesh Kalluri <rk...@manduca.com> on 2002/07/10 20:31:10 UTC

Bean Utils Problems transferring Indexed Properties.....String []-->Integer []

Hi

I am trying to commons-beanutils to transfer data from  a String [] in a
form-bean
to a data bean with a Integer[].

My String[] has three elements when it comes from the ActionForm.

BeanUtils.populate(bean,map); copys only the first element of the String[]
into the integer array.

I searched the archives and the nightly build of commons is supposed to
solve the problem, i tried and it did not help.

Can any one help me with this issue, i am stuck.

regards
Rajesh

-----Original Message-----
From: Michael Connor [mailto:mconnor@baan.com]
Sent: Wednesday, July 10, 2002 2:24 PM
To: 'struts-user@jakarta.apache.org'
Subject: RE: Tiles: pass "title" value to header page


I think I know what your issue is here because I had a problem with this a
couple of days ago.  When I went to use the title attribute in the header,
it was null.  I had to do this in my basicLayout page...

<tiles:useAttribute name="title" classname="java.lang.String"
ignore="true"/>

<tiles:insert attribute="header">
   <tiles:put name="title" value="<%=title%>"/>
</tiles:insert>

It didn't really make sense to me why the title attribute didn't trickle
down into the header.  It seems like a scope issue and I was trying
different ways of declaring scope but didn't have any luck.  This is the
only way I could get it to work.

Michael Connor

-----Original Message-----
From: James Mitchell [mailto:jmitchtx@telocity.com]
Sent: Wednesday, July 10, 2002 2:30 AM
To: Struts Users Mailing List
Subject: RE: Tiles: pass "title" value to header page


> -----Original Message-----
> From: David M. Karr [mailto:dmkarr@earthlink.net]
> Sent: Tuesday, July 09, 2002 8:47 PM
> To: struts-user@jakarta.apache.org
> Subject: Tiles: pass "title" value to header page
>
>
> I have a simple page definition that looks like this:
>
> --------------
> <tiles:insert page="basicLayout.jsp">
>  <tiles:put name="title" value="Music Index Home"/>
>  <tiles:put name="header" value="header.jsp"/>
>  <tiles:put name="footer" value="footer.jsp"/>
>  <tiles:put name="sidebar" value="menu.jsp"/>
>  <tiles:put name="body" value="mainBody.jsp"/>
> </tiles:insert>
> --------------
>
> I'm thinking that it might be good to code "header.jsp" so it
> shows the "title"
> string, by reference, instead of hard-coded, so I don't have to
> write it twice,

What would you have twice?  The tiles:put or the tiles:getAsString?
Why not just define the title in the ApplicationResources.properties file?

> in two different places.  I would have to somehow "pass" the
> value provided for
> the "title" attribute to "header.jsp" so it can read it as a
> request attribute,
> possibly.
>
> What are the various ways I could achieve this (hopefully without using
> scriptlets)?  Is this a reasonable thing to do?

It's not clear (to me) what you want to do.
Off-hand (and if I am guess-timating correctly) I can think of about 10
unique ways to avoid duplication of code (or in this case, tiles
configuration)

>
> If I could send "request parameters" or "attributes" with
> "tiles:insert", then
> with my "tiles:insert" tag for the "header" attribute, I could
> pass the output
> of "tiles:getAsString" to get the "title" field.  I don't know if this is
> possible, however.

In concept, you would only want to do this if you wanted a different title
for each view.

I can provide (very basic) code samples for what I consider to be "Best
Practices with Tiles".  Let me know if you would like a copy.

>
> --
> ===================================================================
> David M. Karr          ; Java/J2EE/XML/Unix/C++
> dmkarr@earthlink.net
>


James Mitchell
Software Engineer\Struts Evangelist
Struts-Atlanta, the "Open Minded Developer Network"
http://www.open-tools.org/struts-atlanta








--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


BeanUtils.describe and BeanUtils.populate indexeed properties...

Posted by Rajesh Kalluri <rk...@manduca.com>.
I saw a similar issue on the archive but did not see what the solution to
this was, so decided to ask the same question again.

Do BeanUtils.describe and BeanUtils.populate supposed to handle indexed
properties?

Suppose I have this JavaBean:

public class NameBean {
     private String[] name;

     public String[] getName() {
          return this.name;
     }
     public void setName(String[] name) {
          this.name = name;
     }
     public String getName(int index) {
          return this.name[index];
     }
     public void setName(int index, String name) {
          this.name[index] = name;
     }
}

     NameBean nameBean = new NameBean();
     nameBean.setName(new String[] {"John", "Paul", "Jack"});

     Map properties = BeanUtils.describe(nameBean);

I would expect the following code to return a Map containing:
name[0]="John", name[1]="Paul", name[2]="Jack"

but instead,

I get name="John".
Only the first element is considered.

regards

Rajesh


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Bean Utils Problems transferring Indexed Properties.....String []-->Integer []

Posted by Rajesh Kalluri <rk...@manduca.com>.
Craig,

I have this Integer[] as part of a bean and String [] as part of a form bean

Do i have to register custom describe to transfer data from a bean having a
string[] to an Integer

in order to use BeanUtils.populate(). If so do you have an example.


// I am trying to transfer liek this.

Map Properties = BeanUtils.describe(formBean);

BeanUtils.populate(dataBean,map);

DATA BEAN:
 	/**
     * The authors of the article
     * <p>
     */
     private Integer[] authors;


	/**
	 * Returns the authors.
	 * @return Integer[]
	 */
	public Integer[] getAuthors() {
		return authors;
	}

	/**
	 * Sets the authors.
	 * @param authors The authors to set
	 */
	public void setAuthors(Integer[] authors) {
		this.authors = authors;
	}

FORM BEAN:
 /**
     * The author of the article
     * <p>
     */
    private String[] authors;




	/**
	 * Returns the authors.
	 * @return Integer[]
	 */
	public String[] getAuthors() {
		return authors;
	}

	/**
	 * Sets the authors.
	 * @param authors The authors to set
	 */
	public void setAuthors(String[] authors) {
		this.authors = authors;
	}



-----Original Message-----
From: Craig R. McClanahan [mailto:craigmcc@apache.org]
Sent: Wednesday, July 10, 2002 2:48 PM
To: Struts Users Mailing List
Subject: Re: Bean Utils Problems transferring Indexed
Properties.....String []-->Integer []




On Wed, 10 Jul 2002, Rajesh Kalluri wrote:

> Date: Wed, 10 Jul 2002 14:31:10 -0400
> From: Rajesh Kalluri <rk...@manduca.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Bean Utils Problems transferring Indexed Properties.....String
>     []-->Integer []
>
>
> Hi
>
> I am trying to commons-beanutils to transfer data from  a String [] in a
> form-bean
> to a data bean with a Integer[].
>
> My String[] has three elements when it comes from the ActionForm.
>
> BeanUtils.populate(bean,map); copys only the first element of the String[]
> into the integer array.
>
> I searched the archives and the nightly build of commons is supposed to
> solve the problem, i tried and it did not help.
>
> Can any one help me with this issue, i am stuck.
>

  Integer integerArray[] =
    (Integer[]) ConvertUtils.convert(stringArray, Integer.class);

> regards
> Rajesh

Craig


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Bean Utils Problems transferring Indexed Properties.....String []-->Integer []

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 10 Jul 2002, Rajesh Kalluri wrote:

> Date: Wed, 10 Jul 2002 14:31:10 -0400
> From: Rajesh Kalluri <rk...@manduca.com>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: Struts Users Mailing List <st...@jakarta.apache.org>
> Subject: Bean Utils Problems transferring Indexed Properties.....String
>     []-->Integer []
>
>
> Hi
>
> I am trying to commons-beanutils to transfer data from  a String [] in a
> form-bean
> to a data bean with a Integer[].
>
> My String[] has three elements when it comes from the ActionForm.
>
> BeanUtils.populate(bean,map); copys only the first element of the String[]
> into the integer array.
>
> I searched the archives and the nightly build of commons is supposed to
> solve the problem, i tried and it did not help.
>
> Can any one help me with this issue, i am stuck.
>

  Integer integerArray[] =
    (Integer[]) ConvertUtils.convert(stringArray, Integer.class);

> regards
> Rajesh

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>