Component with ListView that adds other Components?

2011-08-03 Thread Gary Thomas

Stumped on this, seemed it should simple:

I am making a component that uses a ListView.
Two important requirements:

1) This component will add Components and other markup before the list 
items, which I do not want the page designer or Java coder to worry 
about adding themselves in markup or code.


2) I want the page designer to be able to specify the markup that will 
be repeated for list items, just like a ListView:




Blah blah blah




So this Component's usage would look like this:


   
  Blah blah blah
   


Which would generate this (fake markup example):


  My Important Stuff
  Yadda
  
 ...
  

  
  Blah blah blah
  
  
  Blah blah blah
  
  
  Blah blah blah
  
  ...



I was going to use a panel, but realized I have no idea how to "grab" 
markup to use within the ListView.


Help?


Thanks,
G

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Scala DSL for Wicket

2011-07-31 Thread Gary Thomas


I've written some Scala utilities as well, but instead of a DSL I'm 
using implicit conversions via traits, which I've found to be a really 
nice fit with Wicket.


An example:

import org.apache.wicket.model.IModel
import org.apache.wicket.model.LoadableDetachableModel
import org.apache.wicket.model.PropertyModel

trait WicketConversions {
   // transparent PropertyModel conversion
implicit def tuple2model[T](tuple: (AnyRef, String)): 
PropertyModel[T] = {

new PropertyModel[T](tuple._1, tuple._2)
}

// transparent function/closure to LoadableDetachableModel conversion
implicit def function2model[T](f: => T): IModel[T] = {
new LoadableDetachableModel[T] {
def load: T = f
}
}
}

Usage:

class MyPanel extends Panel("id") with WicketConversions {

// transparent PropertyModel conversion using article.rating):
add(new RatingPanel("rating", article -> "rating") // so pretty

// transparent LoadableDetachableModel conversion (expects 
IModel[Boolean]):

add(new AjaxCheckBox("selected", { dao.get(id).isAdmin }) {
def onUpdate(target: AjaxRequestTarget) { ... }
})
}


I have more code as well for Spring integration, etc.
If anyone is interested, I could add mine to this or to a new GitHub 
project.



Thanks,
Gary


On 7/29/11 5:22 PM, Ben Tilford wrote:

For LDM

class Ldm[T](provider:()=>  T) extends LoadableDetachable... {
   def load():T {
 provider()
   }
}

object Ldm {
   def apply(provider:()=>T) = new Ldm[T](provider)
}

could be used as

...
val id = 1
val model = Ldm(()=>{dao.get(id)})

or

val id = 1
def provider = dao.get(id)
val model = Ldm(provider)


On Fri, Jul 29, 2011 at 6:44 AM, Martin Grigorovwrote:


Bruno,

Yet another idea for the dsl:

def ldm[R, ID](id: ID = null, f: (ID) =>  R) = {new
LoadableDetachableModel(id) { override def load() : R = { f(id); } } }

P.S. Not tested.

On Thu, Jul 28, 2011 at 9:07 AM, Bruno Borges
wrote:

Just wanted to share my experience playing a little more with Scala and
Wicket>  A few minutes ago I got this excelent code:

I know it is too simple, and it can be accomplished as well in Java with
static imports. But still, for my project it's being great (and cool) to

do

such things.

 object btnEditar extends Button("btnEditar") {
   override def onSubmit() = {
-/* show fields */
-camposForm.setVisibilityAllowed(true)
-btnSalvar.setVisibilityAllowed(true)
-cancelar.setVisibilityAllowed(true)
-
-/* hide them */
-camposTela.setVisibilityAllowed(false)
-btnEditar.setVisibilityAllowed(false)
+show(camposForm, btnSalvar, cancelar)
+hide(camposTela, btnEditar)
   }
 }
 add(btnEditar)

Methods show/hide are imported as "import code.DSLWicket._"



