Re: Different root between upload folder and ContextRelativeResource

2012-12-28 Thread Martin Grigorov
Hi,

ContextRelativeResource looks for the resource in the web application
context, i.e. in the folders next to WEB-INF.
By using new File()/Folder() with relative path you create file relative to
the current working directory. In Eclipse this is the folder that contains
'src/' folder. When deployed this depends on the used web container. Use :
System.err.println(CWD:  + new java.io.File(.).toAbsolutePath()); to
see what it is exactly.

In the other thread I suggested you to use ByteArrayResource instead. See
http://wicketinaction.com/2011/07/wicket-1-5-mounting-resources/ for
example.


On Fri, Dec 28, 2012 at 1:16 AM, Delange delan...@telfort.nl wrote:

 I have an application which can upload pictures.
 When I use the upload with Jetty in my Eclipse directory it stores all
 pictures under
 eclipseproject
 /images
 /src/main/webapp/images

 But if i want to display them with ContextRelativeResource then they must
 be
 in /src/main/webapp/images

 Upload command is
 Folder uploadFolder = new Folder(opdrachten/+input.getOpdrachtnummer(),
 );

 for display i use
 String picture =
 opdrachten/+opdracht.getOpdrachtnummer()+/+file.getName();
 logger.info(picture);
 Image image2 = new Image(image2,new
 ContextRelativeResource(picture));
 What is wrong?




 --
 View this message in context:
 http://apache-wicket.1842946.n4.nabble.com/Different-root-between-upload-folder-and-ContextRelativeResource-tp4655089.html
 Sent from the Users forum mailing list archive at Nabble.com.

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




-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com http://jweekend.com/


Issue while adding Custom Validator to ListMultipleChoice component

2012-12-28 Thread wicket_new_user
Hi,
is it possible to add Custom Validator (implenting IValidatorT) for
ListMultipleChoice component?

when i'm trying to add validator to the the componnent using the below code, 

final ListMultipleChoiceAttribute selectedFields = new
ListMultipleChoiceAttribute(selected,
new ListModelAttribute(new ArrayListAttribute()),
availableAttributesModel,
FIELD_RENDERER);

selectedFields.setOutputMarkupId(true);
s*electedFields.add(new SelectedAttributesValidator());*

i'm seeing the below compilation error for the above statement
*The method add(IValidator? super CollectionAttribute) in the type
FormComponentCollectionlt;Attribute is not applicable for the arguments
(SelectedAttributesValidator)*


Following is the Validator Class
=
public class SelectedAttributesValidator implements
IValidatorListMultipleChoicelt;Attribute
{

/**
 * 
 */
private static final long serialVersionUID = 1L;

/**
 * 
 */
public void validate(IValidatableListMultipleChoicelt;Attribute
validatable)
{
final ListMultipleChoiceAttribute selectedFields =
validatable.getValue();

if (CollectionUtils.isEmpty(selectedFields.getChoices()))
{
validatable.error(new
ValidationError().addMessageKey(attributesMustBeSelected));
}

}

}

the reason i'm going for Custom Validator is as i'm unable to get the value
from the getConvertedInput() as it is showing always empty, when the form
is loaded with default values. Not able to understand what could be the
problem.


can one please let me know, if there is any issue in the above code?

Thanks




--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Issue-while-adding-Custom-Validator-to-ListMultipleChoice-component-tp4655091.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: Issue while adding Custom Validator to ListMultipleChoice component

2012-12-28 Thread Sven Meier

The generic type of your validator should be:

  public class SelectedAttributesValidator implements 
IValidatorCollectionAttribute


Sven

On 12/28/2012 09:41 AM, wicket_new_user wrote:

Hi,
is it possible to add Custom Validator (implenting IValidatorT) for
ListMultipleChoice component?

when i'm trying to add validator to the the componnent using the below code,

final ListMultipleChoiceAttribute selectedFields = new
ListMultipleChoiceAttribute(selected,
 new ListModelAttribute(new ArrayListAttribute()),
availableAttributesModel,
 FIELD_RENDERER);

selectedFields.setOutputMarkupId(true);
s*electedFields.add(new SelectedAttributesValidator());*

