Re: [Stripes-users] Populating Sets

Subject:   Re: [Stripes-users] Populating Sets (find more)
From:   Sebastian Beigel <hidden> (find more)
Date:   Dec 05, 2005 08:54

Hi,

> I think there are several ways to tackle this depending on exactly what
> the underlying objects look like, and what you need done in order to
> make your use case work...

I made this work using a request-scope action bean, a Formatter for my
domain objects and a constructor with an appropriate String param (to
process the id) -- and fixing a bug (or missing feature *g*) in Stripes
[1]

Example:

In your action bean:

public Foo foo;

// getter & setter...


in your domain object Foo:

public Set<Bar> bars;

// getter & setter...


in your child domain object Bar:

// constructor
public Bar(String id) {
 this.id = new Long(id);
}

and in your JSP:

<c:forEach items="${actionBean.bars}" var="b" varStatus="status">
 <stripes:checkbox name="foo.bars" value="${b.id}"
checked="${actionBean.foo.bars}" /> ${b.label}
</c:forEach>


This works also w/ multi-select boxes like:

<stripes:select multiple="true" name="foo.bars">
 <stripes:options-collection collection="${actionBean.bars}" value="id"
label="label" />
</stripes:select>


You need a special Formatter for your domain objects or you adjust your
toString() in these objects, I prefer the former (my domain objects all
extend BaseModel):

BaseModelFormatter:

// other (empty) methods omitted

public String format(Object input) {
 return ((BaseModel) input).getId().toString();
}



Stripes is great! I knew there would be a way to do this in a simple and
elegant way! :)

Sebastian


[1] http://stripes.mc4j.org/jira/browse/STS-119


--
Sebastian Beigel // Software Architekt
(F) Die Firma GmbH // Innovative Kommunikation
Schwalbacher Stra├če 74 // D-65183 Wiesbaden
T +49.6 11.2 38 50.24 // F +49.6 11.2 38 50.11
mailto:hidden // http://www.diefirma.de


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Stripes-users mailing list
hidden
https://lists.sourceforge.net/lists/listinfo/stripes-users