*Bruno Borges*
www.brunoborges.com.br
+55 21 76727099



On Wed, Jul 27, 2011 at 4:53 PM, Bruno Borges
Thanks Martin,

There was only a small little problem in your code. The correct syntax

is:


def label[T](id: String, model: IModel[T] = null): Label = { val label
= new Label(id, model); add(label); label }

The suggestions were updated on Gist.

*Bruno Borges*
www.brunoborges.com.br
+55 21 76727099



On Wed, Jul 27, 2011 at 3:55 PM, Martin Grigorov
wrote:



Idea for simplification: use named parameters.
For example
def label[T](id: String, model: IModel[T]): Label = { val label = new
Label(id, model); add(label); label }
would become
def label[T](id: String, model = _ : IModel[T]): Label = { val label =
new Label(id, model); add(label); label }

this way you'll have just one declaration of label function which will
handle the current three

additionally you may add a pimp:
implicit def ser2model[S :<  Serializable](ser: S): IModel[S] =
Model.of(ser)

now even when you pass String as second param to label() it will be
converted to IModel

On Wed, Jul 27, 2011 at 9:11 PM, Martin Grigorov


wrote:

Take a look at scala.swing.* sources.

On Wed, Jul 27, 2011 at 8:34 PM, Bruno Borges<

bruno.bor...@gmail.com>

wrote:

Can some Scala expert help me to make this DSL available as PML

(pimp

my

library)?

I've tried to code it that way but things didn't quite worked out

the

way

they should.

The reason is that for every Wicket object I create, I must extend

the

trait

DSLWicket



*Bruno Borges*
www.brunoborges.com.br
+55 21 76727099



On Wed, Jul 27, 2011 at 2:30 PM, Bruno Borges<

bruno.bor...@gmail.com

wrote:



Not really.

The method onSubmit() of button is void, as well onClick(), so

there's

no

need for the function be passed as () =>  Unit or anything else.

I made a few changes to it and updated on Gist.

I've also uploaded a page that uses this DSL at
https://gist.github.com/1109919

Take a look

*Bruno Borges*
www.brunoborges.com.br
+55 21 76727099



On Wed, Jul 27, 2011 at 2:22 PM, Scott Swank<

scott.sw...@gmail.com

wrote:



I think you do want Unit, which as I understand it is closest
equivalent to "void" in Scala.

htt

Re: [VOTE] WICKET-3218 - Component#onInitialize is broken for Pages

2011-03-09 Thread Gary Thomas

On 3/9/11 2:18 AM, Maarten Billemont wrote:

On 09 Mar 2011, at 10:44, Gary Thomas wrote:


While a minority use-case, this allows for very elegant Wicket code when using 
Scala:

add(new Form[Person]("form", model) {
add (new TextArea[String]("text", (getModel ->  "text")) {
override def isVisible: Boolean = false
})
})


Style is great when there are no issues involved with doing it.  If it turns 
out that adding components from the constructor is indeed dangerous when 
combined with other components (eg. in libraries) that use onInitialize then we 
should reconsider.

I think the best solution so far would be to not invoke onInitialize when 
adding components to a page, that would allow the constructor to be used still 
if the developer really wants to.

With regards to your Scala code, while I don't know any Scala whatsoever, 
wouldn't it be just as easy to do something like this:

add(new Form[Person]("form", model) {
override def onInitialize: add (new TextArea[String]("text", (getModel ->  
"text")) {
override def isVisible: Boolean = false
})
})



Thanks for the reply -
Yes it would be as simple as that - but again, not quite as elegant (imho).

I admit my argument is pretty minor, but elegant code is a hallmark of 
an API or library that is designed well, and I think Wicket is great in 
that regard.


Scala aside, the current usage of add() from the constructor "just makes 
sense" to me, since you really are "constructing" the component.  Fully 
understood there are valid concerns about the side effects of this 
design, but would love to see that resolved transparently if at all 
possible.