i'm seeing the below compilation error for the above statement
*The method add(IValidator? super CollectionAttribute) in the type
FormComponentCollectionlt;Attribute is not applicable for the arguments
(SelectedAttributesValidator)*


Following is the Validator Class
=
public class SelectedAttributesValidator implements
IValidatorListMultipleChoicelt;Attribute
{

 /**
  *
  */
 private static final long serialVersionUID = 1L;

 /**
  *
  */
 public void validate(IValidatableListMultipleChoicelt;Attribute
validatable)
 {
 final ListMultipleChoiceAttribute selectedFields =
validatable.getValue();

 if (CollectionUtils.isEmpty(selectedFields.getChoices()))
 {
 validatable.error(new
ValidationError().addMessageKey(attributesMustBeSelected));
 }

 }

}

the reason i'm going for Custom Validator is as i'm unable to get the value
from the getConvertedInput() as it is showing always empty, when the form
is loaded with default values. Not able to understand what could be the
problem.


can one please let me know, if there is any issue in the above code?

Thanks




--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Issue-while-adding-Custom-Validator-to-ListMultipleChoice-component-tp4655091.html
Sent from the Users forum mailing list archive at Nabble.com.

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




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



Re: Wicket integration with Spring

2012-12-28 Thread Per Newgro
With the 2nd approach you couple the application (in the role as service 
mother) to all your calling components.
Coupling is a bad idea. It's hard to test in separation and almost 
always you end in a hell of small single methods.
But if you inject your beans into the target component you can define 
your required dependeny there were you use them.
Another cool approach in wicket is the event system in 1.5+. So you 
throw events in child components and provide the

services in high ranking components (page, app ...)

Just my 2 ct.

Per

Am 27.12.2012 11:11, schrieb Arun Chauhan:

I am making an application in which I want to integrate Wicket + Spring.
Application is a grocery store on which user comes and buy something. I know
there are two ways to do this.

1. Using the *annotation *aprroach. Wicket-Spring integration shows various
ways on how to inject Spring   Beans into Wicket pages.

public class FormPage extends WebPage
{
   @SpringBean
   private IContact icontact;
   ...
   Form form = new Form(contactForm,
  new CompoundPropertyModel(contact))
   {
 private static final long serialVersionUID = 1L;

 protected void onSubmit(Contact contact)
 {
   icontact.saveContact(contact);
 }
   };


2. The @SpringBean is of course valid and considered a best practice by
many. But there is also *another approach*, where your Wicket Application
has the services you need.

public class YourWicketApp extends WebApplication{
   public static YourWicketApp get(){
 return (YourWicketApp) Application.get();
   }
   private ServiceA serviceA;
   // getter and setter for serviceA here
}

Now in your component, call

YourWicketApp.get().getServiceA();



I want to know which is the best way to integrate spring with wicket.


/However as far as I remember Wicket pages and components aren't managed by
Spring container so you cannot use @Transactional annotation on them (which
is a bad idea anyway - transactions belong to deeper levels)./ *Is this
statement valid?*



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Wicket-integration-with-Spring-tp4655077.html
Sent from the Users forum mailing list archive at Nabble.com.

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





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



Re: CSS load order in 6.x

2012-12-28 Thread vp143
Many thanks for your help.

This is what I have done:

public class YUICalendarCssResourceReference extends CssResourceReference {
private static final long serialVersionUID = 1L;

public YUICalendarCssResourceReference() {
super(YUICalendarCssResourceReference.class, yui.css);
}

public Iterable? extends HeaderItem getDependencies() {
ListHeaderItem dependencies = new ArrayListHeaderItem(); 
dependencies.add(CssHeaderItem.forReference(new
CssResourceReference(YuiLib.class,
calendar/assets/skins/sam/calendar.css)));
 
return dependencies;
}
}

And then in my page:
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response); 
response.render(CssHeaderItem.forReference(APP_CSS)); //my css 
file 
response.render(CssHeaderItem.forReference(new
YUICalendarCssResourceReference()));
}

Where yui.css is my custom css
Firstly is the above correct?

