Hi,

Here's an alternative solution using a custom Formatter/TypeConverter.

public abstract class XMLTypeConverter<T> implements TypeConverter<T>,
Formatter<T> {
  public String format(T input) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(out);
    encoder.writeObject(input);
    encoder.close();
    return CryptoUtil.encrypt(out.toString());
  }

  public T convert(String input, Class<? extends T> targetType,
    Collection<ValidationError> errors) {
    ByteArrayInputStream in = new
ByteArrayInputStream(CryptoUtil.decrypt(input).getBytes());
    XMLDecoder decoder = new XMLDecoder(in);
    @SuppressWarnings("unchecked")
    T obj = (T)decoder.readObject();
    decoder.close();
    return obj;
  }

  // Other methods can be left empty.
}

For object you want to store on a page, create a subclass of
XMLTypeConverter and put it into the extension package.
Here's the one for Customer, for example.

public class CustomerTypeConverter
  extends XMLTypeConverter<Customer>
  implements Formatter<Customer>, TypeConverter<Customer> {}

Assuming an ActionBean has a field 'customer' of type Customer, just
write a hidden tag on the JSP.

<stripes:hidden name="customer" />

The Formatter encodes the customer object to an encrypted string when
the tag is rendered.
And when the form is submitted, the TypeConverter decodes the string
back into a Customer object.

In the actual solution, JSON might be a better alternative to XML
because the output string is smaller.

To all:
It might be useful to add a 'formatter' property to InputTagSupport so
that we can specify non-global formatter for a particular input tag
(like 'converter' in @Validate).
Was there a discussion about this before?

Regards,
Iwao

2012/4/3 Chut Yee <yeec...@gmail.com>:
> Hi guys,
>
> I like to make a proposal - for making the rendered page an additional scope
> where we can store objects. The objects can be serialized into an encrypted
> block in a hidden textbox. On postback the encrypted block will be 
> deserialized
> and bind back to the original variables.
>
> We can add an annotation for this:
>
> @PageScope
> private Customer customer;
>
> I get my idea from VIEWSTATE mechanism of ASP.NET. This is basically the only
> thing I missed about ASP.NET.
>
> Currently I have been using a fair bit of <stripes:hidden> for achieving the
> effect. It is simply too sloppy.
>
> What do you guys think?
>
> Cheers,
> Chut
>
>
> 7th years into stripes and counting...
>
>
> ------------------------------------------------------------------------------
> Better than sec? Nothing is better than sec when it comes to
> monitoring Big Data applications. Try Boundary one-second
> resolution app monitoring today. Free.
> http://p.sf.net/sfu/Boundary-dev2dev
> _______________________________________________
> Stripes-users mailing list
> Stripes-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to