struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Li Ying <liying.cn.2...@gmail.com>
Subject Re: [S2] Displaying user entered values after failed type conversion while using getText()?
Date Fri, 18 Nov 2011 07:34:14 GMT
I have 2 suggestion:

(A)Declare the input data field in your action as a String, instead of
date or integer.
So, the String field can hold anything input from client side.
But this will be inconvenience to use, because you have to convert the
string value
to the date or integer value by yourself, before you can use it.

Another solution is:
(B)Declare 2 fields in your action.
One as date or integer, to hold the type converted valid value.
Another as String,  to hold the original input text.

On the input page side,  you also need 2 form elements.
One is <input>, which will send data to the [real value] field,
and another is <hidden>, which will send data to the [original input
text] field.

User can only see the <input>, and input data in it.
you can create some JS code, to copy the <input> content to the
<hidden> element, before the form be posted.

When the type conversion fails, and the input page displayed again,
the <hidden> element will contains the original input text,
and the <input> element will contains empty text.

You can create some JS code, to copy the <hidden> element content to
the <input> element, after the page loaded.
Or, you can simply set the value of the <input> element from the
[original input text] field of Action.


Hope this helps.



2011/11/17 Burton Rhodes <burtonrhodes@gmail.com>:
> I am having an issue with displaying the original value entered on a
> form after failed type conversion.  This "bug" is caused by my use of
> getText() in the form value fields.  I'm curious how one solves this
> issue for making sure the field is formatted correctly upon display,
> but also making sure the users see the orignal malformed entry after
> failed type conversion.  I have a few examples below.  The last one
> displays works the way it should.  The top two only present an empty
> field upon failed type conversion.
>
> [code snippets]
>
> <!-- "convert to java.util.Date": Will NOT display the incorrectly
> entered date -->
> <s:textfield key="xaction.closedDate"
> value="%{getText('format.dateShort',{xaction.closedDate != null ?
> xaction.closedDate :''})}" />
>
> <!-- "convert to BigDecimal": Will NOT display the incorrectly entered
> number -->
> <s:textfield key="xaction.listPrice"
> value="%{getText('format.money',{xaction.listPrice != null ?
> xaction.listPrice :''})}"/>
>
> <!-- "convert to Integer": Will display the incorrect value -->
> <s:textfield key="xaction.beds" />
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message