The result is that in the source the .css files appear correctly.
However, visually it does not work. Looking at Firebug I have the following
css files loaded:
1) app-ver-.css
2)
wicket/resource/org.apache.wicket.extensions.yui.YuiLib/calendar/assets/skins/sam/calendar-ver-1356690284000.css
3) yui-ver-.css
4)
wicket/resource/org.apache.wicket.extensions.yui.YuiLib/calendar/assets/skins/sam/calendar.css

My understanding is that the 4th css file should not be loaded there.



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/CSS-load-order-in-6-x-tp4654942p4655095.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: CSS load order in 6.x

2012-12-28 Thread Martin Grigorov
Hi,

I also  think that 4) should not be loaded at all.
I guess that YUI itself loads it. YUI supports its own dependency
management.
Check what is rendered by Wicket in the HTML.


On Fri, Dec 28, 2012 at 1:20 PM, vp143 vishal.po...@cipriati.co.uk wrote:

 Many thanks for your help.

 This is what I have done:

 public class YUICalendarCssResourceReference extends CssResourceReference {
 private static final long serialVersionUID = 1L;

 public YUICalendarCssResourceReference() {
 super(YUICalendarCssResourceReference.class, yui.css);
 }

 public Iterable? extends HeaderItem getDependencies() {
 ListHeaderItem dependencies = new
 ArrayListHeaderItem();
 dependencies.add(CssHeaderItem.forReference(new
 CssResourceReference(YuiLib.class,
 calendar/assets/skins/sam/calendar.css)));

 return dependencies;
 }
 }

 And then in my page:
 @Override
 public void renderHead(IHeaderResponse response) {
 super.renderHead(response);
 response.render(CssHeaderItem.forReference(APP_CSS)); //my
 css file
 response.render(CssHeaderItem.forReference(new
 YUICalendarCssResourceReference()));
 }

 Where yui.css is my custom css
 Firstly is the above correct?

 The result is that in the source the .css files appear correctly.
 However, visually it does not work. Looking at Firebug I have the following
 css files loaded:
 1) app-ver-.css
 2)

 wicket/resource/org.apache.wicket.extensions.yui.YuiLib/calendar/assets/skins/sam/calendar-ver-1356690284000.css
 3) yui-ver-.css
 4)

 wicket/resource/org.apache.wicket.extensions.yui.YuiLib/calendar/assets/skins/sam/calendar.css

 My understanding is that the 4th css file should not be loaded there.



 --
 View this message in context:
 http://apache-wicket.1842946.n4.nabble.com/CSS-load-order-in-6-x-tp4654942p4655095.html
 Sent from the Users forum mailing list archive at Nabble.com.

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




-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com http://jweekend.com/


Re: CSS load order in 6.x

2012-12-28 Thread vp143
The HTML source appears correctly to me:

link rel=stylesheet type=text/css
href=../../../../wicket/resource/web.pages.BasePage/::/::/::/css/app-ver-1356687988000.css
/
link rel=stylesheet type=text/css
href=../../../../wicket/resource/org.apache.wicket.extensions.yui.YuiLib/calendar/assets/skins/sam/calendar-ver-1356690284000.css
/
link rel=stylesheet type=text/css
href=../../../../wicket/resource/web.wicket.extensions.YUICalendarCssResourceReference/yui-ver-1356640705000.css
/

It is a bit strange that there is no reference to 4) at all in the source
but Firebug loads it.



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/CSS-load-order-in-6-x-tp4654942p4655097.html
Sent from the Users forum mailing list archive at Nabble.com.

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



Re: CSS load order in 6.x

2012-12-28 Thread Martin Grigorov
Read about YUILoader : http://developer.yahoo.com/yui/yuiloader/
Some .js file uses it to load 4) dynamically.