I'm not an expert on the internals, but am a very happy user of Wicket :-)

Thanks,
Gary

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: [VOTE] WICKET-3218 - Component#onInitialize is broken for Pages

2011-03-09 Thread Gary Thomas

On 3/8/11 12:33 PM, Martijn Dashorst wrote:

On Tue, Mar 8, 2011 at 6:03 PM, GOODWIN, MATTHEW (ATTCORP)
  wrote:

+1 for clear documentation/Javadoc explaining proper use of
onInitialize.

Does this exist somewhere? As someone new to Wicket I'm trying to learn
as fast as I can and a lot of examples (almost exclusively) I see out
there show the add(..) from within the constructor - which is apparently
an anti-pattern from the sound of this thread.


It is most certainly not an antipattern in my book. I find the
reaction of the anti-constructor folks too strong and am trying to
formulate a civil reaction to this whole anti constructor rant.

Martijn



*Please* don't deprecate add() from constructor.

While a minority use-case, this allows for very elegant Wicket code when 
using Scala:


add(new Form[Person]("form", model) {
add (new TextArea[String]("text", (getModel -> "text")) {
override def isVisible: Boolean = false
})
})

etc.


Since the body of a class is the constructor in Scala, this is a perfect 
fit for closure-like structures when using Wicket.


Thanks,
Gary

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Wicket + Scala + Spring

2010-01-03 Thread Gary Thomas
P.S. though one slight difficulty I've run into is the need to translate 
between Scala and Java collections.
Perfectly doable, and not a Wicket problem, but takes a way some of the 
elegance of coding purely in Scala.


Happy to hear if anyone has tips on elegant ways of dealing with this.


On 1/3/10 4:38 PM, Gary Thomas wrote:
Same here - not much more to say other than after 10 years of working 
with Java webapps,
learning both Wicket and Scala have made the past 6 months very 
enjoyable.


Immediately before trying Wicket, I was a die-hard Struts/Spring MVC 
user and didn't know what I was missing.  Scala+Wicket is a nice mix.


Best,
g


On 1/3/10 11:24 AM, Giovanni wrote:
I'm developing two new applications (a webapp + a standalone) using 
Scala + Spring + Wicket 1.4.5 (webapp) + H2 database.


The development is nice and interesting.

Wicket is working with Scala very well.

If someone else has a similar experience, please share it.

Best regards
giovanni








-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Wicket + Scala + Spring

2010-01-03 Thread Gary Thomas
Same here - not much more to say other than after 10 years of working 
with Java webapps,

learning both Wicket and Scala have made the past 6 months very enjoyable.

Immediately before trying Wicket, I was a die-hard Struts/Spring MVC 
user and didn't know what I was missing.  Scala+Wicket is a nice mix.


Best,
g


On 1/3/10 11:24 AM, Giovanni wrote:

I'm developing two new applications (a webapp + a standalone) using Scala + 
Spring + Wicket 1.4.5 (webapp) + H2 database.

The development is nice and interesting.

Wicket is working with Scala very well.

If someone else has a similar experience, please share it.

Best regards
giovanni



   



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Groovy 1.7 released with ...

2009-12-24 Thread Gary Thomas

Cool, thanks for the info.
Is anyone have any luck building a Groovy+Wicket project with Maven?

Would love to try it out, but not having much luck with various gmaven 
plugin settings.  Stub generation does not seem to work with AIC.


Thanks,
G

On 12/22/09 7:47 AM, Ashley Aitken wrote:


Hi All,

FYI.

Groovy 1.7 has just been released with support for Anonymous Inner
Classes and Nested Classes (as well as other new features and
enhancements).

For those interested in using Groovy with Wicket this should make things
doable now and perhaps simpler than regular Java.



Cheers,
Ashley.

--
Ashley Aitken
Perth, Western Australia
mrhatken at mac dot com
Skype Name: MrHatken (GMT + 8 Hours!)


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org