You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by RogerV <ro...@googlemail.com> on 2009/11/16 16:29:07 UTC

OGNL expression help

Could someone show me the correct way to insert a string field length into
the size attribute of a <s:textfield> element. 

Regards
-- 
View this message in context: http://old.nabble.com/OGNL-expression-help-tp26373897p26373897.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


RE: OGNL expression help

Posted by Neil Aggarwal <ne...@JAMMConsulting.com>.
> Extending String? String is final so it isn't doable ;-)

I did not check that.

I see someone posted a better solution than this but 
I guess if someone wanted to have a getLength() for
a String, they could write a container class that 
holds a String and then implement all the methods to 
call the corresponding String methods.  That would be
really be a pain!

Anyway, thanks for the clarification,
	Neil

--
Neil Aggarwal, (281)846-8957, http://UnmeteredVPS.net
Host your struts app on a CentOS VPS for only $25/month!
Unmetered bandwidth, 7 day no risk trial, Google Checkout


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


Re: OGNL expression help

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/11/16 Neil Aggarwal <ne...@jammconsulting.com>:
> You could create your own MyString class that
> extends String and then have a getLength() method
> that calls super.length().

Extending String? String is final so it isn't doable ;-)


Regards
-- 
Lukasz
http://www.lenart.org.pl/

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


RE: OGNL expression help

Posted by Neil Aggarwal <ne...@JAMMConsulting.com>.
> length are related to the fact that the method call on a string is
> String.length() not String.getLength and when I use 
> size="%{attrib.length}"
> OGNL is trying to call getAttrib().getLength() on my action 

You could create your own MyString class that
extends String and then have a getLength() method
that calls super.length().

It's a pain, but should work.

	Neil

--
Neil Aggarwal, (281)846-8957, http://UnmeteredVPS.net
Host your struts app on a CentOS VPS for only $25/month!
Unmetered bandwidth, 7 day no risk trial, Google Checkout


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


RE: OGNL expression help

Posted by Neil Aggarwal <ne...@JAMMConsulting.com>.
> Doesn't help unfortunately as the 
> length of the string
> in characters is not the same as the space required to 
> display it in full!

Have you tried adding 2 or 3 to the length value?

	Neil


--
Neil Aggarwal, (281)846-8957, http://UnmeteredVPS.net
Host your struts app on a CentOS VPS for only $25/month!
Unmetered bandwidth, 7 day no risk trial, Google Checkout


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


Re: OGNL expression help

Posted by RogerV <ro...@googlemail.com>.


Chris Pratt wrote:
> 
> Like Neil suggested, use "attrib.length()"  The extra parens cause OGNL to
> call getAttrib().length() rather than getAttrib().getLength().
>   (*Chris*)
> 

Thanks, that does work in that the textfield re-sizes according to the
length of the string. Doesn't help unfortunately as the length of the string
in characters is not the same as the space required to display it in full!

Regards

-- 
View this message in context: http://old.nabble.com/OGNL-expression-help-tp26373897p26387022.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: OGNL expression help

Posted by Chris Pratt <th...@gmail.com>.
Like Neil suggested, use "attrib.length()"  The extra parens cause OGNL to
call getAttrib().length() rather than getAttrib().getLength().
  (*Chris*)

On Mon, Nov 16, 2009 at 8:08 AM, RogerV <ro...@googlemail.com> wrote:

>
>
>
> Kawczynski, David wrote:
> >
> > For this example pretend your field "firstname" has a max length of 15:
> > <s:textfield name="firstname" maxlength="15" />
> >
>
> LOL :)  I suspect that my difficulties in trying to use OGNL to insert the
> length are related to the fact that the method call on a string is
> String.length() not String.getLength and when I use size="%{attrib.length}"
> OGNL is trying to call getAttrib().getLength() on my action -which won't
> work.
>
> So, rephrasing slighly, how do I/can I use OGNL to call methods on
> attributes in my actions that do not follow the Bean pattern.
>
> Regards
>
> > -----Original Message-----
> > From: RogerV [mailto:roger.varley@googlemail.com]
> > Sent: Monday, November 16, 2009 10:29 AM
> > To: user@struts.apache.org
> > Subject: OGNL expression help
> >
> >
> > Could someone show me the correct way to insert a string
> > field length into
> > the size attribute of a <s:textfield> element.
> >
> > Regards
> > --
>
> --
> View this message in context:
> http://old.nabble.com/OGNL-expression-help-tp26373897p26374503.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

RE: OGNL expression help

Posted by RogerV <ro...@googlemail.com>.


Kawczynski, David wrote:
> 
> For this example pretend your field "firstname" has a max length of 15:
> <s:textfield name="firstname" maxlength="15" />
> 

LOL :)  I suspect that my difficulties in trying to use OGNL to insert the
length are related to the fact that the method call on a string is
String.length() not String.getLength and when I use size="%{attrib.length}"
OGNL is trying to call getAttrib().getLength() on my action -which won't
work. 

So, rephrasing slighly, how do I/can I use OGNL to call methods on
attributes in my actions that do not follow the Bean pattern.

Regards

> -----Original Message-----
> From: RogerV [mailto:roger.varley@googlemail.com] 
> Sent: Monday, November 16, 2009 10:29 AM
> To: user@struts.apache.org
> Subject: OGNL expression help
> 
> 
> Could someone show me the correct way to insert a string 
> field length into
> the size attribute of a <s:textfield> element. 
> 
> Regards
> -- 

-- 
View this message in context: http://old.nabble.com/OGNL-expression-help-tp26373897p26374503.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


RE: OGNL expression help

Posted by Neil Aggarwal <ne...@JAMMConsulting.com>.
> > Could someone show me the correct way to insert a string 
> > field length into
> > the size attribute of a <s:textfield> element. 

> <s:textfield name="firstname" maxlength="15" />

I think he was looking for something more involved,
something like:

<s:textfield name="firstname" size="%{myString.length()}" />

I have not tested code to do this, so I don't know if
that would work.  Also, what if the myString is null
or an empty string.  The code would throw a null
pointer or the field size would be zero.

	Neil

--
Neil Aggarwal, (281)846-8957, http://UnmeteredVPS.net
Host your struts app on a CentOS VPS for only $25/month!
Unmetered bandwidth, 7 day no risk trial, Google Checkout


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


RE: OGNL expression help

Posted by "Kawczynski, David" <da...@merck.com>.
For this example pretend your field "firstname" has a max length of 15:
<s:textfield name="firstname" maxlength="15" />


> -----Original Message-----
> From: RogerV [mailto:roger.varley@googlemail.com] 
> Sent: Monday, November 16, 2009 10:29 AM
> To: user@struts.apache.org
> Subject: OGNL expression help
> 
> 
> Could someone show me the correct way to insert a string 
> field length into
> the size attribute of a <s:textfield> element. 
> 
> Regards
> -- 
> View this message in context: 
> http://old.nabble.com/OGNL-expression-help-tp26373897p26373897.html
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
Notice:  This e-mail message, together with any attachments, contains information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates Direct contact information for affiliates is available at http://www.merck.com/contact/contacts.html) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system.


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