Sloshed hey hehehe :)
I'm doing something with a select atm, so here's my 2c on howto do what
you want, but I'm using Objects rather than simple enums, but you can make
a List<ENUMTYPE> of your ENUMTYPE or something equally (un)elegant i guess.
In page class you're going to need this stuff
private Long onActivateId ;
@Property
@Persist
private YourObject editOfYourObject;
@Inject
private YourObjectService tapestryYourObjectService;
@Inject
SelectModelFactory selectYourObjectModelFactory;
@Property
private SelectModel yourObjectSelectModel;
//i noticed george in an earlier reply made this accessible by a simple
getCarTypeModel() method
//which is pretty neat, I might incorporate that touch
@Property
private ENUMTYPE yourEnumField ;
void onActivate(Long id){
onActivateId = id ;
}
In the setupRender phase
void setupRender() {
List<YourObject> yourObjects = tapestryYourObjectService.findAll()
; //or just a quick hibernate query
yourObjectSelectModel =
selectYourObjectModelFactory.create(yourObjects,"displayColumnNameHere") ;
editYourObject = tapestryYourObjectService.getById(onActivateid) ;
}
So far above is the general gist for getting a select to work with any
object type and the options of the select will be readable with whatever
"displayColumnNameHere" - usually it's "name" if you were to have objects
which have a name field so it's easy to distinguish.
In your template,
<t:beaneditform object="editYourObject" exclude="id"
add="yourEnumField">
<p:yourEnumField>
<t:label for="yourEnumField" />
<t:select secure="never" t:id="parent"
value="editYourObject.yourEnumField" model="yourObjectSelectModel" />
</p:yourEnumField>
</t:beaneditform>
If you are editing a saved thingy out of the database, the saved value
will be selected in the options with all others around it.
If you want your saved value to be at the top of the list, you'll have to
modify the "yourObjectSelectModel" by sorting it in the setupRender
phase. How you want to do that is up to you.
So slosh-head,
Cheers Engineers,
Hope that helps a bit
Chris
On Fri, 24 Oct 2014 08:04:52 +1100, Sloshed Techie
<sloshedtec...@gmail.com> wrote:
Hello,
Thanks. I had a look before it. Apparently, I can make it work with a
simple Enum.
Hope I didn't overlook but it doesn't talk about the scenario I'm talking
about.
Thanks!
Niks
On Thu, Oct 23, 2014 at 8:23 PM, George Christman
<gchrist...@cardaddy.com>
wrote:
Have you seen the following example?
http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Select.html
On Oct 23, 2014 2:10 PM, "Sloshed Techie" <sloshedtec...@gmail.com>
wrote:
> Hi,
>
> Good Afternoon!
>
> Thanks. Due to some constraints for using only Enum. can you please
> elaborate the step 1.
>
> It should be something like the values for select box should be
loaded as
> per the values defined in Enum but with the selected enum value(
which is
> stored in database), should be the default one for the select box.
>
> Thanks
> Niks!
>
> On Thu, Oct 23, 2014 at 5:38 PM, George Christman <
gchrist...@cardaddy.com
> >
> wrote:
>
> > 1. You can either put all your values in your enum and store the
string
> in
> > the database or 2. build a simple lookup table in the database
containing
> > your enum values and create a relationship with your primary table.
I
> would
> > recommend option 2. There would be no need for a value encoder then.
> >
> > It would look something like this.
> >
> > <t:select value="myObject.carType" t:model="carTypeModel"/>
> >
> > @PageActivationContext
> > @Property
> > private MyObject myObject;
> >
> > @Inject
> > private SelectModelFactory selectModelFactory;
> >
> > public void onPrepare() {
> > if(myObject == null) {
> > myObject = new MyObject();
> > }
> > }
> >
> > public void onSuccess() {
> > //save car object.
> > }
> >
> > public SelectModel getCarTypeModel() {
> > List<CarType> carTypes = your cartype query.
> > return selectModelFactory.create(carTypes , "name");
> > }
> >
> > @Entity
> > public class CarType {
> >
> > private String name;
> >
> > }
> >
> >
> > On Thu, Oct 23, 2014 at 6:52 AM, Thiago H de Paula Figueiredo <
> > thiag...@gmail.com> wrote:
> >
> > > On Thu, 23 Oct 2014 05:05:00 -0200, Chris Poulsen <
> > mailingl...@nesluop.dk>
> > > wrote:
> > >
> > > I don't know what you are trying to achieve, but you can always
> provide
> > >> your own select model, if you need something more flexible than
what
> the
> > >> standard coercions provide. (if that was the question?)
> > >>
> > >
> > > That's correct, but I guess a ValueEncoder implementation will be
> needed
> > > too. Either way, mixing different object classes in a Select
doesn't
> > sound
> > > right . . .
> > >
> > > --
> > > Thiago H. de Paula Figueiredo
> > > Tapestry, Java and Hibernate consultant and developer
> > > http://machina.com.br
> > >
> > >
---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> > > For additional commands, e-mail: users-h...@tapestry.apache.org
> > >
> > >
> >
> >
> > --
> > George Christman
> > www.CarDaddy.com
> > P.O. Box 735
> > Johnstown, New York
> >
>
--
Using Opera's mail client: http://www.opera.com/mail/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org