On Fri, Dec 28, 2012 at 4:12 PM, vp143 vishal.po...@cipriati.co.uk wrote:

 The HTML source appears correctly to me:

 link rel=stylesheet type=text/css

 href=../../../../wicket/resource/web.pages.BasePage/::/::/::/css/app-ver-1356687988000.css
 /
 link rel=stylesheet type=text/css

 href=../../../../wicket/resource/org.apache.wicket.extensions.yui.YuiLib/calendar/assets/skins/sam/calendar-ver-1356690284000.css
 /
 link rel=stylesheet type=text/css

 href=../../../../wicket/resource/web.wicket.extensions.YUICalendarCssResourceReference/yui-ver-1356640705000.css
 /

 It is a bit strange that there is no reference to 4) at all in the source
 but Firebug loads it.



 --
 View this message in context:
 http://apache-wicket.1842946.n4.nabble.com/CSS-load-order-in-6-x-tp4654942p4655097.html
 Sent from the Users forum mailing list archive at Nabble.com.

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




-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com http://jweekend.com/


Re: Create/Edit domain object data

2012-12-28 Thread Bas Gooren

Nick,

I'm not sure if anyone responded, so let me share how we deal with this.

Since a JPA entity can reference other (persistent entities), and 
usually does, we've tried to never, ever, serialize JPA entities. The 
only time where it's needed is when you have an entity creation 
workflow which spans more than a single screen.


For the cases where an entity is created using a single screen, we 
simply write a LDM which creates a new instance, setting defaults. 
Wicket then pushes all form fields to the entity on submit, and as a 
result we have an entity we can persist.


Other possible strategies:
- serialize the new entity inside a normal model (Model)
- pre-create new entities, and have a flag on them which indicates their 
workflow state (NEW, ACTIVE etc); that way you can simply load them 
through whatever EntityDatabaseModel you have in place


Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 7-12-2012 19:14, schreef Nick Pratt:

Im looking for recommendations on how to work with Form data and a
JPA/Hibernate model, specifically around creating and editing domain data.

I have a JPA backed domain model, and I want to create a page/panel/form
that allows entry of a new Foo, as well as being able to pass an existing
LDMFoo to the Page/Panel so that I can edit it.

Obviously I'd like to use an IModel for the domain object so that I dont
end up serializing the DB in to the session, but at the same time, I cant
use an LDM until the new entity is saved and an ID is assigned to the
object.

For the 'new' case, do you just serialize the domain entity in to the
session, IModelFoo model = Model.of( new Foo() ); and let the Foo object
be serialized until such time as the Foo.id is set so you can switch out
the IModel ref to an LDM? Or is it best to just show the minimal number of
fields required (*) to create a new Foo (accessed via PropertyModel(this,
attributeName), save it, and then set the LDMFoo reference in the page
and then let the other form elements be shown? (This approach duplicates
code - the fields in the domain object are duplicated as primitives in the
Page (which get serialized in to the session) )

The edit functionality needs to allow all fields to be edited (including
the fields mentioned in (*) above) - I dont want to duplicate form markup
and code - once for the 'new' case and once for the 'edit' case - the
'edit' case would have a lot more fields that could be entered/edited.

Are there other approaches that I'm missing, and what is the best pattern
to follow here?





Re: Issue while adding Custom Validator to ListMultipleChoice component

2012-12-28 Thread Sven Meier

Hi,

This is getting empty when it is loaded with default values.

You mean you have values in your model but they don't show up on a 
re-submit?


Please take a look at ListMultipleChoicePage in wicket-examples. If I 
add a validator there, everything works as expected:


listChoice.add(new IValidatorCollectionString()
{
@Override
public void validate(IValidatableCollectionString 
validatable)

{
CollectionString value = validatable.getValue();
// value is filled with the now selected choices
}
});

Check what's different to your usage.

Sven

On 12/28/2012 11:10 AM, wicket_new_user wrote:

thanks Sven for your reply. the syntax issue worked.

But i'm, getting another probelm is

final CollectionAttribute selectedFields = validatable.getValue();

This is getting empty when it is loaded with default values. Not sure if i'm
missing anything to add here.



Able to get the values only when the values or added to the list (i.e, the
component gets modified)



Also, I have observed that, in onSubmit(), the updateModel() iof
ListMultipleChoice() s getting called to set the actual property values, and
so the values are being displayed in in on submit when storing them in
domain objects :-(.
But it is not the case in Validating it :-(

Thanks
WN







--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Issue-while-adding-Custom-Validator-to-ListMultipleChoice-component-tp4655091p4655093.html
Sent from the Users forum mailing list archive at Nabble.com.

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




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