Re: RadioChoice keeps null rawInput after required validation?

2011-02-03 Thread Xavier López
Just in case it helps someone else, we've finally managed to understand why
we needed to call clearInput() on rc1 after changing its model object, with
help from this previous post
http://apache-wicket.1842946.n4.nabble.com/Ajax-and-form-handling-and-clearInput-td1866836.html(thanks
Alexander, Igor)

1. When selecting 'no' and submitting the form without providing a value to
rc1, the required validation prevents form submission. An empty string
remains as rc1's rawinput as that's the last user inputted value.
2. When selecting 'yes', an ajax updating behavior fires on the yes/no
radiochoice. Rc1's rawInput remains empty.
3. In the behavior's onUpdate(), we set rc1's model object by means of only
modifying the backing entity (it had a propertymodel). This is the key
point, we weren't aware that rc1#setModelObject() would clear input
automatically by calling modelChanged().
4. At render time, rc1#getValue() got the empty input that the last form
submission left, and using that one to set the selected option.

Oh, my, I've been thinking this whole time that setModelObject() was
equivalent to doing getModel().setObject(). Have to say maybe fooled by
setModelObject()'s javadoc 'Sets the backing model object; shorthand for
getModel().setObject(object).'

Cheers,
Xavier

2011/1/26 Igor Vaynberg igor.vaynb...@gmail.com

 clearinput() is a good way to deal with it, but the component should
 still set no_raw_input if it is submitted in a disabled state. please
 file a jira issue, preferably with a quickstart.

 -igor

 On Wed, Jan 26, 2011 at 3:05 AM, Xavier López xavil...@gmail.com wrote:
  Hi,
 
  I've got a form with a required radiochoice to select among some options.
  I've also got a yes/no radiochoice that selects a given option on rc1 and
  disables it when 'yes' is selected. When 'no' is selected, rc1 is set to
  enabled and its model object is cleared.
 
  The enabling/disabling of rc1 and its modelobject set is done in the
  onUpdate() method of an AjaxFormChoiceComponentUpdatingBehavior on the
  yes/no radiochoice.
 
  It's working fine, except in the following situation: 'no' is selected
 and
  rc1 has no value set. Then the required validation prevents the form
  submission. After that, if I select 'yes' on the yes/no radiochoice, it
  enables rc1 and sets its model object successfully, but, to my surprise,
 the
  input type=radio has no value selected when rendering the HTML.
 
  After debbuging through rc1#onComponentTagBody(), I've found that
 getValue()
  returns null, because rawInput is null (and not NO_RAW_INPUT), that's why
  there's no radio selected. I suspect rawInput is null because of last
  submitting rc1 with no value selected (when the required validation
 fails).
  I managed to get around this by calling rc1.clearInput() on the ajax
  behavior.
 
  Just want to know if i'm right about these thoughts, because I feel
  something wrong here, and if calling clearInput() is a good way of
 dealing
  with this.
 
  Thank you for your feedback!
  Xavier
 

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




Re: RadioChoice keeps null rawInput after required validation?

2011-02-03 Thread Xavier López
2011/2/3 Xavier López xavil...@gmail.com

 Have to say maybe fooled by setModelObject()'s javadoc 'Sets the backing
 model object; shorthand for getModel().setObject(object).'


My fault, didn't see this has already been addressed on
https://issues.apache.org/jira/browse/WICKET-2113 , and is specific of 1.3.

Cheers,
Xavier


Calculate property value on form submission

2011-01-26 Thread Xavier López
Hi,

I've got a form with some fields, backed by an entity with a cpm. I've got
one property on the entity which value is calculated in terms of one of the
input fields in the form. It's important to have this field calculated up to
date at form validation time.
I tipically approached this issue by using an
ajaxformcomponentupdatingbehavior to update the entity's calculated field on
every change. Now i'm allowing non-js users into the site, and have mimed
this action with a submit button. But, of course, the user might not press
the button and go straight away without pre-calculating the value
server-side.
I've been thinking about binding a propertymodel to that calculated
property, and somehow make it work like a model, so that its getObject will
calculate the value, and thus have the value calculated before executing the
form validator.
Could you please provide any hint on how tho achieve this, if it is
possible?

Thank you very much!
Xavier


RadioChoice keeps null rawInput after required validation?

2011-01-26 Thread Xavier López
Hi,

I've got a form with a required radiochoice to select among some options.
I've also got a yes/no radiochoice that selects a given option on rc1 and
disables it when 'yes' is selected. When 'no' is selected, rc1 is set to
enabled and its model object is cleared.

The enabling/disabling of rc1 and its modelobject set is done in the
onUpdate() method of an AjaxFormChoiceComponentUpdatingBehavior on the
yes/no radiochoice.

It's working fine, except in the following situation: 'no' is selected and
rc1 has no value set. Then the required validation prevents the form
submission. After that, if I select 'yes' on the yes/no radiochoice, it
enables rc1 and sets its model object successfully, but, to my surprise, the
input type=radio has no value selected when rendering the HTML.

After debbuging through rc1#onComponentTagBody(), I've found that getValue()
returns null, because rawInput is null (and not NO_RAW_INPUT), that's why
there's no radio selected. I suspect rawInput is null because of last
submitting rc1 with no value selected (when the required validation fails).
I managed to get around this by calling rc1.clearInput() on the ajax
behavior.

Just want to know if i'm right about these thoughts, because I feel
something wrong here, and if calling clearInput() is a good way of dealing
with this.

Thank you for your feedback!
Xavier


Re: checkGroup - 2 out of 5?

2010-09-07 Thread Xavier López
I'd do it with a component validator. That would avoid the Form's onSubmit
being called and getting the model updated with incorrect user data. Or also
with a FormValidator. If I remember correctly, you can call
getConvertedInput to get the Checkgroup's list of selected values.

Cheers,
Xavi

2010/9/7 nino martinez wael nino.martinez.w...@gmail.com

 you an also do it server side... just check your model on submit etc..

 2010/9/6 Zeldor pgronkiew...@gmail.com

 
  Oh, I hoped that it can be avoided. So anyone has AJAX example at hand?
  --
  View this message in context:
 
 http://apache-wicket.1842946.n4.nabble.com/checkGroup-2-out-of-5-tp2527723p2527763.html
  Sent from the Wicket - User 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: checkGroup - 2 out of 5?

2010-09-07 Thread Xavier López
To switch the last check with the first checked in case there are two of
them checked already, you could also use an
AjaxFormComponentUpdatingBehavior to do it server-side, though that would
only be disadvantages. I remember some nasty issues with the onchange event
on checkboxes with IE, and the server-side ajax would be just doing dom
attribute manipulations. You'll be much better off doing it with JS, as Igor
stated.

Cheers,
Xavi

2010/9/7 nino martinez wael nino.martinez.w...@gmail.com

 yup validator's more correct

 2010/9/7 Xavier López xavil...@gmail.com

  I'd do it with a component validator. That would avoid the Form's
 onSubmit
  being called and getting the model updated with incorrect user data. Or
  also
  with a FormValidator. If I remember correctly, you can call
  getConvertedInput to get the Checkgroup's list of selected values.
 
  Cheers,
  Xavi
 
  2010/9/7 nino martinez wael nino.martinez.w...@gmail.com
 
   you an also do it server side... just check your model on submit etc..
  
   2010/9/6 Zeldor pgronkiew...@gmail.com
  
   
Oh, I hoped that it can be avoided. So anyone has AJAX example at
 hand?
--
View this message in context:
   
  
 
 http://apache-wicket.1842946.n4.nabble.com/checkGroup-2-out-of-5-tp2527723p2527763.html
Sent from the Wicket - User 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
   
   
  
 




-- 
Klein bottle for rent--inquire within.


Re: Show/hide form components best practice

2010-06-17 Thread Xavier López
Please correct me if I'm wrong, but, once the component's validators have
been passed, and when executing, for instance a FormValidator, you can get
the converted input of the Checkbox. Then choose to use or not the input of
the conditional field. Of course that prevents you from using setRequired on
that field, because it would be executed as a Component Validator before the
Form one.

Hope that helps,
Xavier

2010/6/16 Iain Reddick iain.redd...@beatsystems.com

 I looked at this again today and realised that my examples are basically
 broken (also typos in the last one :) ).

 Obviously, you can't use the converted input of a FormComponent before
 validation has happened. This means that using the CheckBox converted input
 to determine whether another form component is used in the submission is
 wrong - it will only return the value it held before the submit. You would
 actually have to look at the raw input.

 So I'm back at square one with this again.

 I suppose my question is Is component visibility the only means of
 determining whether a form component should be considered in the form submit
 mechanism?.

 - Original Message -
 From: Iain Reddick iain.redd...@beatsystems.com
 To: users@wicket.apache.org
 Sent: Wednesday, 9 June, 2010 8:35:13 PM
 Subject: Re: Show/hide form components best practice

 Looking at the wicket source regarding this, I don't think it's possible
 to get the desired behaviour.

 It looks like a new hook is needed in FormComponent.validate() that is
 called before any of the other logic.

 Something like FormComponent.isUsed(). If this returns false, just exit
 the validate() methods.

 Default FormComponent implementation would return true for this method,
 but it can be overriden to provide the desired behaviour.

 As I understand the submit/validate/bind sequence, this would mean that
 the form component's raw input is updated (which makes sense), but
 validation/model object doesn't happen.

 Is this feasible, and would it impact elsewhere?


 Here's an update of my previous example showing how it would be used:

 private class TestForm extends Form {

 private String always;
 private boolean useOptional = false;
 private String optional;

 public TestForm(String id) {
 super(id);

 add( new TextField(always, new PropertyModel(this,
 always)).setRequired(true) );
 final CheckBox useOptionalCheck = new CheckBox( useOptional, new
 PropertyModel(this, useOptional) );
 add( useOptionalCheck );
 add( new TextField(optional, new PropertyModel(this, optional)) {
 @Override public boolean isUsed() {
 return ((Boolean)useOptionalCheck.getConvertedInput()).booleanValue();
 }

 @Override
 public boolean isRequired() {
 isUsed(); }
 }.add(MinimumLengthValidator.minimumLength(3)) );
 }

 }


 - Original Message -
 From: Xavier López xavil...@gmail.com
 To: users@wicket.apache.org
 Sent: Thursday, 3 June, 2010 2:56:33 PM
 Subject: Re: Show/hide form components best practice

 I'm with you on this one, this code feels like doing something that it
 shouldn't, looks kind of bloated for such a simple and common
 requirement. Maybe we need some stuffing of nice, pre-canned
 FormValidators ? :)

 The problem with wicket's validators, as I see it, is that they are at a
 Component level. They do their job based on that component's
 input/state, only. In fact, they are called in Form's
 validateComponents() one by one in
 a traversal. If another component's input or state is required to
 perform the validation, i'd do it inside a FormValidator. That copes
 with your
 requirement of ignore the input for this component completely,
 although I
 don't know how would that be achieved.

 Of course, in all those comments, I assume you can not rely on
 javascript nor ajax to perform those validations, in which case the
 visibility approach
 simply couldn't work.

 Cheers,
 Xavier

 2010/6/3 Iain Reddick iain.redd...@beatsystems.com

  The problem with this approach is that you throw away all the nice,
  re-usable pre-canned validators that wicket has, and that it seems
  very wrong.
 
  I'd actually push the behaviour I would like to see even further - in
  the example I gave, I don't even want the optional field to update
  it's model
  when the check box isn't selected.
 
  Effectively, I want to be able to specify logic which says ignore the
  input for this component completely. Currently, the only way to do
  this is
  by using component visibility (unless I'm completely wrong on this).
 
  Xavier López wrote:
 
  Hi Iain,
 
  I would do it like this, with a FormValidator. I moved the minimum
  length validation also to the formValidator, because doing it with a
  MinimumLenghtValidator would trigger it before the formValidator
  executes, and may raise errors when the input is not valid (i.e. not
  mandatory) :
 
  private class TestForm extends Form {
 
  IModel modelAlways;
  IModel modelCheckOptional;
  IModel modelOptional;
 
   public TestForm(String id) {
super(id

Re: Show/hide form components best practice

2010-06-03 Thread Xavier López
Hi Iain,

I would do it like this, with a FormValidator. I moved the minimum length
validation also to the formValidator, because doing it with a
MinimumLenghtValidator would trigger it before the formValidator executes,
and may raise errors when the input is not valid (i.e. not mandatory) :

private class TestForm extends Form {

IModel modelAlways;
IModel modelCheckOptional;
IModel modelOptional;

 public TestForm(String id) {
   super(id);

   modelAlways =  new Model();
   modelCheckOptional = Boolean.FALSE;
   modelOptional = new Model();
   final TextField alwaysTextfield = new TextField(always, modelAlways);
   alwaysTextField.setRequired(true);
   add(alwaysTextField);
   final CheckBox useOptionalCheck = new CheckBox( useOptional,
modelCheckOptional);
   add( useOptionalCheck );
   final TextField optionalTextField = new TextField(optional,
modelOptional);
   add(optionalTextField);

   add(new IFormValidator(){
  protected FormComponent getDependentFormComponents(){ return null; }
  public boolean validate(Form f){
  if (Boolean.TRUE.equals(useOptionalCheck.getConvertedInput()){
String optionalValue =
optionalTextField.getConvertedInput();
if (Strings.isEmpty(optionalValue ){
   error (field optional is required);
}
else if (optionalValue.length  3){
   error (optional value's length must be at least 3);
}
  }.
}
});

Cheers,
Xavier

2010/6/2 Iain Reddick iain.redd...@beatsystems.com

 Here's some example code (wicket 1.3.x):

 Java:

 private class TestForm extends Form {

  private String always;
  private boolean useOptional = false;
  private String optional;

  public TestForm(String id) {
super(id);

add( new TextField(always, new PropertyModel(this,
 always)).setRequired(true) );
final CheckBox useOptionalCheck = new CheckBox( useOptional, new
 PropertyModel(this, useOptional) );
add( useOptionalCheck );
add( new TextField(optional, new PropertyModel(this, optional)) {
  @Override
  public boolean isRequired() {
return
 ((Boolean)useOptionalCheck.getConvertedInput()).booleanValue();
  }
}.add(MinimumLengthValidator.minimumLength(3)) );
  }

 }

 Markup:

 form wicket:id=testForm
  input wicket:id=always type=text /
  input wicket:id=useOptional type=checkbox /
  input wicket:id=optional type=text /
  input type=submit /
 /form

 How can I express that I want the optional text field to only be used when
 the checkbox is selected?

 - Original Message -
 From: Igor Vaynberg igor.vaynb...@gmail.com
 To: users@wicket.apache.org
 Sent: Wednesday, 2 June, 2010 4:00:57 PM
 Subject: Re: Show/hide form components best practice

 if the form contains all the state then the answer is simple: write a
 bit of javascript that does it for you.

 -igor

 On Wed, Jun 2, 2010 at 2:53 AM, Iain Reddick
 iain.redd...@beatsystems.com wrote:
  That's just a server round-trip on client-side state changem, which is
  basically (1) in my initial list.
 
  Basically, this type of form behaviour is very common and the question
  of how to implement it with Wicket has been raised by every developer
  I know
  who has worked with the framework.
 
  I know that Wicket generally works best when you round-trip
  client-side state changes to the server, but I think that in this
  situation it is silly,
  as the submitted form contains all the required state.
 
  Jeremy Thomerson wrote:
 
  return true from wantOnSelectionChangedNotifications and put your
  visibility changing code in onSelectionChanged
 
 
  
 http://wicket.apache.org/docs/1.4/org/apache/wicket/markup/html/form/CheckGroup.html#wantOnSelectionChangedNotifications()http://wicket.apache.org/docs/1.4/org/apache/wicket/markup/html/form/CheckGroup.html#wantOnSelectionChangedNotifications%28%29
 
 
 
 http://wicket.apache.org/docs/1.4/org/apache/wicket/markup/html/form/CheckGroup.html#wantOnSelectionChangedNotifications()http://wicket.apache.org/docs/1.4/org/apache/wicket/markup/html/form/CheckGroup.html#wantOnSelectionChangedNotifications%28%29
 
  On Tue, Jun 1, 2010 at 5:37 AM, Iain Reddick
  iain.redd...@beatsystems.comwrote:
 
 
 
  Say I have a form with a check box that, when checked, shows some
  other field (i.e. it controls the visibility of other form
  components).
 
  What is the best approach to handling this?
 
  From what I understand, you have 3 options:
 
  1. Add ajax behaviour to the check box (re-render relevant
  components). 2. Add javascript from the Java code (e.g. add some
  kind of show/hide
  behaviour). 3. Add javascript directly to the HTML.
 
  What are peoples experiences of the 3 methods, and which is best?
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 
 
 
 
 
 
 
 

 

Re: Show/hide form components best practice

2010-06-03 Thread Xavier López
I'm with you on this one, this code feels like doing something that it
shouldn't, looks kind of bloated for such a simple and common requirement.
Maybe we need some stuffing of nice, pre-canned FormValidators ? :)

The problem with wicket's validators, as I see it, is that they are at a
Component level. They do their job based on that component's input/state,
only. In fact, they are called in Form's validateComponents() one by one in
a traversal. If another component's input or state is required to perform
the validation, i'd do it inside a FormValidator. That copes with your
requirement of ignore the input for this component completely, although I
don't know how would that be achieved.

Of course, in all those comments, I assume you can not rely on javascript
nor ajax to perform those validations, in which case the visibility approach
simply couldn't work.

Cheers,
Xavier

2010/6/3 Iain Reddick iain.redd...@beatsystems.com

 The problem with this approach is that you throw away all the nice,
 re-usable pre-canned validators that wicket has, and that it seems very
 wrong.

 I'd actually push the behaviour I would like to see even further - in the
 example I gave, I don't even want the optional field to update it's model
 when the check box isn't selected.

 Effectively, I want to be able to specify logic which says ignore the
 input for this component completely. Currently, the only way to do this is
 by using component visibility (unless I'm completely wrong on this).

 Xavier López wrote:

 Hi Iain,

 I would do it like this, with a FormValidator. I moved the minimum length
 validation also to the formValidator, because doing it with a
 MinimumLenghtValidator would trigger it before the formValidator executes,
 and may raise errors when the input is not valid (i.e. not mandatory) :

 private class TestForm extends Form {

 IModel modelAlways;
 IModel modelCheckOptional;
 IModel modelOptional;

  public TestForm(String id) {
   super(id);

   modelAlways =  new Model();
   modelCheckOptional = Boolean.FALSE;
   modelOptional = new Model();
   final TextField alwaysTextfield = new TextField(always, modelAlways);
   alwaysTextField.setRequired(true);
   add(alwaysTextField);
   final CheckBox useOptionalCheck = new CheckBox( useOptional,
 modelCheckOptional);
   add( useOptionalCheck );
   final TextField optionalTextField = new TextField(optional,
 modelOptional);
   add(optionalTextField);

   add(new IFormValidator(){
  protected FormComponent getDependentFormComponents(){ return null; }
  public boolean validate(Form f){
  if (Boolean.TRUE.equals(useOptionalCheck.getConvertedInput()){
String optionalValue =
 optionalTextField.getConvertedInput();
if (Strings.isEmpty(optionalValue ){
   error (field optional is required);
}
else if (optionalValue.length  3){
   error (optional value's length must be at least 3);
}
  }.
 }
 });

 Cheers,
 Xavier

 2010/6/2 Iain Reddick iain.redd...@beatsystems.com



 Here's some example code (wicket 1.3.x):

 Java:

 private class TestForm extends Form {

  private String always;
  private boolean useOptional = false;
  private String optional;

  public TestForm(String id) {
   super(id);

   add( new TextField(always, new PropertyModel(this,
 always)).setRequired(true) );
   final CheckBox useOptionalCheck = new CheckBox( useOptional, new
 PropertyModel(this, useOptional) );
   add( useOptionalCheck );
   add( new TextField(optional, new PropertyModel(this, optional)) {
 @Override
 public boolean isRequired() {
   return
 ((Boolean)useOptionalCheck.getConvertedInput()).booleanValue();
 }
   }.add(MinimumLengthValidator.minimumLength(3)) );
  }

 }

 Markup:

 form wicket:id=testForm
  input wicket:id=always type=text /
  input wicket:id=useOptional type=checkbox /
  input wicket:id=optional type=text /
  input type=submit /
 /form

 How can I express that I want the optional text field to only be used
 when
 the checkbox is selected?

 - Original Message -
 From: Igor Vaynberg igor.vaynb...@gmail.com
 To: users@wicket.apache.org
 Sent: Wednesday, 2 June, 2010 4:00:57 PM
 Subject: Re: Show/hide form components best practice

 if the form contains all the state then the answer is simple: write a
 bit of javascript that does it for you.

 -igor

 On Wed, Jun 2, 2010 at 2:53 AM, Iain Reddick
 iain.redd...@beatsystems.com wrote:


 That's just a server round-trip on client-side state changem, which is
 basically (1) in my initial list.

 Basically, this type of form behaviour is very common and the question
 of how to implement it with Wicket has been raised by every developer
 I know
 who has worked with the framework.

 I know that Wicket generally works best when you round-trip
 client-side state changes to the server, but I think that in this
 situation it is silly,
 as the submitted form contains all

Re: Show/hide form components best practice

2010-06-01 Thread Xavier López
I'd say what's reccomended to do in that case is to use a FormValidator in
order to check the conditions that make the toggling component validatable
or not. Check those conditions on the other component's input (getInput(),
getConvertedInput()), because model objects won't be updated until
validation phase ends.

I've been struggling recently on this matter with components inside
refreshingviews, and I have to say I'm feeling like not doing things the way
they should be, i'll append a sample of the formvalidator. I have the
refreshingview as a class attribute, altough it could have been found by
calling a visitor on the Form parameter of validate(), and using a 'tagging'
subclass for the refreshingview. I'd appreciate any comments on this code,
and if it can be improved in any way, I'd love to follow your suggestions
(also, hope that helps, Iain :) )

It's a validator that need counting how many inputs have been filled by the
user to make some business validation. I've been making 'tagging' subclasses
(no code by themselves, only super constructors) of the components inside
the view just to write a simpler visitor:

new IFormValidator(){
private static final long serialVersionUID = 1L;
public FormComponent[] getDependentFormComponents() { return
null; }

public void validate(Form form) {
ListIModel beansList =
(ListIModel)refreshingView.getModelObject();

   // Check count for some inputs on the view
countInputsA= 0;
countInputsB = 0;

// Obtenir els components de desplegables per consultar
inputs en cas que toqui
final ListFormComponent typeAComponents = new
ArrayListFormComponent();
final ListFormComponent typeBComponents= new
ArrayListFormComponent();
refreshingView.visitChildren(TypeAComponent.class, new
IVisitor(){
public Object component(Component component) {
typeAComponents.add((FormComponent)component);
return CONTINUE_TRAVERSAL;
}
});

refreshingView.visitChildren(DdcEntrevistaM45DropDownChoice.class, new
IVisitor(){
public Object component(Component component) {
typeBComponents.add((FormComponent)component);
return CONTINUE_TRAVERSAL;
}
});

for (FormComponent component : typeAComponents ) {
if (component.getConvertedInput() != null){
countInputsA++;
}
}
for (FormComponent component : typeBComponents ) {
if (component.getConvertedInput() != null){
countInputsB++;
}
}

// perform some validations on countInputsA and countInputsB
if (countInputsA  countInputsB) {
error(whatever);
}
}

2010/6/1 Iain Reddick iain.redd...@beatsystems.com

 With (2) and (3), what is the best way of handling validation?

 With (1), the server-side state for the form is correct, and the hidden
 component won't be validated on form submit.

 With (2) and (3), the visible state of the toggled component is purely
 client side. This means that on form submit, the hidden component will still
 be validated.


 Pedro Santos wrote:

 2 or 3 since there is no relevant state on the server side you want to
 consider to implement the component visibility rule.

 On Tue, Jun 1, 2010 at 7:37 AM, Iain Reddick
 iain.redd...@beatsystems.comwrote:



 Say I have a form with a check box that, when checked, shows some other
 field (i.e. it controls the visibility of other form components).

 What is the best approach to handling this?

 From what I understand, you have 3 options:

 1. Add ajax behaviour to the check box (re-render relevant components).
 2. Add javascript from the Java code (e.g. add some kind of show/hide
 behaviour).
 3. Add javascript directly to the HTML.

 What are peoples experiences of the 3 methods, and which is best?

 -
 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: NonCachingImage and xhtmlRenderer

2010-05-31 Thread Xavier López
Might this have something to do with the fact that I'm faking the
requestCycle in order to get the page's processed HTML ?
Like having the IResourceListener expired ?

I'm faking the request cycle like this :

/** Returns the processed HTML of the page as it would have been responded
by faking a requestcycle */
public static String renderPage(Page page) {

//get the servlet context
WebApplication application = (WebApplication) WebApplication.get();

ServletContext context = application.getServletContext();

//fake a request/response cycle
MockHttpSession servletSession = new MockHttpSession(context);
servletSession.setTemporary(true);

MockHttpServletRequest servletRequest = new MockHttpServletRequest(
application, servletSession, context);
MockHttpServletResponse servletResponse = new
MockHttpServletResponse(
servletRequest);

//initialize request and response
servletRequest.initialize();
servletResponse.initialize();

WebRequest webRequest = new ServletWebRequest(servletRequest);

BufferedWebResponse webResponse = new
BufferedWebResponse(servletResponse);
webResponse.setAjax(true);

WebRequestCycle requestCycle = new WebRequestCycle(
application, webRequest, webResponse);

//requestCycle.setRequestTarget(new
BookmarkablePageRequestTarget(pageClass, pageParameters));
requestCycle.setRequestTarget(new PageRequestTarget(page));

try {
requestCycle.getProcessor().respond(requestCycle);

if (requestCycle.wasHandled() == false) {
requestCycle.setRequestTarget(new
WebErrorCodeResponseTarget(
HttpServletResponse.SC_NOT_FOUND));
}
requestCycle.detach();

} finally {
requestCycle.getResponse().close();
}

return webResponse.toString();
}


Thank you,
Xavier



2010/5/27 Xavier López xavil...@gmail.com

 Finally, I've managed to dig through the XHtmlRenderer's code, and the
 IText dependencies inside, and have encountered the root of the issue :

 The problem is raised by the IText Image resource class, which tries to
 detect the format of the image by peeking at the first bytes of the stream.
 Getting into details, that piece of code receives an InputStream, obtained
 from a new URL(source), where 'source' is the value of the 'src' attribute
 in the img tag.

 I've tried constructing that URL by myself, and peeking at the first bytes,
 and have found that they do not match what it should be expected taking into
 account the image's format (jpg - 0xFF, 0xD8). Instead, the first bytes
 are: 0x3C, 0x21, 0x44, 0x4F.

 I'm creating the Wicket image resource with a DynamicImageResource, and
 I've checked that, when it's called, it returns the expected first bytes...

 DynamicImageResource resource = new DynamicImageResource(jpg) {
 @Override
 protected byte[] getImageData() {
 return generateBarCode();
 }
 };


 And again, when I try this on the link's onClick:

 link = new Link(printFullPagament){

 private static final long serialVersionUID = 1L;
 @Override
 public void onClick() {
 try{

 String srcImg = 
 http://myapp/?wicket:interface=:34:
 barcode::IResourceListener::wicket:antiCache=1274953227999;
 java.io.InputStream is = new
 URL(srcImg).openStream();
 int c1 = is.read();
 int c2 = is.read();
 int c3 = is.read();
 int c4 = is.read();
 ...
 }

 I don't seem to get DynamicImageResource#getImageData, nor any of the
 methods it defines (getResourceState()), and get those values on the first
 bytes ( 0x3C, 0x21, 0x44, 0x4F)

 Does anyone know what may be happening here ?

 Thanks a lot,
 Xavier Lopez



 2010/5/27 Xavier López xavil...@gmail.com

 Sorry for double-posting, I'm attaching some of the code I'm using:

 I havent't mentioned other static styling images are rendering correctly.


 byte[] imageByteArray = generateBarCodeImage(...)
 ByteArrayResource resource = new ByteArrayResource(image/jpeg,
 imageByteArray);
 Image barcodeImage= new Image(barcode, resource){
 protected void onComponentTag(ComponentTag tag)
 {
 super.onComponentTag(tag);
 String url = tag.getAttributes().getString(src);
 url = url + ((url.indexOf(?) = 0) ? amp; : ?);
 url = url + wicket:antiCache= +
 System.currentTimeMillis();
 tag.put(src, url);
 }
 };
 barcodeImage.setMarkupId(barcodeImageId

NonCachingImage and xhtmlRenderer

2010-05-27 Thread Xavier López
Hi,

I'm trying to use a xhtml to pdf renderer
(https://xhtmlrenderer.dev.goog_1283895835
java.net/) in order to print out a page to PDF.

The page contains a  NonCachingImage, with a barcode, in such a way that the
image gets the following HTML :

?xml version=1.0 encoding=UTF-8?
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN 
 http://www.w3.org/TR/xhtml11/DTD/xhtml11-flat.dtd;
 html xml:lang=ca xmlns=http://www.w3.org/1999/xhtml;
 ...
 img class=floatR
 src=?wicket:interface=:34:barcode::IResourceListener::wicket:antiCache=1274953227999/
 ...
 /html


When parsing the html String into a org.w3c.dom.document, I get the
following exception:

org.xml.sax.SAXParseException: The reference to entity wicket:antiCache
 must end with the ';' delimiter.



I know this is probably not a Wicket issue, and maybe has to do with the DTD
used for validation, or something like that.
I found somewhere this can get solved by changing the '' character in the
URL by 'amp;'. That worked. Now I plan to override NonCachingImage's
onComponentTag to append amp; instead of ''.

That solved, I can't get the image to get rendered in the pdf document, in
the html's DOM I have the img Element with the 'src' atttribute with value
=http://myapp/?wicket:interface=:34:
barcode::IResourceListener::wicket:antiCache=1274953227999, but
Image#onResourceRequested() (which is the callback for that URL) never gets
called during the render phase of the PDF...

I'd really appreciate any hints on this one, I've been looking into the
resources reference but I don't know if I should use it, or which
implementation to use... The image resource is formed from a byte array.

Many thanks,
Xavier López


Re: NonCachingImage and xhtmlRenderer

2010-05-27 Thread Xavier López
Sorry for double-posting, I'm attaching some of the code I'm using:

I havent't mentioned other static styling images are rendering correctly.


byte[] imageByteArray = generateBarCodeImage(...)
 ByteArrayResource resource = new ByteArrayResource(image/jpeg,
 imageByteArray);
 Image barcodeImage= new Image(barcode, resource){
 protected void onComponentTag(ComponentTag tag)
 {
 super.onComponentTag(tag);
 String url = tag.getAttributes().getString(src);
 url = url + ((url.indexOf(?) = 0) ? amp; : ?);
 url = url + wicket:antiCache= +
 System.currentTimeMillis();
 tag.put(src, url);
 }
 };
 barcodeImage.setMarkupId(barcodeImageId);
 barcodeImage.setOutputMarkupId(true);
 add(imatgeCodiBarres);
 .
 link = new Link(printPDF){
 private static final long serialVersionUID = 1L;
 @Override
 public void onClick() {
 try{
 String baseUrl = http://myapp/;;
 // Get the html to render into pdf
 String html = RenderHTMLUtils.renderPage(new
 PrintPage(...));
 DocumentBuilder builder =
 DocumentBuilderFactory.newInstance().newDocumentBuilder();
 Document doc = builder.parse(new
 ByteArrayInputStream(html.getBytes(UTF-8)));


 String src =
 doc.getElementById(barcodeImageId).getAttribute(src);
 src = baseUrl + src;

 doc.getElementById(barcodeImageId).setAttribute(src, src);

 ITextRenderer renderer = new ITextRenderer();
 renderer.setDocument(doc, baseUrl);


 RequestCycle.get().setRequestTarget(EmptyRequestTarget.getInstance());
 WebResponse response = (WebResponse)
 getResponse();
 response.setContentType(application/pdf);
 response.setAttachmentHeader(printout.pdf);
 response.setHeader(Cache-Control,
 max-age=0);
 OutputStream out = response.getOutputStream();
 renderer.layout();
 renderer.createPDF(out);
 }
 catch (Exception e){ }
 }
 };


2010/5/27 Xavier López xavil...@gmail.com

 Hi,

 I'm trying to use a xhtml to pdf renderer 
 (https://xhtmlrenderer.dev.http://goog_1283895835
 java.net/) in order to print out a page to PDF.

 The page contains a  NonCachingImage, with a barcode, in such a way that
 the image gets the following HTML :

 ?xml version=1.0 encoding=UTF-8?
 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN 
 http://www.w3.org/TR/xhtml11/DTD/xhtml11-flat.dtd;
 html xml:lang=ca xmlns=http://www.w3.org/1999/xhtml;
 ...
 img class=floatR
 src=?wicket:interface=:34:barcode::IResourceListener::wicket:antiCache=1274953227999/
 ...
 /html


 When parsing the html String into a org.w3c.dom.document, I get the
 following exception:

 org.xml.sax.SAXParseException: The reference to entity wicket:antiCache
 must end with the ';' delimiter.



 I know this is probably not a Wicket issue, and maybe has to do with the
 DTD used for validation, or something like that.
 I found somewhere this can get solved by changing the '' character in the
 URL by 'amp;'. That worked. Now I plan to override NonCachingImage's
 onComponentTag to append amp; instead of ''.

 That solved, I can't get the image to get rendered in the pdf document, in
 the html's DOM I have the img Element with the 'src' atttribute with value
 =http://myapp/?wicket:interface=:34:
 barcode::IResourceListener::wicket:antiCache=1274953227999, but
 Image#onResourceRequested() (which is the callback for that URL) never gets
 called during the render phase of the PDF...

 I'd really appreciate any hints on this one, I've been looking into the
 resources reference but I don't know if I should use it, or which
 implementation to use... The image resource is formed from a byte array.

 Many thanks,
 Xavier López




-- 
Klein bottle for rent--inquire within.


Re: NonCachingImage and xhtmlRenderer

2010-05-27 Thread Xavier López
Finally, I've managed to dig through the XHtmlRenderer's code, and the IText
dependencies inside, and have encountered the root of the issue :

The problem is raised by the IText Image resource class, which tries to
detect the format of the image by peeking at the first bytes of the stream.
Getting into details, that piece of code receives an InputStream, obtained
from a new URL(source), where 'source' is the value of the 'src' attribute
in the img tag.

I've tried constructing that URL by myself, and peeking at the first bytes,
and have found that they do not match what it should be expected taking into
account the image's format (jpg - 0xFF, 0xD8). Instead, the first bytes
are: 0x3C, 0x21, 0x44, 0x4F.

I'm creating the Wicket image resource with a DynamicImageResource, and I've
checked that, when it's called, it returns the expected first bytes...

DynamicImageResource resource = new DynamicImageResource(jpg) {
@Override
protected byte[] getImageData() {
return generateBarCode();
}
};


And again, when I try this on the link's onClick:

link = new Link(printFullPagament){
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
try{

String srcImg = 
http://myapp/?wicket:interface=:34:
barcode::IResourceListener::wicket:antiCache=1274953227999;
java.io.InputStream is = new
URL(srcImg).openStream();
int c1 = is.read();
int c2 = is.read();
int c3 = is.read();
int c4 = is.read();
...
}

I don't seem to get DynamicImageResource#getImageData, nor any of the
methods it defines (getResourceState()), and get those values on the first
bytes ( 0x3C, 0x21, 0x44, 0x4F)

Does anyone know what may be happening here ?

Thanks a lot,
Xavier Lopez


2010/5/27 Xavier López xavil...@gmail.com

 Sorry for double-posting, I'm attaching some of the code I'm using:

 I havent't mentioned other static styling images are rendering correctly.


 byte[] imageByteArray = generateBarCodeImage(...)
 ByteArrayResource resource = new ByteArrayResource(image/jpeg,
 imageByteArray);
 Image barcodeImage= new Image(barcode, resource){
 protected void onComponentTag(ComponentTag tag)
 {
 super.onComponentTag(tag);
 String url = tag.getAttributes().getString(src);
 url = url + ((url.indexOf(?) = 0) ? amp; : ?);
 url = url + wicket:antiCache= +
 System.currentTimeMillis();
 tag.put(src, url);
 }
 };
 barcodeImage.setMarkupId(barcodeImageId);
 barcodeImage.setOutputMarkupId(true);
 add(imatgeCodiBarres);
 .
 link = new Link(printPDF){
 private static final long serialVersionUID = 1L;
 @Override
 public void onClick() {
 try{
 String baseUrl = http://myapp/;;
 // Get the html to render into pdf
 String html = RenderHTMLUtils.renderPage(new
 PrintPage(...));
 DocumentBuilder builder =
 DocumentBuilderFactory.newInstance().newDocumentBuilder();
 Document doc = builder.parse(new
 ByteArrayInputStream(html.getBytes(UTF-8)));


 String src =
 doc.getElementById(barcodeImageId).getAttribute(src);
 src = baseUrl + src;

 doc.getElementById(barcodeImageId).setAttribute(src, src);

 ITextRenderer renderer = new ITextRenderer();
 renderer.setDocument(doc, baseUrl);


 RequestCycle.get().setRequestTarget(EmptyRequestTarget.getInstance());
 WebResponse response = (WebResponse)
 getResponse();
 response.setContentType(application/pdf);
 response.setAttachmentHeader(printout.pdf);
 response.setHeader(Cache-Control,
 max-age=0);
 OutputStream out = response.getOutputStream();
 renderer.layout();
 renderer.createPDF(out);
 }
 catch (Exception e){ }
 }
 };


 2010/5/27 Xavier López xavil...@gmail.com

 Hi,

 I'm trying to use a xhtml to pdf renderer 
 (https://xhtmlrenderer.dev.http://goog_1283895835
 java.net/) in order to print out a page to PDF.

 The page contains a  NonCachingImage, with a barcode, in such a way that
 the image gets the following HTML :

 ?xml version=1.0 encoding=UTF-8

Re: Check and CheckGroup

2010-05-14 Thread Xavier López
If you hava a single checkbox, and only want to know if it's selected, I'd
use a Checkbox component instead. You can put it a Boolean Model initialized
to whatever and it will come back with the boolean value that will tell you
if it's selected.

Cheers,
Xavier

2010/5/14 Michael O'Cleirigh michael.ocleir...@rivulet.ca

 Hi Zilvinas,

 The Model for a CheckGroup is a CollectionT; I looked in
 Check.onComponentTag(...) in Eclipse and it shows that it emits the
 checked tag if the model object of the Check is contained in the
 CheckGroup's collection.

 But you should only really need to use the CollectionT returned from the
 CheckGroup as it contains the list of selected items.

 Regards,

 Mike

  Can anyone explain me how do I determine whether the checkbox is
 checked?
 Is the modelObject null if not or what? Don't understand that and
 javadoc's don't help :)

 What does the list in the CheckGroup model do? what does model in Check
 do?
 does the item in the check model require to be inside the CheckGroup list?

 Thank you :)

 Žilvinas Vilutis

 Mobile:   (+370) 652 38353
 E-mail:   cika...@gmail.com





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




-- 
Klein bottle for rent--inquire within.


Required component depending on other's component value

2010-05-13 Thread Xavier López
Hi,

I have a Form with some components that are required depending on some other
component's value. Let's put for example a RadioGroup with values City and
Country. There are two DropDownChoices with Cities and Countries, and only
the selected one in the RadioGroup is required. It's important taking into
account the radiogroup is also required.

Tipically, I've approached this matter by overriding isRequired() on the
DDC's, and querying the RadioGroup input by means of
radiogroup.validate()+radiogroup.getConvertedInput(), in order to return
true or false in the override depending of the input value.

I don't think that's a good way to do that sort of validation, mainly
because if the radiogroup is not being given any value by the user, the
subsequent calls to radiogroup.validate() on account of the isRequired()
overridings throw up several error messages on that component.

Is using a FormValidator the best way to perform this kind of validations ?
In general, could it be asserted that when a validation involves two or more
different components it should be put in a FormValidator ?

I'd appreciate any opinion or commentary about this subject.

Thanks,
Xavier


Re: wicket:message attribute in regular html tags with child components

2010-04-30 Thread Xavier López
Hasn't anybody else been in this situation ? I finally checked it is
necessary for a regular tag with a wicket:message attribute and with wicket
component childs to be also a wicket component... Maybe it would be nice to
have this information on the wiki page talking about the wicket:message
attribute...

This example would give the error:

public class TestPage extends Page {
public TestPage(){
add(new Label(childLabel, Sample text for the label));
}
}

html
body
table wicket:message=summary:anyResourceKey
trtdspan wicket:id=childLabel/span/td/tr
/table
/body
/html


The only way I see to get around it is to :
public class TestPage extends Page {
public TestPage(){
WebMarkupContainer cont = new WebMarkupContainer(cont);
add(cont);
cont.add(new Label(childLabel, Sample text for the label));
}
}

html
body
table wicket:id=cont wicket:message=summary:anyResourceKey
trtdspan wicket:id=childLabel/span/td/tr
/table
/body
/html

Cheers,
Xavier

2010/4/29 Xavier López xavil...@gmail.com

 Yes, you are right, Wilhelmsen, and that's what Wicket is doing, I
 understand that correctly. The problem is, when I have a wicket component
 attached to that table tag. Wicket seems to treat that table as a
 component, with autogenerated wicket:id, and logically, expects the child
 components (in markup) to be added to it. I suppose I have to manually model
 that table into a wicket component (i.e. WebMarkupContainer) in order to
 be able to add those child components to it and let Wicket process the
 component hierarchy correctly...


 BTW, I just noticed I wrote the last message incorrectly:

 input type=text wicket:message=title:myresource/input

 Turns into

 input type=text title=Test Title/input


 Thanks,
 Xavier

 2010/4/29 Wilhelmsen Tor Iver toriv...@arrive.no

  i meant where do you expect the localized message to be rendered into?
  if wicket:message is attached to the table tag?

 Well, since he is using the attribute version of wicket:message, I guess
 he expects the output from

   table wicket:message=summary:myresource

 to be

 table summary=localized message with key myresource

 - Tor Iver



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





Re: wicket:message attribute in regular html tags with child components

2010-04-29 Thread Xavier López
Oh, now I think I got your point... I don't know how wicket treats markup
internally, I could expect some markup substitution on the attribute
wicket:message='summary:myResource'  by summary='This table'

In fact, I have tried using another tag, without any child Wicket Component

input type=text wicket:message=title:myresource/input

And Wicket is treating it correctly...

input type=text wicket:message=Test Title/input

Thanks,
Xavier


2010/4/28 Igor Vaynberg igor.vaynb...@gmail.com

 i meant where do you expect the localized message to be rendered into?
 if wicket:message is attached to the table tag?

 -igor

 On Wed, Apr 28, 2010 at 9:52 AM, Xavier López xavil...@gmail.com wrote:
  Hi, I'd expect it to lie in the ContainerComponent's folder, assuming
  ContainerComponent is the the Page or Panel associated with that
 markup...
  In other words, getString(myresource) from that component would find
 it.
 
  Does this have something to do with that error ?
 
  Thanks,
  Xavier
 
  2010/4/28 Igor Vaynberg igor.vaynb...@gmail.com
 
  when you have markup like:
 
  table wicket:message=summary:myresource
   trtdspan wicket:id=myComponent/span/td/tr
   /table
 
  where do you expect your localized message to go?
 
  -igor
 
  On Wed, Apr 28, 2010 at 2:51 AM, Xavier López xavil...@gmail.com
 wrote:
   Hi,
  
   I have just bumped into a particular situation, I think I know what's
   happening but I'd like to share and, if possible, have it confirmed
 here.
   Additionally, some info on this subject could be added to the wiki
 page
  
 
 https://cwiki.apache.org/WICKET/wickets-xhtml-tags.html#Wicket%27sXHTMLtags-Attributewicket:message
  
   In a regular table html tag (wicket:id-less), I'd like to have a
   wicket:message attribute (for the 'summary' attribute) in order to
 take
   advantage from wicket's localization mechanism. Under this tag, I have
 a
   number of wicket components. My surprise came when I found the
 following
   error:
  
   table wicket:message=summary:myresource
   trtdspan wicket:id=myComponent/span/td/tr
   /table
  
   org.apache.wicket.markup.MarkupException: Unable to find component
 with
  id
   'myComponent' in [MarkupContainer [Component id =
 _message_attr_303]].
  This
   means that you declared wicket:id=myComponentin your markup, but that
  you
   either did not add the component to your page at all, or that the
  hierarchy
   does not match.
  
  
  
   The first suspicious thig I noticed here was the _message_attr_303
 in
  the
   component hierarchy. Digging through the code, I found in
   WicketMessageTagHandler that this id is given to components with
   wicket:message attributes and without wicket:id's.
  
   So, maybe what's happening here is that the table tag is being
 assigned
  a
   wicket:id and Wicket expects me to add 'myComponent' to the
 automatically
   generated _message_attr_303... Should it be fixed by modelling the
  table
   tag with a webmarkupcontainer and adding 'myComponent' to it ?
  
   Cheers,
   Xavier
  
 
  -
  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




-- 
Klein bottle for rent--inquire within.


Re: wicket:message attribute in regular html tags with child components

2010-04-29 Thread Xavier López
Yes, you are right, Wilhelmsen, and that's what Wicket is doing, I
understand that correctly. The problem is, when I have a wicket component
attached to that table tag. Wicket seems to treat that table as a
component, with autogenerated wicket:id, and logically, expects the child
components (in markup) to be added to it. I suppose I have to manually model
that table into a wicket component (i.e. WebMarkupContainer) in order to
be able to add those child components to it and let Wicket process the
component hierarchy correctly...


BTW, I just noticed I wrote the last message incorrectly:

input type=text wicket:message=title:myresource/input

Turns into

input type=text title=Test Title/input


Thanks,
Xavier

2010/4/29 Wilhelmsen Tor Iver toriv...@arrive.no

  i meant where do you expect the localized message to be rendered into?
  if wicket:message is attached to the table tag?

 Well, since he is using the attribute version of wicket:message, I guess he
 expects the output from

   table wicket:message=summary:myresource

 to be

 table summary=localized message with key myresource

 - Tor Iver



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



Re: DropDownChoice problem

2010-04-28 Thread Xavier López
Hi,

I also bumped into this matter when starting with Wicket, make sure the
Collection returned by getNationalities() contains the value of the
'nationality' attribute of the CPM's backing object, or use a suitable
ChoiceRenderer, as Wilhelmsen suggests, in order to be able to put as
choices the same objects you can have in the 'nationality' attribute.

I think the DDC's ModelObject has to be/will be one of the objects in the
choices list before rendering/after form submission

Cheers,
Xavier

2010/4/28 Wilhelmsen Tor Iver toriv...@arrive.no

  After adding the dropdown to the form, i am able to save the record
  properly. However, when i display a  form with an existing record,
 
  the DropDownChoice is not showing the current 'nationality' and it is
  only
  showing Choose One;

 Sounds like Wicket gets confused regarding value/id, try setting an
 IChoiceRenderer, e.g.

 lstNationality.setChoiceRenderer(new ChoiceRenderer(name, id));

 - Tor Iver

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




-- 
Klein bottle for rent--inquire within.


Re: wicket:message attribute in regular html tags with child components

2010-04-28 Thread Xavier López
Hi, I'd expect it to lie in the ContainerComponent's folder, assuming
ContainerComponent is the the Page or Panel associated with that markup...
In other words, getString(myresource) from that component would find it.

Does this have something to do with that error ?

Thanks,
Xavier

2010/4/28 Igor Vaynberg igor.vaynb...@gmail.com

 when you have markup like:

 table wicket:message=summary:myresource
  trtdspan wicket:id=myComponent/span/td/tr
  /table

 where do you expect your localized message to go?

 -igor

 On Wed, Apr 28, 2010 at 2:51 AM, Xavier López xavil...@gmail.com wrote:
  Hi,
 
  I have just bumped into a particular situation, I think I know what's
  happening but I'd like to share and, if possible, have it confirmed here.
  Additionally, some info on this subject could be added to the wiki page
 
 https://cwiki.apache.org/WICKET/wickets-xhtml-tags.html#Wicket%27sXHTMLtags-Attributewicket:message
 
  In a regular table html tag (wicket:id-less), I'd like to have a
  wicket:message attribute (for the 'summary' attribute) in order to take
  advantage from wicket's localization mechanism. Under this tag, I have a
  number of wicket components. My surprise came when I found the following
  error:
 
  table wicket:message=summary:myresource
  trtdspan wicket:id=myComponent/span/td/tr
  /table
 
  org.apache.wicket.markup.MarkupException: Unable to find component with
 id
  'myComponent' in [MarkupContainer [Component id = _message_attr_303]].
 This
  means that you declared wicket:id=myComponentin your markup, but that
 you
  either did not add the component to your page at all, or that the
 hierarchy
  does not match.
 
 
 
  The first suspicious thig I noticed here was the _message_attr_303 in
 the
  component hierarchy. Digging through the code, I found in
  WicketMessageTagHandler that this id is given to components with
  wicket:message attributes and without wicket:id's.
 
  So, maybe what's happening here is that the table tag is being assigned
 a
  wicket:id and Wicket expects me to add 'myComponent' to the automatically
  generated _message_attr_303... Should it be fixed by modelling the
 table
  tag with a webmarkupcontainer and adding 'myComponent' to it ?
 
  Cheers,
  Xavier
 

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




Re: AjaxSubmitLink javadocs

2010-04-16 Thread Xavier López
Thanks for the answer, Jeremy.

I just created issue https://issues.apache.org/jira/browse/WICKET-2837.

I'm with you on what you state, it was obvious the only possible way to do a
submit without JS is to have an html submit mechanism, anyway, I was just
being cautious in case I was missing something.
I'm just glad to contribute improving this great framework, even though it's
on a lesser thing like this.

Cheers,
Xavier


2010/4/16 Jeremy Thomerson jer...@wickettraining.com

 This appears to be an issue in the documentation of the AjaxSubmitLink.  I
 just checked and the documentation is still the same in 1.4.  I will try to
 verify this and fix it tomorrow.  In the meantime, it would be helpful if
 you opened a JIRA issue to keep track of this (post the link back to this
 thread).

 Anyway, the documentation is written as if this were a fallback component
 (i.e. AjaxFallbackLink).  However, it is not.  Obviously, if you do not
 have
 JS enabled, you can not submit a form with a link in the browser.  You
 could
 only submit it with a submit button.

 --
 Jeremy Thomerson
 http://www.wickettraining.com



 On Thu, Apr 15, 2010 at 4:12 AM, Xavier López xavil...@gmail.com wrote:

  Hi,
 
  I'm a liitle confused about AjaxSubmitLink's JavaDoc, and the code inside
  it... I'm using Wicket 1.3.6:
 
  If/when javascript is turned off in the browser, or it doesn't support
   javascript, then the
   browser will not respond to the onclick event, using the href directly.
   Wicket will then use a
   normal request target, and call the serverside onClick with a null
 {...@link
   AjaxRequestTarget}.
  
 
  First question is, does it really mean 'serverside onClick' ? Or should
 it
  read 'serverside onSubmit' ?
 
  And then, in the code, I see :
 
  protected void onComponentTag(ComponentTag tag)
   {
   super.onComponentTag(tag);
  
   if (isLinkEnabled())
   {
   if (tag.getName().toLowerCase().equals(a))
   {
   tag.put(href, #);
   }
   }
   else
   {
   disableLink(tag);
   }
   }
  
 
  So it seems this component never gets to have anything else than # in its
  href, so it won't do anything when js is not enabled...
 
  Is this an error in the documentation ?
 
  Thanks,
  Xavier
 




-- 
Klein bottle for rent--inquire within.


Detect bookmark access to nonbookmarkablepages

2010-04-16 Thread Xavier López
Hi there,

I'm trying to find an elegant way to detect the cases where a user tries to
access a nonbookmarkablepage with a bookmark. From the stack trace produced
in this case, I see this situation is handled in
DefaultPageFactory#newPage(Class pageClass), like this:


catch (NoSuchMethodException e)
{
// a bit of a hack here..
Constructor constructor = constructor(pageClass,
PageParameters.class);
if (constructor != null)
{
return newPage(constructor, new PageParameters());
}
else
{
throw new WicketRuntimeException(Unable to create page from
 + pageClass +
. Class does not have a default contructor, e);
}
}


I would like to present a custom page explaining the circumstances with a
nice link to the starting place where to navigate from.
I don't really like treating this situation as a WicketRuntimeException and
have it bubbling up to an internalerrorpage, because of the little
information on the exception thrown (i don't like identifying it by its
text, or nested exception type).

Unfortunately, DefaultPageFactory#newPage(Class pageClass) is final, so this
behavior can not be overriden. Is providing a custom implementation of
IPageFactory the best approach to this issue ? Any other way around ?

Cheers,
Xavier


Re: Repeating form on a page

2010-04-16 Thread Xavier López
Hi,

I've been through a similar issue recently, also with a 'remove' button to
delete elements from the list. I ended up using RefreshingView (that's the
one I'd reccomend), and it worked nicely.

However I'll expose the various solutions I've gone through, hoping to
provide some background on the subject. I'd also be grateful on observations
and comments on these, because I'm sure I'm missing something and there are
still some aspects of these repeaters that I don't understand, so probably
part of these thoughts are wrong :)

In the first place, I used a ListView repeater. When clicking the 'add new'
button, however, I found that all unsaved input entered on the other list
elements was lost. That's because ListView refreshes the entire List with
the backing Model objects in it's ModelList, and models were not being
updated, as forms were not being submitted. So, I had to make the 'add new'
link a submit button (skipping default form processing in order to avoid
validation errors on incomplete data). However, to my surprise, same thing
keeped happening (same for the delete button). Later on, I found about
'ListView#setReuseItems(boolean)', which solved the problem. But to my
despair, the delete button always deleted the last element from the List. I
still do not understand why, and still don't know what is 'reuseItems'
really doing. (Any hints on that one?)

Then, I was advised to use RefreshingView, and things were moreover the
same, only that instead of having a ModelList given to the repeater, an
IteratorModel had to be provided in an overriden method. In this case, a
ModelsEqual ReuseItemStrategy had to be provided in order to keep the
unsaved inputs in the forms when adding/removing.


As a last appreciation, I have to say I hoped there was a specific component
addressing this behavior, being it a fairly common arrangement... If one day
I fully understand this I'd be happy to implement one myself, even if only
for the sake of clarity in my code ;)

Thanks,
Xavier

2010/4/16 David Hamilton dhamil...@hermitagelighting.com

 I am new to Wicket (and have had great help from this community so far -
 thank you). My question here is that I'm trying to setup a simple
 contact form where a person may have zero or more contacts. My solution
 is to make the contact info a form within a panel. However, I need to
 repeat the panel form on the page for each contact (represented by a
 POJO I can bind to the form elements).  I will provide and add button
 at the bottom of the list to allow them to re-submit the page and add a
 new empty object bound to a new form element.



  So my question is really two questions.



 1)  Is this best approach for this situation?

 2)  If it is, how do I bind each POJO on the list to a unique form
 instance?



 The goal is to allow each contact to be individually edited  and saved.



 Any help is greatly appreciated.



 Thanks,



 David Hamilton

 Web Coordinator

 (615) 843-3337

 Hermitage Lighting Gallery

 www.hermitagelighting.com




 
 Keep it Green! To help protect the environment, please
 only print this email if necessary.
 Printing email can cost more than you think.
 Learn more on our website:
 http://www.hermitagelighting.com/printing_email.php

 The information transmitted in this email is
 intended solely for the individual or entity
 to which it is addressed and may contain
 confidential and/or privileged material.
 Any review, retransmission, dissemination or
 other use of or taking action in reliance
 upon this information by persons or entities
 other than the intended recipient is prohibited.
 If you have received this email in error please
 immediately notify us by reply email to the sender.
 You must destroy the original material and its contents from any computer.
 




-- 
Klein bottle for rent--inquire within.


Re: Bug in Page refresh?

2010-04-16 Thread Xavier López
Hi Wolfgang,

If I had to refresh the entire page on language change, I would not do it
with an Ajax Request, but with a normal one instead. I do not know how will
setResponsePage behave in a serverside Ajax callback. However, if you need
to do it with ajax, you should add the language dependent components to the
AjaxRequestTarget...

Hope that helped.

Cheers,
Xavier

2010/4/16 Wolfgang Grossinger wolfgang.grossin...@teamead.com

 We have a DropDownChoice to change the language of a page (the language in
 mapped through an enum). The handler to change the code is as follows.

@Override
protected void onSubmit(AjaxRequestTarget target) {

  getSession().setLocale(getLanguage().getObject().getLocale());
setResponsePage(getPage());
}

 We just have 3 pages and a login page. The code works on 2 of 3 pages but I
 don't know why it doesn't work on the third page (the code to find the
 language and to get the current page seems also to be correct and working).
 My question is does anybody have some hints what I could do wrong?

 Regards,

 Wolfgang



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




Re: Detect bookmark access to nonbookmarkablepages

2010-04-16 Thread Xavier López
Thanks for the feedback, Igor, nice idea.

About the page factory exception, in fact I have nonbookmarkablepages
mounted as if they were, just to makeup the url's, like this:

mount(new HybridUrlCodingStrategy(/pageA, PageA.class));

So that when the user enters PageA (no default constructor - non
bookmarkable), he gets on the browser's location bar:
http://myapplication/pageA[.x]

Maybe it's a little weird, but it's working for me :)

Cheers,
Xavier

2010/4/16 Igor Vaynberg igor.vaynb...@gmail.com

 use a decorator, wrap the default factory, catch the exception,
 transform it into something else.

 although, if your users are bookmarking a non-bookmarkable url you
 should get a page expired error. page factory is only used for
 creating bookmarkable pages.

 -igor

 On Fri, Apr 16, 2010 at 1:37 AM, Xavier López xavil...@gmail.com wrote:
  Hi there,
 
  I'm trying to find an elegant way to detect the cases where a user tries
 to
  access a nonbookmarkablepage with a bookmark. From the stack trace
 produced
  in this case, I see this situation is handled in
  DefaultPageFactory#newPage(Class pageClass), like this:
 
 
 catch (NoSuchMethodException e)
 {
 // a bit of a hack here..
 Constructor constructor = constructor(pageClass,
  PageParameters.class);
 if (constructor != null)
 {
 return newPage(constructor, new PageParameters());
 }
 else
 {
 throw new WicketRuntimeException(Unable to create page
 from
   + pageClass +
 . Class does not have a default contructor, e);
 }
 }
 
 
  I would like to present a custom page explaining the circumstances with a
  nice link to the starting place where to navigate from.
  I don't really like treating this situation as a WicketRuntimeException
 and
  have it bubbling up to an internalerrorpage, because of the little
  information on the exception thrown (i don't like identifying it by its
  text, or nested exception type).
 
  Unfortunately, DefaultPageFactory#newPage(Class pageClass) is final, so
 this
  behavior can not be overriden. Is providing a custom implementation of
  IPageFactory the best approach to this issue ? Any other way around ?
 
  Cheers,
  Xavier
 

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




-- 
Klein bottle for rent--inquire within.


AjaxSubmitLink javadocs

2010-04-15 Thread Xavier López
Hi,

I'm a liitle confused about AjaxSubmitLink's JavaDoc, and the code inside
it... I'm using Wicket 1.3.6:

If/when javascript is turned off in the browser, or it doesn't support
 javascript, then the
 browser will not respond to the onclick event, using the href directly.
 Wicket will then use a
 normal request target, and call the serverside onClick with a null {...@link
 AjaxRequestTarget}.


First question is, does it really mean 'serverside onClick' ? Or should it
read 'serverside onSubmit' ?

And then, in the code, I see :

protected void onComponentTag(ComponentTag tag)
 {
 super.onComponentTag(tag);

 if (isLinkEnabled())
 {
 if (tag.getName().toLowerCase().equals(a))
 {
 tag.put(href, #);
 }
 }
 else
 {
 disableLink(tag);
 }
 }


So it seems this component never gets to have anything else than # in its
href, so it won't do anything when js is not enabled...

Is this an error in the documentation ?

Thanks,
Xavier


Re: Weird feedback message formats

2010-03-25 Thread Xavier López
Hi  Sigmar,

I went fine just setting the component's Label with setLabel().
This method sets a Model which will be used instead of the wicket:id in the
built-in validator's error messages.

Cheers,
Xavier

2010/3/25 Sigmar Muuga meedi...@gmail.com

 Hello,
 how to customize error / feedback messages in wicket?
 At the moment wicket displays quite stupidly password errors:
 mysecret is too short and so on.

 I would like to use translated field labels in feedback messages instead of
 field names, that are not so user friendly.

 Sigmar




-- 
Klein bottle for rent--inquire within.


Input and Model

2010-03-24 Thread Xavier López
I have a Form with a list of Checks in a CheckGroup. In the same Form, there
is a DropDownChoice with a dynamic choices model. The choices are the
selected checks plus some fixed options.
It has to be considered that some Checks can be preselected at construction
time, and that the choices have to be updated while the user checks the
Checks. The Checks have an EventAjaxBehavior(onclick) in order to do some
processing and update the ddc's choice Model.

So, the Choices Model looks like this:

IModel choiceModel = new AbstractReadOnlyModel(){
   public Object get(){
  ListString checkeds;
  if (!checkGroup.hasRawInput()){
  // With no input, get the ModelObject - construction time case
  checkeds = checkGroup.getModelObject();
  }
  else {
  checkeds = checkGroup.getConvertedInput();
  }
  // Add fixed options
  checkeds.add (...);
  return checkeds;
   }
};

I find it quite annoying to have to do that kind of conditional. I have seen
there is the getValue() method, but that method returns getInput() or
getModelObjectAsString(). Isn't there any method to get ConvertedInput or
ModelObject instead ? Or any better way to achieve this ?

Also, I don't know if the choices Model will be updated automatically, or if
I have to perform some manual operation, if possible at all. Even if it's
not possible, I found this issue in other circumstances...

Cheers,
Xavier


Re: Dynamic Image (aka Barcode) based on user input not refreshed via Ajax

2010-03-19 Thread Xavier López
Found a similar issue not long ago. There is a class that does just what you
mentioned, appends a timestamp as a request parameter of the img tag's
url. I think the class was NonCachingImage.

Cheers,
Xavier

2010/3/19 Doug Leeper douglee...@yahoo.com

 I am trying to create a barcode image from a user entered value.  The image
 is to be updated while the user types.  Hence I am using Ajax (onChange
 event) on the text field to regenerate the image.  However, the image is not
 getting refreshed.  It appears that the browser is not recognizing that the
 image has been updated.  Is there a way to append a timestamp on the image
 url just for this image?

 or should I use a different type of resource?

 Note: the value entered has not be persisted so I don't believe I can a
 ResourceReference.  Please correct me if I am wrong.


 Thanks
 - Doug



 BTW...Here is my code that I am using to generate the bar code:

 barCodeValueContainer = new WebMarkupContainer(barCodeValueContainer) {
@Override
public void onBeforeRender() {
if (coupon.getObject().getBarCodeType() == null) {
codeContainer.replace(new
 WebMarkupContainer(barCode));
} else if (barCodeErrorMessage == null) {
codeContainer.replace(new BarCodeFragment(barCode,
 this));
} else {
codeContainer.replace(new ErrorFragment(barCode, this,
barCodeErrorMessage));
}
super.onBeforeRender();
}

public boolean isVisible() {
return coupon.getObject().getBarCodeType() != null;
}
};

 private class BarCodeFragment extends Fragment {
public BarCodeFragment(String id, MarkupContainer markupProvider) {
super(id, barCodeFragment, markupProvider);
setRenderBodyOnly(true);

// Create the barcode bean

String barCodeType = coupon.getObject().getBarCodeType();
String barCodeValue = coupon.getObject().getBarCodeValue();

AbstractBarcodeBean bean = null;

if (barCodeType.equals(BarCodeType.CODE_39.id())) {
bean = new Code39Bean();
// bar width exactly one pixel
((Code39Bean) bean).setWideFactor(3);
} else if (barCodeType.equals(BarCodeType.CODE_128.id())) {
bean = new Code128Bean();
} else if (barCodeType.equals(BarCodeType.UPC_A.id())) {
bean = new UPCABean();
}

if (bean == null || barCodeValue == null) {
add(new ErrorFragment(barCode, CouponDetailEditPanel.this,
Bar code value not set));
} else {
final int dpi = 150;

// Configure the barcode generator
bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); // makes
 the
// narrow

bean.doQuietZone(false);

// Open output file
ByteArrayOutputStream out = new ByteArrayOutputStream();

try {
// Set up the canvas provider for monochrome PNG output
BitmapCanvasProvider canvas = new
 BitmapCanvasProvider(out,
image/png, dpi,
 BufferedImage.TYPE_BYTE_BINARY,
false, 0);

// Generate the barcode
bean.generateBarcode(canvas, barCodeValue);

System.out.println(VALUE:  + barCodeValue);

// Signal end of generation
canvas.finish();
out.close();
final byte[] content = out.toByteArray();
Image img = new Image(barCode, new
 BarCodeImageResource(
content));
add(img);
} catch (Exception e) {
add(new ErrorFragment(barCode,
CouponDetailEditPanel.this, e.getMessage()));
}
}

}
}


 private class BarCodeImageResource extends DynamicImageResource {
private byte[] content;

public BarCodeImageResource(byte[] content) {
super(image/png);
this.content = content;
this.setLastModifiedTime(Time.now());
}

@Override
protected byte[] getImageData() {
return content;
}

}



Re: Invoke method after onPopulate

2010-03-17 Thread Xavier López
Thank you, I ended up doing it client-side, but I appreciate the feedback,
I'm sure it will be useful in another moment.

Cheers,
Xavier

2010/3/16 Igor Vaynberg igor.vaynb...@gmail.com

 you can override onbeforerender, call super first, then iterate over
 the children and do what you need to.

 -igor

 On Tue, Mar 16, 2010 at 6:44 AM, Xavier López xavil...@gmail.com wrote:
  Hi,
 
  I have a ListView that build up a list of checks. These Checks have all
 to
  be enabled or disabled depending on a bean's property. That property is
  binded to a general checkbox (outside the listview). When the user
 changes
  the selection on the main checkbox, the ones in the listview
 enable/disable.
  Now, I see that I can't use the same method I use in the Ajax Behavior,
  because at constructor time, the ListView has not been populated yet.
 
  Is there a way to invoke a method after ListView' s onPopulate() ?
  Is it a better approach to override isEnabled() on those Checks ? The
 bean
  holding the property to decide it is large, I think I should use a binded
  model in this case (getModel().bind(generalProperty), or the
 propertyModel
  from the general checkbox).
 
  Thanks,
  Xavier
 

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




-- 
Klein bottle for rent--inquire within.


Re: ClassLoader (Serialization?) error

2010-03-16 Thread Xavier López
)
at
net.gencat.accesnet.portal.application.ANetFilter.doFilter(ANetFilter.java:37)
at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3242)
at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at
weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2010)
at
weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1916)
at
weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1366)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
2010-03-15 20:38:58,509 ERROR ap18_s1_IX_II [[ACTIVE] ExecuteThread: '0' for
queue: 'weblogic.kernel.Default (self-tuning)']
org.apache.wicket.request.target.resource.SharedResourceRequestTarget
359167|RGCZLpMSQGtMyQvz53HrwSsxrS9cGrRJQGyp8dJNNz3xTpHv8QpW!-469065994!
1268681938...@192.168.131.143 - shared resource
mypac%3C/a%3E%3C/h4%3E%20%20%20%20%3Cdiv%20id= not found2010-03-15
20:38:58,509 ERROR ap18_s1_IX_II [[ACTIVE] ExecuteThread: '0' for queue:
'weblogic.kernel.Default (self-tuning)']
org.apache.wicket.request.target.resource.SharedResourceRequestTarget
359167|RGCZLpMSQGtMyQvz53HrwSsxrS9cGrRJQGyp8dJNNz3xTpHv8QpW!-469065994!
1268681938...@192.168.131.143 - shared resource
mypac%3C/a%3E%3C/h4%3E%20%20%20%20%3Cdiv%20id= not found

2010/3/15 Jonas barney...@gmail.com

 I guess you use that panel somewhere on a page near a shared resource,
 maybe for an Image,
 have you tried debugging the rendering of that page?

 A side note, probably totally unrelated to your problem:
 having 'head' tags inside a wicket:panel will probably result in
 invalid html, you
 should consider using wicket:head instead (see:
 http://cwiki.apache.org/WICKET/wickets-xhtml-tags.html)

 cheers,
 Jonas

 On Mon, Mar 15, 2010 at 10:11 AM, Xavier López xavil...@gmail.com wrote:
  I agree it's not a classloader issue, the classloader is being given a
  cobbled class name, so it's not its fault it cannot load it.
 
  Is it possible that due to some serialization error the class name gets
  messed with the html markup, so that the class name read in
 deserialization
  ends messed up ?
 
  I don't see where can this be messing with comments, here is the markup
 file
  (the only one with fi usuari in it)
 
  html xmlns:wicket
  wicket:panel
  head
  script src=/accesnet/js/modal-message.js
 type=text/javascript/script
  /head
  !-- usuari --
  div id=usuari
 div class=caixaUser
 div class=userdades
 span class=waiwicket:message
  key=userpanel.nomusuari.wai//spanstrongspan
  wicket:id=nomUsuari/span/strongbr  /
 span class=noPopupa href=# wicket:id=linkEditUsuari
  wicket:message=title:userpanel.editusuari.titlewicket:message
  key=userpanel.editusuari.text//a/span
 span class=noPopupa href=# wicket:id=linkHomeAdmin
  wicket:message=title:userpanel.homeadmin.titlewicket:message
  key=userpanel.homeadmin.text//a/span
 /div
 div class=sessio
 spana href=# class=botoE cancela
  wicket:message=title:userpanel.fisessio.title
  wicket:id=linkFiSessiowicket:message
 key=userpanel.desconnecta/span
  class=waiwicket:message
  key=userpanel.fisessio.text.wai//span/a/span
 /div
 /div
  /div
  !-- fi usuari --
  /wicket:panel
  /html
 
 
  Thanks for all your responses !
  Xavier
 
  2010/3/14 Jonas barney...@gmail.com
 
  As stated in my previous mail, I really doubt this is a classloader
  issue, since the class name is
  'mypackage.MyClass-%20fi%20usuari%20--%3E%20%20%3C'
  which decodes to
  'mypackage.MyClass- fi usuari --  '
  which obviously isn't just a class name, but a class name
  plus some 'garbage', which will make any classloader choke.
 
  2010/3/13 François Meillet fm...@meillet.com:
   sounds like a classloading effect.
  
   Have a look to the classloader hierarchy
  
   Here is a good doc:
  
 
 http://download.oracle.com/docs/cd/E12840_01/wls/docs103/programming/classloading.html
  
   Especially this one : Resource Loading Order
  
 
 http://download.oracle.com/docs/cd/E12840_01/wls/docs103/programming/classloading.html#wp1097288
  
   François
  
  
   Le 12 mars 2010 à 17:30, Igor Vaynberg a écrit :
  
   ive seen this once before on the list. also with weblogic i think.
   search the list.
  
   -igor
  
   On Fri, Mar 12, 2010 at 3:16 AM, Xavier López xavil...@gmail.com
  wrote:
   Hi,
  
   From time to time I see the following error in my deployed
  application's
   log. The application is running clustered on Weblogic 9.2 MP3.
  
   It seems to be messing up with the classloading of class
  mypackage.MyClass
   (this error comes up in many different classes). I can guess from
 the
  stack
   trace that something is going wrong maybe

Re: Render a Wicket page to a string for HTML email

2010-03-16 Thread Xavier López
Here is another way I used when I was in need of this feature. This one
simulates a request cycle. I don't know if you could adapt this to fit your
needs (maybe doing the same, but with the real requestCycle instead) ?

http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/

Cheers,
Xavier

2010/3/16 rolandpeng rolandp...@cht.com.tw


 That works , thank you!
 But I have another question:
 when I use requestLogger.getLiveSessions() to get the live sessions,the
 number of sessions always increased after I call the render api.
 Is it possible to render page of html source in the same session(not create
 a new one)?
 Thank you!


 Scott Swank wrote:
 
  Here is a largely equivalent class that I created.  It simply extends
  BaseWicketTester.
 
  public class PageRenderer extends BaseWicketTester {
private final Locale locale;
 
public PageRenderer(Locale locale) {
this.locale = locale;
}
 
public PageRenderer() {
this.locale = null;
}
 
private String renderStartPage() {
if (this.locale != null) {
getWicketSession().setLocale(locale);
}
 
return getServletResponse().getDocument();
}
 
public synchronized String render(Class? extends WebPage
 pageClass) {
startPage(pageClass);
return renderStartPage();
}
 
public synchronized String render(Class? extends WebPage
 pageClass,
  PageParameters parameters) {
startPage(pageClass, parameters);
return renderStartPage();
}
 
public synchronized String render(WebPage page) {
startPage(page);
return renderStartPage();
}
 
  }
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 
 
 

 --
 View this message in context:
 http://old.nabble.com/Render-a-Wicket-page-to-a-string-for-HTML-email-tp20325702p27914411.html
 Sent from the Wicket - User 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




-- 
Klein bottle for rent--inquire within.


Re: Render a Wicket page to a string for HTML email

2010-03-16 Thread Xavier López
Oops, forgot to mention that code has a pair of bugs in it. Here is the
implementation i came up with :

public class RenderHTMLUtils {

public static String renderPage(Page page) {

//get the servlet context
WebApplication application = (WebApplication) WebApplication.get();

ServletContext context = application.getServletContext();

//fake a request/response cycle
MockHttpSession servletSession = new MockHttpSession(context);
servletSession.setTemporary(true);

MockHttpServletRequest servletRequest = new MockHttpServletRequest(
application, servletSession, context);
MockHttpServletResponse servletResponse = new
MockHttpServletResponse(
servletRequest);

//initialize request and response
servletRequest.initialize();
servletResponse.initialize();

WebRequest webRequest = new ServletWebRequest(servletRequest);

BufferedWebResponse webResponse = new
BufferedWebResponse(servletResponse);
webResponse.setAjax(true);

WebRequestCycle requestCycle = new WebRequestCycle(
application, webRequest, webResponse);

//requestCycle.setRequestTarget(new
BookmarkablePageRequestTarget(pageClass, pageParameters));
requestCycle.setRequestTarget(new PageRequestTarget(page));

try {
requestCycle.getProcessor().respond(requestCycle);

if (requestCycle.wasHandled() == false) {
requestCycle.setRequestTarget(new
WebErrorCodeResponseTarget(
HttpServletResponse.SC_NOT_FOUND));
}
requestCycle.detach();

} finally {
requestCycle.getResponse().close();
}

return webResponse.toString();
}

}

Cheers,
Xavier

2010/3/16 Xavier López xavil...@gmail.com

 Here is another way I used when I was in need of this feature. This one
 simulates a request cycle. I don't know if you could adapt this to fit your
 needs (maybe doing the same, but with the real requestCycle instead) ?


 http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/

 Cheers,
 Xavier

 2010/3/16 rolandpeng rolandp...@cht.com.tw


 That works , thank you!
 But I have another question:
 when I use requestLogger.getLiveSessions() to get the live sessions,the
 number of sessions always increased after I call the render api.
 Is it possible to render page of html source in the same session(not
 create
 a new one)?
 Thank you!


 Scott Swank wrote:
 
  Here is a largely equivalent class that I created.  It simply extends
  BaseWicketTester.
 
  public class PageRenderer extends BaseWicketTester {
private final Locale locale;
 
public PageRenderer(Locale locale) {
this.locale = locale;
}
 
public PageRenderer() {
this.locale = null;
}
 
private String renderStartPage() {
if (this.locale != null) {
getWicketSession().setLocale(locale);
}
 
return getServletResponse().getDocument();
}
 
public synchronized String render(Class? extends WebPage
 pageClass) {
startPage(pageClass);
return renderStartPage();
}
 
public synchronized String render(Class? extends WebPage
 pageClass,
  PageParameters parameters) {
startPage(pageClass, parameters);
return renderStartPage();
}
 
public synchronized String render(WebPage page) {
startPage(page);
return renderStartPage();
}
 
  }
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 
 
 

 --
 View this message in context:
 http://old.nabble.com/Render-a-Wicket-page-to-a-string-for-HTML-email-tp20325702p27914411.html
 Sent from the Wicket - User 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




 --
 Klein bottle for rent--inquire within.



Invoke method after onPopulate

2010-03-16 Thread Xavier López
Hi,

I have a ListView that build up a list of checks. These Checks have all to
be enabled or disabled depending on a bean's property. That property is
binded to a general checkbox (outside the listview). When the user changes
the selection on the main checkbox, the ones in the listview enable/disable.
Now, I see that I can't use the same method I use in the Ajax Behavior,
because at constructor time, the ListView has not been populated yet.

Is there a way to invoke a method after ListView' s onPopulate() ?
Is it a better approach to override isEnabled() on those Checks ? The bean
holding the property to decide it is large, I think I should use a binded
model in this case (getModel().bind(generalProperty), or the propertyModel
from the general checkbox).

Thanks,
Xavier


Re: ClassLoader (Serialization?) error

2010-03-15 Thread Xavier López
I agree it's not a classloader issue, the classloader is being given a
cobbled class name, so it's not its fault it cannot load it.

Is it possible that due to some serialization error the class name gets
messed with the html markup, so that the class name read in deserialization
ends messed up ?

I don't see where can this be messing with comments, here is the markup file
(the only one with fi usuari in it)

html xmlns:wicket
wicket:panel
head
script src=/accesnet/js/modal-message.js type=text/javascript/script
/head
!-- usuari --
div id=usuari
div class=caixaUser
div class=userdades
span class=waiwicket:message
key=userpanel.nomusuari.wai//spanstrongspan
wicket:id=nomUsuari/span/strongbr  /
span class=noPopupa href=# wicket:id=linkEditUsuari
wicket:message=title:userpanel.editusuari.titlewicket:message
key=userpanel.editusuari.text//a/span
span class=noPopupa href=# wicket:id=linkHomeAdmin
wicket:message=title:userpanel.homeadmin.titlewicket:message
key=userpanel.homeadmin.text//a/span
/div
div class=sessio
spana href=# class=botoE cancela
wicket:message=title:userpanel.fisessio.title
wicket:id=linkFiSessiowicket:message key=userpanel.desconnecta/span
class=waiwicket:message
key=userpanel.fisessio.text.wai//span/a/span
/div
/div
/div
!-- fi usuari --
/wicket:panel
/html


Thanks for all your responses !
Xavier

2010/3/14 Jonas barney...@gmail.com

 As stated in my previous mail, I really doubt this is a classloader
 issue, since the class name is
 'mypackage.MyClass-%20fi%20usuari%20--%3E%20%20%3C'
 which decodes to
 'mypackage.MyClass- fi usuari --  '
 which obviously isn't just a class name, but a class name
 plus some 'garbage', which will make any classloader choke.

 2010/3/13 François Meillet fm...@meillet.com:
  sounds like a classloading effect.
 
  Have a look to the classloader hierarchy
 
  Here is a good doc:
 
 http://download.oracle.com/docs/cd/E12840_01/wls/docs103/programming/classloading.html
 
  Especially this one : Resource Loading Order
 
 http://download.oracle.com/docs/cd/E12840_01/wls/docs103/programming/classloading.html#wp1097288
 
  François
 
 
  Le 12 mars 2010 à 17:30, Igor Vaynberg a écrit :
 
  ive seen this once before on the list. also with weblogic i think.
  search the list.
 
  -igor
 
  On Fri, Mar 12, 2010 at 3:16 AM, Xavier López xavil...@gmail.com
 wrote:
  Hi,
 
  From time to time I see the following error in my deployed
 application's
  log. The application is running clustered on Weblogic 9.2 MP3.
 
  It seems to be messing up with the classloading of class
 mypackage.MyClass
  (this error comes up in many different classes). I can guess from the
 stack
  trace that something is going wrong maybe serializing that page, it can
 be
  seen that the class name is being messed with some content of the page
 (div
  tags, text displayed in the page,...).
 
  Has anyone been in this situation before ? Any tip on how to address
 the
  issue ?
 
  2010-03-11 22:31:10,506 ERROR ap16_s1_IX_II [[ACTIVE] ExecuteThread:
 '2' for
  queue: 'weblogic.kernel.Default (self-tuning)']
  org.apache.wicket.request.target.resource.SharedResourceRequestTarget
  579910|vJS0LZhR01NKqxLWh6QbpWm77g3jHJ96Y4GYV6KB996NfHnHLb5t!-619140133!
  1268343057...@192.168.131.142 - unable to lazily register shared
 resource
  mypackage.MyClass%20fi%20usuari%20--%3E%20%20%3C/div%3E%3Cdiv%20id=
  java.lang.ClassNotFoundException:
  mypackage.MyClass-%20fi%20usuari%20--%3E%20%20%3C
 at
 
 weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:289)
 at
 
 weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:262)
 at
 
 weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:54)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
 at
 
 weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:161)
 at
 
 weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:35)
 at
 
 org.apache.wicket.application.DefaultClassResolver.resolveClass(DefaultClassResolver.java:103)
 at
 
 org.apache.wicket.request.target.resource.SharedResourceRequestTarget.respond(SharedResourceRequestTarget.java:149)
 at
 
 org.apache.wicket.request.AbstractRequestCycleProcessor.respond(AbstractRequestCycleProcessor.java:104)
 at
 
 org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1181)
 at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252)
 at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353)
 at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
 at
 
 org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355)
 at
 
 org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:200

ClassLoader (Serialization?) error

2010-03-12 Thread Xavier López
Hi,

From time to time I see the following error in my deployed application's
log. The application is running clustered on Weblogic 9.2 MP3.

It seems to be messing up with the classloading of class mypackage.MyClass
(this error comes up in many different classes). I can guess from the stack
trace that something is going wrong maybe serializing that page, it can be
seen that the class name is being messed with some content of the page (div
tags, text displayed in the page,...).

Has anyone been in this situation before ? Any tip on how to address the
issue ?

2010-03-11 22:31:10,506 ERROR ap16_s1_IX_II [[ACTIVE] ExecuteThread: '2' for
queue: 'weblogic.kernel.Default (self-tuning)']
org.apache.wicket.request.target.resource.SharedResourceRequestTarget
579910|vJS0LZhR01NKqxLWh6QbpWm77g3jHJ96Y4GYV6KB996NfHnHLb5t!-619140133!
1268343057...@192.168.131.142 - unable to lazily register shared resource
mypackage.MyClass%20fi%20usuari%20--%3E%20%20%3C/div%3E%3Cdiv%20id=
java.lang.ClassNotFoundException:
mypackage.MyClass-%20fi%20usuari%20--%3E%20%20%3C
at
weblogic.utils.classloaders.GenericClassLoader.findLocalClass(GenericClassLoader.java:289)
at
weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClassLoader.java:262)
at
weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAwareClassLoader.java:54)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at
weblogic.utils.classloaders.GenericClassLoader.loadClass(GenericClassLoader.java:161)
at
weblogic.utils.classloaders.ChangeAwareClassLoader.loadClass(ChangeAwareClassLoader.java:35)
at
org.apache.wicket.application.DefaultClassResolver.resolveClass(DefaultClassResolver.java:103)
at
org.apache.wicket.request.target.resource.SharedResourceRequestTarget.respond(SharedResourceRequestTarget.java:149)
at
org.apache.wicket.request.AbstractRequestCycleProcessor.respond(AbstractRequestCycleProcessor.java:104)
at
org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1181)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1252)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1353)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
at
org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:355)
at
org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:200)
at mypacakge.MyFilter.doFilter(ANetFilter.java:37)
at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3242)
at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at
weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2010)
at
weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1916)
at
weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1366)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
2010-03-11 22:31:10,511 ERROR ap16_s1_IX_II [[ACTIVE] ExecuteThread: '2' for
queue: 'weblogic.kernel.Default (self-tuning)']
org.apache.wicket.request.target.resource.SharedResourceRequestTarget
579910|vJS0LZhR01NKqxLWh6QbpWm77g3jHJ96Y4GYV6KB996NfHnHLb5t!-619140133!
1268343057...@192.168.131.142 - shared resource
mypackage.MyClass-%20fi%20usuari%20--%3E%20%20%3C/div%3E%3Cdiv%20id= not
found

Thanks,
Xavier


Model Comparator

2010-03-05 Thread Xavier López
Hi,

I have a checkbox. The checkbox's Model is a PropertyModel, on a property
that can be either a Boolean or a String, with values {S, N}. And I want to
set the user and date in which the checkbox's model has changed, in order to
provide traceability. The checkbox is using an implementation of IConverter
when it's about Strings and the standard BooleanConverter otherwise.

Now, the problem is, the value with which the checkbox is initialized *can*
be null, if it has never been set. So, I can not rely on implementing
'onModelChanged()' because it will always fire the first time (in fact,
having null value would be the same as having negative value as far as this
requirement is concerned)

I've tried different approaches, and I finally came up with the one that
seems more logical to me, as it is close to a translation of what I've
stated before. I'm overriding onModelChanged(), and implementing a custom
IModelComparator, so that onModelChanged does not fire when changing value
from null to 'nonselected'.

Here follows the implementation. My question is, can't my custom comparison
be implemented in a simpler way ? I can't get component.getInput(), because
it's only a Component. And I'd not like to implement a util method to return
a boolean from the ModelObject, doing instanceof's...

Maybe I'm asking too much :-)


public boolean compare(Component component, Object compareValue)
{
final Object currentValue = component.getModelObject();
if (currentValue == null  compareValue == null) {
return true;
}
if (currentValue == null || compareValue == null) {
return false;
}

// MY CUSTOM COMPARISON: Null value equals not checking the
checkbox
if (currentValue == null 
!Strings.isTrue(component.getConverter(compareValue.getClass()).convertToString(compareValue,
component.getLocale({
return false;
}
else{
return currentValue.equals(compareValue);
}
}


Thanks ! feel free to comment :-)


Re: CompoundPropertyModel issue

2010-03-03 Thread Xavier López
Strange. I thought the component only searches parents for a CPM if and only
if its model is null.

Have you tried doing approvalofficers.setModel(new Model()); ?
Maybe EmployeeDropDownChoice is nulling the model somewhere in the
constructor (calling proper super() ? ).

Cheers
Xavier

2010/3/3 chinedu efoagui chinedub...@gmail.com

 I tried that.still did not work? Any other ideas
 rg.apache.wicket.WicketRuntimeException: No get method defined for
 class: class com.mw.hr.entity.leaveappempleave.LeaveappEmpleave
 expression: approvaloficer
at
 org.apache.wicket.util.lang.PropertyResolver.getGetAndSetter(PropertyResolver.java:445)


 On Tue, Mar 2, 2010 at 5:29 PM, Xavier López xavil...@gmail.com wrote:
  I think the Model you are passing to the constructor refers to the
 choices
  Model. Try using EmployeeDropDownChoice(approvaloficer,new Model(), new
  Model());
 
  Cheers,
  Xavier
 
  2010/3/2 chinedu efoagui chinedub...@gmail.com
 
  hello,
 
  i am added a dropdownchoice to a form. The form's model is set to a
  CompoundPropertyModel
  as shown below
  IModel zaModel=new CompoundPropertyModel(selected);
  leaveform.setModel(zaModel);
 
  Now the dropdown shows a list of Employees
 
  EmployeeDropDownChoice approvalofficers=new
  EmployeeDropDownChoice(approvaloficer,new Model());
 leaveform.add(approvalofficers);
  Now when I run it gives me error that it can find the getter property
  of component approvaloficer
  Now the thing is the component is
  So how do i exclude the component from the CompoundPropertyModel and
  still have  it show ?
  I thought i could achieve that with by passing an emppty model into
  its constructor like new model?
  how do i solve this??
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 
 
 
 
  --
  Klein bottle for rent--inquire within.
 

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




Re: CompoundPropertyModel issue

2010-03-02 Thread Xavier López
I think the Model you are passing to the constructor refers to the choices
Model. Try using EmployeeDropDownChoice(approvaloficer,new Model(), new
Model());

Cheers,
Xavier

2010/3/2 chinedu efoagui chinedub...@gmail.com

 hello,

 i am added a dropdownchoice to a form. The form's model is set to a
 CompoundPropertyModel
 as shown below
 IModel zaModel=new CompoundPropertyModel(selected);
 leaveform.setModel(zaModel);

 Now the dropdown shows a list of Employees

 EmployeeDropDownChoice approvalofficers=new
 EmployeeDropDownChoice(approvaloficer,new Model());
leaveform.add(approvalofficers);
 Now when I run it gives me error that it can find the getter property
 of component approvaloficer
 Now the thing is the component is
 So how do i exclude the component from the CompoundPropertyModel and
 still have  it show ?
 I thought i could achieve that with by passing an emppty model into
 its constructor like new model?
 how do i solve this??

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




-- 
Klein bottle for rent--inquire within.


Wicket Ajax Channels

2010-02-27 Thread Xavier López
I've been facing a scenario where AJAX requests processing times were
abnormally elevated. That situation has already been fixed (problem of
AppServer configuration), but meanwhile, I was looking for some way to avoid
queueing all requests, in a way such that only the last request should be
processed (a good example would be an AutoComplete textfield).

I found this post
http://old.nabble.com/Discard-queued-ajax-requests-td27140816.html, on the
same issue. The post states that using |d at the end of the ajax channel
does the job. However, the only way I know to specify the channel is by
making ajax calls from my code (js functions WicketAjaxGet/Post). There are
some questions that pop up off my head, just out of curiosity:

Is it possible to specifiy that channel, let's say, in an AjaxBehavior ?
Looking through wicket-ajax.js i've seen the channel is defaulted to 0|s.
What does that |s mean ?

Is there any documentation on the flags like can (or seem to) be added to
the channel ?

Thanks!
Xavier


Re: Wicket Ajax Channels

2010-02-27 Thread Xavier López
Thanks Daniel, didn't notice AbstractDefaultAjaxBehavior.getChannelName().
Not that I needed it, just curious. About the channel modes, that's what I
supposed, just wanted to be sure I'm not missing any possibly interesting
features.

And thanks for the post 'Discard queued Ajax Requests ;-)

2010/2/27 Daniel Frisk dan...@jalbum.net

 Hello Xavier,

 you can override AbstractDefaultAjaxBehavior.getChannelName() to return
 something|d and the channel will switch to drop behavior. I'm still using
 1.3 so it may be different in 1.4.

 I've seen no documentation other than the code itself, but if my memory
 serves me right there are no other options.

 // Daniel
 jalbum.net


 On 27 feb 2010, at 13:59, Xavier López wrote:

  I've been facing a scenario where AJAX requests processing times were
  abnormally elevated. That situation has already been fixed (problem of
  AppServer configuration), but meanwhile, I was looking for some way to
 avoid
  queueing all requests, in a way such that only the last request should be
  processed (a good example would be an AutoComplete textfield).
 
  I found this post
  http://old.nabble.com/Discard-queued-ajax-requests-td27140816.html, on
 the
  same issue. The post states that using |d at the end of the ajax
 channel
  does the job. However, the only way I know to specify the channel is by
  making ajax calls from my code (js functions WicketAjaxGet/Post). There
 are
  some questions that pop up off my head, just out of curiosity:
 
  Is it possible to specifiy that channel, let's say, in an AjaxBehavior ?
  Looking through wicket-ajax.js i've seen the channel is defaulted to
 0|s.
  What does that |s mean ?
 
  Is there any documentation on the flags like can (or seem to) be added to
  the channel ?
 
  Thanks!
  Xavier


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




-- 
Klein bottle for rent--inquire within.


InspectorBug on 1.3.5

2010-01-07 Thread Xavier López
Hi,

I'm trying to use the InspectorBug in wicket 1.3.5. I extracted it from the
wicket-examples source code.
The problem is, every page is treated as stateless, soI can get no
information on component's models. I get info on Application and Session,
but about the Pages, debugging through the code I find out that the problem
is that the page never gets an Id (Page.getId()) so the IPageMapEntry can be
retrieved...

public InspectorBug(final String id, final WebPage page)
{
super(id);
PageParameters parameters = new PageParameters();
parameters.put(pageId, page.getId());
Link link = new BookmarkablePageLink(link, InspectorPage.class,
parameters);
link.add(new Image(bug));
add(link);
}

public InspectorPage(final PageParameters parameters)
{
add(new ApplicationView(application, Application.get()));
add(new SessionView(session, Session.get()));
IPageMapEntry entry = null;
try
{
entry = getPageMap().getEntry(parameters.getInt(pageId));
}
catch (StringValueConversionException e)
{
// Ignore
}
add(new PageView(page, entry == null ? null : entry.getPage()));
add(new Image(bug));
add(new BookmarkablePageLink(allsessions,
LiveSessionsPage.class));
add(new Label(wicketVersion,
getApplication().getFrameworkSettings().getVersion()));
}

I also noticed that Page.setId() is only called when the Page is put into
the PageMap (which makes sense, and is also stated by the comments on Page's
constructors)
// A Page's id is not determined until setId is called when the
Page is
// added to a PageMap in the Session.

I suppose this is not working because in InspectorBug's construction, the
page isn't in the pagemap yet, so it has no id.
Is there any workaround to get the InspectorBug panel working ?

Cheers,
Xavier


Re: Parameterized Component

2009-12-15 Thread Xavier López
Thanks for the replies.

CPM has been working fine for me. Although what Martin says is true, I've
been reducing that in my CPM's by means of public static final variables on
the bean's classes. Just fields with the name of fields (sort of class
meta-info). Then using those fields as wicket:id's...

However, the topic of the post is a real limitation about CPM's and I'll be
using PropertyModels instead, although the new solution looks great ;)


2009/12/15 Martin Makundi martin.maku...@koodaripalvelut.com

  so you where talking about property models in general (not the compound)
 
  We have a solution for that now

 No. Property models can use constants or the new solution. But there
 is no solution for compound property models, yet. Unless someone knows
 how to make the compiler chew html wicket:id's too, which would be
 nice.

 my 2cents

 **
 Martin

 
  On Tue, Dec 15, 2009 at 11:25, Martin Makundi 
  martin.maku...@koodaripalvelut.com wrote:
 
  Yes, but it ties your beans to wicket ids. More refactoring and
  maintenance work.
 
  Anyways, if it works for you, use it.
 
  my 2cents
 
  **
  Martin
 
  2009/12/15 Johan Compagner jcompag...@gmail.com:
   why not
   it kills a lot of code.
  
  
   On Mon, Dec 14, 2009 at 17:45, Martin Makundi 
   martin.maku...@koodaripalvelut.com wrote:
  
   I wouldn't use CPM for anything serious anyways...
  
   my 2cents
  
   **
   Martin
  
   2009/12/14 Xavier López xavil...@gmail.com:
Hi,
   
In my application I have a number of fields that allow validation,
 by
   means
of a validation CheckBox. In order to provide some flexibility for
  this
   kind
of validation fields, I'd like to have them implemented in a
 Component
   (i.e.
ValidationTickPanel), so that they provide their own markup and
 other
   panels
using it should not know about its contents. ValidationTickPanel
  extends
Panel in order to be able to provide own markup.
   
The problem is, I'd like to have the CheckBox's wicket:id set from
 the
parent panel (in order to use CompoundPropertyModel). But I'm
 afraid
  that
it's impossible to have a variable wicket_id inside
ValidationTickPanel.html...
   
public class ValidationTick extends Panel implements
  RestrictedComponent
   {
   public ValidationTick(String componentId, String checkId, IModel
checkModel){
   super(componentId);
   CheckBox check =  new CheckBox(checkId, checkModel);
   Label label = new Label(checkId+Label, new
StringResourceModel());
   add(check);
   add(label);
   }
}
   
wicket:panel
   input type=checkbox wicket:id=???/input
   span wicket:id=???Label/span
/wicket:panel
   
Usually, checkModel would be null as the goal would be to use
compoundPropertyModel on the checkBox..My question is, is it
 possible
  to
achieve this ? Or should I be discarding the CPM idea and passing
 for
instance a PropertyModel to ValidationTickPanel ?
   
Thanks a lot,
Xavier
   
  
   -
   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
 
 
 

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




-- 
Klein bottle for rent--inquire within.


Parameterized Component

2009-12-14 Thread Xavier López
Hi,

In my application I have a number of fields that allow validation, by means
of a validation CheckBox. In order to provide some flexibility for this kind
of validation fields, I'd like to have them implemented in a Component (i.e.
ValidationTickPanel), so that they provide their own markup and other panels
using it should not know about its contents. ValidationTickPanel extends
Panel in order to be able to provide own markup.

The problem is, I'd like to have the CheckBox's wicket:id set from the
parent panel (in order to use CompoundPropertyModel). But I'm afraid that
it's impossible to have a variable wicket_id inside
ValidationTickPanel.html...

public class ValidationTick extends Panel implements RestrictedComponent {
public ValidationTick(String componentId, String checkId, IModel
checkModel){
super(componentId);
CheckBox check =  new CheckBox(checkId, checkModel);
Label label = new Label(checkId+Label, new
StringResourceModel());
add(check);
add(label);
}
}

wicket:panel
input type=checkbox wicket:id=???/input
span wicket:id=???Label/span
/wicket:panel

Usually, checkModel would be null as the goal would be to use
compoundPropertyModel on the checkBox..My question is, is it possible to
achieve this ? Or should I be discarding the CPM idea and passing for
instance a PropertyModel to ValidationTickPanel ?

Thanks a lot,
Xavier


CachingPage

2009-12-10 Thread Xavier López
Hi,

I'm trying to adapt the 'CachingPanel' strategy from JL's '26 Wicket Tricks'
to a Page, in order to cache an entire HomePage. It is a requirement that
this Page (it is a HomePage) should be rendered like it was static HTML
(actually the application generated that static html at some moment by means
of templates).

This is the source for CachingPanel from GoogleCode:

http://www.google.com/codesearch/p?hl=es#92PP5HImtBs/trunk/twenty-six-wicket-tricks/src/main/java/com/locke/library/web/panels/caching/CachingPanel.javaq=caching%20package:http://twenty-six-wicket-tricks
\.googlecode\.comsa=Ncd=1ct=rct=0

I've tried to simply extend WebPage instead of Panel in CachingPanel, but
then it turns out in onRender's overriding that markupStream is always
null... My question is: Is onRender the right method to override taking
into account it is about a whole page and not a Panel
(markupStream.skipComponent does not make much sense)...

I'd appreciate any directions on these one, as this matter is regarding the
internals of Wicket, and I'd like to have some security on what's happening
behind the scenes...

Thank you very much !


Re: Component.setLabel and label tags

2009-11-26 Thread Xavier López
Just found out a component that does what I proposed below more cleanly:
SimpleFormComponentLabel.
I'll finally be using this component, and seize the opportunity to insert
automatically the 'required' textflag (*):

public class MyLabel extends SimpleFormComponentLabel {

String mandatory = ;

public MyLabel(String id, final LabeledWebMarkupContainer labelProvider) {
super(id, labelProvider);
boolean required = false;
if (labelProvider instanceof FormComponent){
required = ((FormComponent)labelProvider).isRequired();
}
if (required){
mandatory = nbsp; + new
StringResourceModel(MyHelper.KEY_MANDATORY_FIELD,labelProvider,
null).getString();
}
}
protected void onComponentTagBody(final MarkupStream markupStream, final
ComponentTag openTag)
{
replaceComponentTagBody(markupStream, openTag,
getModelObjectAsString() + mandatory);
}
}


2009/11/26 Martijn Dashorst martijn.dasho...@gmail.com

 s/getDefaultModelObjectAsString/getModelObjectAsString/...

 On Wed, Nov 25, 2009 at 5:29 PM, Xavier López xavil...@gmail.com wrote:
  Thanks anyway Pedro, it's a good insight, and pretty original ;-) Didn't
  think of it, nor knew about visitors...
 
  Sadly, I'm on Wicket 1.3.5 and it wouldn't be working anyway, as
  MarkupContainer does not seem to provide '
  getDefaultModelObjectAsString', apart from what you said about
  MessageContainer...
 
  Just out of curiosity, wouldn't it be possible to do that traversal
 upwards
  (from formComponent to Form) ?
  And I suppose the wicket:message tags get converted somehow to these
  MessageContainers (which are tried to localize in the visitor by means of
  _message_ in its id)
 
  Thanks,
  Xavier
 
 
  2009/11/25 Pedro Santos pedros...@gmail.com
 
  ops, I just see: if you have an form with more than one form componente,
  that behavior will not work. So, it was just an idea :)
 
  On Wed, Nov 25, 2009 at 2:13 PM, Pedro Santos pedros...@gmail.com
 wrote:
 
   Possible alternative that will work on current wicket version, since
   MessageContainer is an private inner class
  
   public class AdjustLabel extends AbstractBehavior
   {
   @Override
   public void beforeRender(Component component)
   {
   if (component instanceof FormComponent)
   {
   final FormComponent formComponent =
   (FormComponent)component;
  
  component.getParent().visitChildren(MarkupContainer.class,
   new IVisitorMarkupContainer()
   {
  
   public Object component(MarkupContainer
   component)
   {
   if
   (component.getId().startsWith(_message_))
   {
   formComponent.setLabel(new
   ResourceModel(component
  
   .getDefaultModelObjectAsString()));
   return IVisitor.STOP_TRAVERSAL;
   }
   else
   {
   return null;
   }
   }
   });
   }
   }
   }
  
   then you set:
  
   input.add(new AdjustLabel());
  
  
   On Wed, Nov 25, 2009 at 1:51 PM, Xavier López xavil...@gmail.com
  wrote:
  
   I forgot,
  
   A possible solution would be using a shared StringResourceModel for
 both
   the
   setLabel() method and providing the label tag like this:
  
   label wicket:id=labelXspan
 wicket:id=labelXText/span/label
  
   StringResourceModel m = new StringResourceModel(form.x.label, this,
   null);
   x.setLabel(m);
   FormComponentLabel labelX = new FormComponentLabel(labelX, x);
   form.add(labelX);
   Label labelXText = new Label(labelXText, m);
  
   But I'm looking for a less intrusive solution on pages already
   developed...
  
   Thanks,
   Xavier
  
   -- Forwarded message --
   From: Xavier López xavil...@gmail.com
   Date: 2009/11/25
   Subject: Component.setLabel and label tags
   To: users@wicket.apache.org
  
  
   Hi,
  
   In a form, I have multiple fields each one with its corresponding
   FormComponentLabel, with proper wicket:message content in the
 markup
   file.
   Now, I'm facing the fact that I need to provide the same keys I
 provided
   in
   wicket:message in a StringResourceModel in component's setLabel()
   method.
  
   Although I'm aware it's not straightforward (setLabel requires a
 Model,
   and
   label's body is just body markup), it would be great if there was
 some
   way
   to avoid this duplication telling Wicket to use the same key provided
 in
   the
   FormComponentLabel's body...
  
   Does anyone have a hint ?
  
   Thanks,
   Xavier
  
  
  
  
   --
   Klein bottle for rent--inquire within

Component.setLabel and label tags

2009-11-25 Thread Xavier López
Hi,

In a form, I have multiple fields each one with its corresponding
FormComponentLabel, with proper wicket:message content in the markup file.
Now, I'm facing the fact that I need to provide the same keys I provided in
wicket:message in a StringResourceModel in component's setLabel() method.

Although I'm aware it's not straightforward (setLabel requires a Model, and
label's body is just body markup), it would be great if there was some way
to avoid this duplication telling Wicket to use the same key provided in the
FormComponentLabel's body...

Does anyone have a hint ?

Thanks,
Xavier


Component.setLabel and label tags

2009-11-25 Thread Xavier López
I forgot,

A possible solution would be using a shared StringResourceModel for both the
setLabel() method and providing the label tag like this:

label wicket:id=labelXspan wicket:id=labelXText/span/label

StringResourceModel m = new StringResourceModel(form.x.label, this, null);
x.setLabel(m);
FormComponentLabel labelX = new FormComponentLabel(labelX, x);
form.add(labelX);
Label labelXText = new Label(labelXText, m);

But I'm looking for a less intrusive solution on pages already developed...

Thanks,
Xavier

-- Forwarded message --
From: Xavier López xavil...@gmail.com
Date: 2009/11/25
Subject: Component.setLabel and label tags
To: users@wicket.apache.org


Hi,

In a form, I have multiple fields each one with its corresponding
FormComponentLabel, with proper wicket:message content in the markup file.
Now, I'm facing the fact that I need to provide the same keys I provided in
wicket:message in a StringResourceModel in component's setLabel() method.

Although I'm aware it's not straightforward (setLabel requires a Model, and
label's body is just body markup), it would be great if there was some way
to avoid this duplication telling Wicket to use the same key provided in the
FormComponentLabel's body...

Does anyone have a hint ?

Thanks,
Xavier




-- 
Klein bottle for rent--inquire within.


Re: Component.setLabel and label tags

2009-11-25 Thread Xavier López
Thanks anyway Pedro, it's a good insight, and pretty original ;-) Didn't
think of it, nor knew about visitors...

Sadly, I'm on Wicket 1.3.5 and it wouldn't be working anyway, as
MarkupContainer does not seem to provide '
getDefaultModelObjectAsString', apart from what you said about
MessageContainer...

Just out of curiosity, wouldn't it be possible to do that traversal upwards
(from formComponent to Form) ?
And I suppose the wicket:message tags get converted somehow to these
MessageContainers (which are tried to localize in the visitor by means of
_message_ in its id)

Thanks,
Xavier


2009/11/25 Pedro Santos pedros...@gmail.com

 ops, I just see: if you have an form with more than one form componente,
 that behavior will not work. So, it was just an idea :)

 On Wed, Nov 25, 2009 at 2:13 PM, Pedro Santos pedros...@gmail.com wrote:

  Possible alternative that will work on current wicket version, since
  MessageContainer is an private inner class
 
  public class AdjustLabel extends AbstractBehavior
  {
  @Override
  public void beforeRender(Component component)
  {
  if (component instanceof FormComponent)
  {
  final FormComponent formComponent =
  (FormComponent)component;
 
 component.getParent().visitChildren(MarkupContainer.class,
  new IVisitorMarkupContainer()
  {
 
  public Object component(MarkupContainer
  component)
  {
  if
  (component.getId().startsWith(_message_))
  {
  formComponent.setLabel(new
  ResourceModel(component
 
  .getDefaultModelObjectAsString()));
  return IVisitor.STOP_TRAVERSAL;
  }
  else
  {
  return null;
  }
  }
  });
  }
  }
  }
 
  then you set:
 
  input.add(new AdjustLabel());
 
 
  On Wed, Nov 25, 2009 at 1:51 PM, Xavier López xavil...@gmail.com
 wrote:
 
  I forgot,
 
  A possible solution would be using a shared StringResourceModel for both
  the
  setLabel() method and providing the label tag like this:
 
  label wicket:id=labelXspan wicket:id=labelXText/span/label
 
  StringResourceModel m = new StringResourceModel(form.x.label, this,
  null);
  x.setLabel(m);
  FormComponentLabel labelX = new FormComponentLabel(labelX, x);
  form.add(labelX);
  Label labelXText = new Label(labelXText, m);
 
  But I'm looking for a less intrusive solution on pages already
  developed...
 
  Thanks,
  Xavier
 
  -- Forwarded message --
  From: Xavier López xavil...@gmail.com
  Date: 2009/11/25
  Subject: Component.setLabel and label tags
  To: users@wicket.apache.org
 
 
  Hi,
 
  In a form, I have multiple fields each one with its corresponding
  FormComponentLabel, with proper wicket:message content in the markup
  file.
  Now, I'm facing the fact that I need to provide the same keys I provided
  in
  wicket:message in a StringResourceModel in component's setLabel()
  method.
 
  Although I'm aware it's not straightforward (setLabel requires a Model,
  and
  label's body is just body markup), it would be great if there was some
  way
  to avoid this duplication telling Wicket to use the same key provided in
  the
  FormComponentLabel's body...
 
  Does anyone have a hint ?
 
  Thanks,
  Xavier
 
 
 
 
  --
  Klein bottle for rent--inquire within.
 
 
 
 
  --
  Pedro Henrique Oliveira dos Santos
 



 --
 Pedro Henrique Oliveira dos Santos




-- 
Klein bottle for rent--inquire within.


Re: StringResourceModel referencing another component

2009-11-19 Thread Xavier López
I've been trying to retrieve the panel's resource, using getLocalizer and
ComponentStringResourceLoader in the following ways:

button1.setModel(new AbstractReadOnlyModel(){
public Object getObject(){
// Attempt 1
return panel.getLocalizer().getString(button1.label, panel);
// Attempt 2
return new ComponentStringResourceLoader().loadStringResource(panel,
button1.label);
}
});

But I've been never been able to get the resource from the panel.
I suppose the matter of it all is that I'm trying to get the resource from
the parent component, so StringResourceModel and derivates start trying to
retrieve it at the invoker's level...

Would it be better to get the label from the component, let's say, by means
of an overridable method on MyTabPanel ?

Thanks,
Xavier


2009/11/17 Igor Vaynberg igor.vaynb...@gmail.com

 you can write your own model that first tries to get the resource from
 the panel and then falls back.

 -igor

 On Tue, Nov 17, 2009 at 2:58 AM, Xavier López xavil...@gmail.com wrote:
  Hi,
 
  I've set up a custom MyTabbedPanel by modifying class TabbedPanel. It
 will
  include a row of buttons, added on setSelectedTab which will be the same
 for
  all tabs.
  Now, I'd like each tab (panel) to be able to override the text of each
  button, like this:
 
  public final void setSelectedTab(int index){
  ...
  // Add Panel with content for the tab to global form variable
  final MyTabPanel panel = tabs.get(index).getPanel(TAB_PANEL_ID);
  form.addOrReplace(panel);
  // Add generic buttons to form, with specific settings depending on
 panel's
  properties
  Button button1 = new Button(button1){ ... };
  button1.setModel(new StringResourceModel(button1.label,panel, null));
  form.addOrReplace(button1);
  ...
  }
 
  The problem is that the StringResourceModel is always pointing to the
  property in MyTabbedPanel.xml, and not the panel's.
  I've noticed that if I remove button1.label from MyTabbedPanel's
 property
  file, Wicket gets the panel's button1.label property, but I'd like to
  provide some kind of 'default' label for the buttons so that panels
 aren't
  forced to explicitly define this property.
 
  I expected specifying the 'panel' component on StringResourceModel's
  constructor would do the trick, but it doesn't work. Is it possible to
  accomplish what I'm trying to do ?
 
  Thanks,
  Xavier
 

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




Re: StringResourceModel referencing another component

2009-11-19 Thread Xavier López
Awesome!

I didn't know about Component.getString(). I had it in front of me all the
time (you can label me newbie).
It's amazing how easy things are in Wicket when you know how to deal with
them.

Thank you Igor :)

2009/11/19 Igor Vaynberg igor.vaynb...@gmail.com

 you should be using getstring() on the component instead of
 getlocalizer().getstring(), simpler, but anyways...

 why not simply:

 class componentresourcemodel extends abstractreadonlymodelstring {
  private final component c;
  private final string key;
  public componentresourcemodel(component c, string key) {
 this.c=c;this.key=key; }
  public string getobject() { return c.getstring(key); }
 }

 -igor

 On Thu, Nov 19, 2009 at 7:30 AM, Xavier López xavil...@gmail.com wrote:
  I've been trying to retrieve the panel's resource, using getLocalizer and
  ComponentStringResourceLoader in the following ways:
 
  button1.setModel(new AbstractReadOnlyModel(){
  public Object getObject(){
  // Attempt 1
  return panel.getLocalizer().getString(button1.label, panel);
  // Attempt 2
  return new ComponentStringResourceLoader().loadStringResource(panel,
  button1.label);
  }
  });
 
  But I've been never been able to get the resource from the panel.
  I suppose the matter of it all is that I'm trying to get the resource
 from
  the parent component, so StringResourceModel and derivates start trying
 to
  retrieve it at the invoker's level...
 
  Would it be better to get the label from the component, let's say, by
 means
  of an overridable method on MyTabPanel ?
 
  Thanks,
  Xavier
 
 
  2009/11/17 Igor Vaynberg igor.vaynb...@gmail.com
 
  you can write your own model that first tries to get the resource from
  the panel and then falls back.
 
  -igor
 
  On Tue, Nov 17, 2009 at 2:58 AM, Xavier López xavil...@gmail.com
 wrote:
   Hi,
  
   I've set up a custom MyTabbedPanel by modifying class TabbedPanel. It
  will
   include a row of buttons, added on setSelectedTab which will be the
 same
  for
   all tabs.
   Now, I'd like each tab (panel) to be able to override the text of each
   button, like this:
  
   public final void setSelectedTab(int index){
   ...
   // Add Panel with content for the tab to global form variable
   final MyTabPanel panel = tabs.get(index).getPanel(TAB_PANEL_ID);
   form.addOrReplace(panel);
   // Add generic buttons to form, with specific settings depending on
  panel's
   properties
   Button button1 = new Button(button1){ ... };
   button1.setModel(new StringResourceModel(button1.label,panel,
 null));
   form.addOrReplace(button1);
   ...
   }
  
   The problem is that the StringResourceModel is always pointing to the
   property in MyTabbedPanel.xml, and not the panel's.
   I've noticed that if I remove button1.label from MyTabbedPanel's
  property
   file, Wicket gets the panel's button1.label property, but I'd like
 to
   provide some kind of 'default' label for the buttons so that panels
  aren't
   forced to explicitly define this property.
  
   I expected specifying the 'panel' component on StringResourceModel's
   constructor would do the trick, but it doesn't work. Is it possible to
   accomplish what I'm trying to do ?
  
   Thanks,
   Xavier
  
 
  -
  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




-- 
Klein bottle for rent--inquire within.


Re: StringResourceModel referencing another component

2009-11-19 Thread Xavier López
I maintain what I stated below, but ehem this one is not working.

In the end, I've decided to change the key's name in case there doesn't
exist the desired resource in the panel, like this:

public String getObject() {
String ret = c.getString(key);
if (ret == null){
ret = c.getString(key+.default);
}
return ret;
}

MyTabbedPanel contains keys button1.label.default and panel's can define
button1.label if they need to.

Thanks anyway :-)
Xavier

2009/11/19 Xavier López xavil...@gmail.com

 Awesome!

 I didn't know about Component.getString(). I had it in front of me all the
 time (you can label me newbie).
 It's amazing how easy things are in Wicket when you know how to deal with
 them.

 Thank you Igor :)

 2009/11/19 Igor Vaynberg igor.vaynb...@gmail.com

 you should be using getstring() on the component instead of
 getlocalizer().getstring(), simpler, but anyways...

 why not simply:

 class componentresourcemodel extends abstractreadonlymodelstring {
  private final component c;
  private final string key;
  public componentresourcemodel(component c, string key) {
 this.c=c;this.key=key; }
  public string getobject() { return c.getstring(key); }
 }

 -igor

 On Thu, Nov 19, 2009 at 7:30 AM, Xavier López xavil...@gmail.com wrote:
  I've been trying to retrieve the panel's resource, using getLocalizer
 and
  ComponentStringResourceLoader in the following ways:
 
  button1.setModel(new AbstractReadOnlyModel(){
  public Object getObject(){
  // Attempt 1
  return panel.getLocalizer().getString(button1.label, panel);
  // Attempt 2
  return new ComponentStringResourceLoader().loadStringResource(panel,
  button1.label);
  }
  });
 
  But I've been never been able to get the resource from the panel.
  I suppose the matter of it all is that I'm trying to get the resource
 from
  the parent component, so StringResourceModel and derivates start trying
 to
  retrieve it at the invoker's level...
 
  Would it be better to get the label from the component, let's say, by
 means
  of an overridable method on MyTabPanel ?
 
  Thanks,
  Xavier
 
 
  2009/11/17 Igor Vaynberg igor.vaynb...@gmail.com
 
  you can write your own model that first tries to get the resource from
  the panel and then falls back.
 
  -igor
 
  On Tue, Nov 17, 2009 at 2:58 AM, Xavier López xavil...@gmail.com
 wrote:
   Hi,
  
   I've set up a custom MyTabbedPanel by modifying class TabbedPanel. It
  will
   include a row of buttons, added on setSelectedTab which will be the
 same
  for
   all tabs.
   Now, I'd like each tab (panel) to be able to override the text of
 each
   button, like this:
  
   public final void setSelectedTab(int index){
   ...
   // Add Panel with content for the tab to global form variable
   final MyTabPanel panel = tabs.get(index).getPanel(TAB_PANEL_ID);
   form.addOrReplace(panel);
   // Add generic buttons to form, with specific settings depending on
  panel's
   properties
   Button button1 = new Button(button1){ ... };
   button1.setModel(new StringResourceModel(button1.label,panel,
 null));
   form.addOrReplace(button1);
   ...
   }
  
   The problem is that the StringResourceModel is always pointing to the
   property in MyTabbedPanel.xml, and not the panel's.
   I've noticed that if I remove button1.label from MyTabbedPanel's
  property
   file, Wicket gets the panel's button1.label property, but I'd like
 to
   provide some kind of 'default' label for the buttons so that panels
  aren't
   forced to explicitly define this property.
  
   I expected specifying the 'panel' component on StringResourceModel's
   constructor would do the trick, but it doesn't work. Is it possible
 to
   accomplish what I'm trying to do ?
  
   Thanks,
   Xavier
  
 
  -
  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




 --
 Klein bottle for rent--inquire within.



StringResourceModel referencing another component

2009-11-17 Thread Xavier López
Hi,

I've set up a custom MyTabbedPanel by modifying class TabbedPanel. It will
include a row of buttons, added on setSelectedTab which will be the same for
all tabs.
Now, I'd like each tab (panel) to be able to override the text of each
button, like this:

public final void setSelectedTab(int index){
...
// Add Panel with content for the tab to global form variable
final MyTabPanel panel = tabs.get(index).getPanel(TAB_PANEL_ID);
form.addOrReplace(panel);
// Add generic buttons to form, with specific settings depending on panel's
properties
Button button1 = new Button(button1){ ... };
button1.setModel(new StringResourceModel(button1.label,panel, null));
form.addOrReplace(button1);
...
}

The problem is that the StringResourceModel is always pointing to the
property in MyTabbedPanel.xml, and not the panel's.
I've noticed that if I remove button1.label from MyTabbedPanel's property
file, Wicket gets the panel's button1.label property, but I'd like to
provide some kind of 'default' label for the buttons so that panels aren't
forced to explicitly define this property.

I expected specifying the 'panel' component on StringResourceModel's
constructor would do the trick, but it doesn't work. Is it possible to
accomplish what I'm trying to do ?

Thanks,
Xavier


Page expired in BEA, not Jetty

2009-11-13 Thread Xavier López
Hi,

I'm having a weird problem deploying my Wicket application in BEA. I only
manage to view the Application's HomePage and mounted BookMarkablePages.
Whenever I try to move from one of these pages (including a failed login
from the HomePage, which does not do 'setResponsePage', so it should load
the HomePage again), I get a PageExpiredException. Using Jetty everyhting is
fine.

I'm using Wicket 1.3.5. Debugging the Wicket classes I found out the root of
the problem is found in Session.getPage(final String pageMapName, final
String path, final int versionNumber).

The first difference I find when executing in Jetty and BEA is here
(Session.class line 694)

if (pageMapsUsedInRequest == null) {
pageMapsUsedInRequest = new HashMap(3);
}

With Jetty the variable does not have a null value (it is an empty Map).
With BEA, it is null.

Then, the execution is the same until it gets to the point: (Session.class
line 746)

PageMapsUsedInRequestEntry newEntry = new PageMapsUsedInRequestEntry();
newEntry.thread = Thread.currentThread();
newEntry.requestCycle = RequestCycle.get();
pageMapsUsedInRequest.put(pageMap, newEntry);
final String id = Strings.firstPathComponent(path,
Component.PATH_SEPARATOR);
Page page = pageMap.get(Integer.parseInt(id), versionNumber);
if (page == null)
{
pageMapsUsedInRequest.remove(pageMap);
pageMapsUsedInRequest.notifyAll();
}
else
{
// attach the page now.
page.onPageAttached();
touch(page);
}
return page;

In Jetty, it effectively returns a Page instance, but in BEA keeps returning
null.

Is there any setting I'm not aware of that may be causing this strange
behavior ? I use a custom session class (extending WebSession, and instanced
by means of Application.newSession), but do not override any of its
methods...

Thanks!
Xavier


Re: Page expired in BEA, not Jetty

2009-11-13 Thread Xavier López
Hi,

It's working nicely on Tomcat.

I'll have to rectify on what I've said on the first assertion. With Jetty,
the first time I try, pageMapsUsedInRequest is null too. I'll try to provide
a more elaborate description of the things happening in the second code
fragment...

I've tried even to remove weblogic.xml to bypass any harmful setting I could
have in it, but it's still happening the same. Curious thing is, I remember
seeing it work before. By the way, I'm on BEA 9.2 MP3,
I'd be grateful to any hint that could lead to this problem's solution
(thanks Igor).

Cheers!
Xavier

2009/11/13 Igor Vaynberg igor.vaynb...@gmail.com

 try in tomcat. sounds like bea is not tracking your sessions.

 -igor

 On Fri, Nov 13, 2009 at 7:37 AM, Xavier López xavil...@gmail.com wrote:
  Hi,
 
  I'm having a weird problem deploying my Wicket application in BEA. I only
  manage to view the Application's HomePage and mounted BookMarkablePages.
  Whenever I try to move from one of these pages (including a failed login
  from the HomePage, which does not do 'setResponsePage', so it should load
  the HomePage again), I get a PageExpiredException. Using Jetty everyhting
 is
  fine.
 
  I'm using Wicket 1.3.5. Debugging the Wicket classes I found out the root
 of
  the problem is found in Session.getPage(final String pageMapName, final
  String path, final int versionNumber).
 
  The first difference I find when executing in Jetty and BEA is here
  (Session.class line 694)
 
  if (pageMapsUsedInRequest == null) {
 pageMapsUsedInRequest = new HashMap(3);
  }
 
  With Jetty the variable does not have a null value (it is an empty Map).
  With BEA, it is null.
 
  Then, the execution is the same until it gets to the point:
 (Session.class
  line 746)
 
  PageMapsUsedInRequestEntry newEntry = new PageMapsUsedInRequestEntry();
  newEntry.thread = Thread.currentThread();
  newEntry.requestCycle = RequestCycle.get();
  pageMapsUsedInRequest.put(pageMap, newEntry);
  final String id = Strings.firstPathComponent(path,
  Component.PATH_SEPARATOR);
  Page page = pageMap.get(Integer.parseInt(id), versionNumber);
  if (page == null)
  {
  pageMapsUsedInRequest.remove(pageMap);
  pageMapsUsedInRequest.notifyAll();
  }
  else
  {
  // attach the page now.
  page.onPageAttached();
  touch(page);
  }
  return page;
 
  In Jetty, it effectively returns a Page instance, but in BEA keeps
 returning
  null.
 
  Is there any setting I'm not aware of that may be causing this strange
  behavior ? I use a custom session class (extending WebSession, and
 instanced
  by means of Application.newSession), but do not override any of its
  methods...
 
  Thanks!
  Xavier
 

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




-- 
Klein bottle for rent--inquire within.


Re: Page expired in BEA, not Jetty

2009-11-13 Thread Xavier López
It's ok, I'm heading that way. Thanks anyway.

2009/11/13 Igor Vaynberg igor.vaynb...@gmail.com

 sorry, i dont use bea so i have no clue. but if it works on jetty and
 on tomcat it limits where you should look - bea configuration? bea
 sessions?

 -igor

 On Fri, Nov 13, 2009 at 8:21 AM, Xavier López xavil...@gmail.com wrote:
  Hi,
 
  It's working nicely on Tomcat.
 
  I'll have to rectify on what I've said on the first assertion. With
 Jetty,
  the first time I try, pageMapsUsedInRequest is null too. I'll try to
 provide
  a more elaborate description of the things happening in the second code
  fragment...
 
  I've tried even to remove weblogic.xml to bypass any harmful setting I
 could
  have in it, but it's still happening the same. Curious thing is, I
 remember
  seeing it work before. By the way, I'm on BEA 9.2 MP3,
  I'd be grateful to any hint that could lead to this problem's solution
  (thanks Igor).
 
  Cheers!
  Xavier
 
  2009/11/13 Igor Vaynberg igor.vaynb...@gmail.com
 
  try in tomcat. sounds like bea is not tracking your sessions.
 
  -igor
 
  On Fri, Nov 13, 2009 at 7:37 AM, Xavier López xavil...@gmail.com
 wrote:
   Hi,
  
   I'm having a weird problem deploying my Wicket application in BEA. I
 only
   manage to view the Application's HomePage and mounted
 BookMarkablePages.
   Whenever I try to move from one of these pages (including a failed
 login
   from the HomePage, which does not do 'setResponsePage', so it should
 load
   the HomePage again), I get a PageExpiredException. Using Jetty
 everyhting
  is
   fine.
  
   I'm using Wicket 1.3.5. Debugging the Wicket classes I found out the
 root
  of
   the problem is found in Session.getPage(final String pageMapName,
 final
   String path, final int versionNumber).
  
   The first difference I find when executing in Jetty and BEA is here
   (Session.class line 694)
  
   if (pageMapsUsedInRequest == null) {
  pageMapsUsedInRequest = new HashMap(3);
   }
  
   With Jetty the variable does not have a null value (it is an empty
 Map).
   With BEA, it is null.
  
   Then, the execution is the same until it gets to the point:
  (Session.class
   line 746)
  
   PageMapsUsedInRequestEntry newEntry = new
 PageMapsUsedInRequestEntry();
   newEntry.thread = Thread.currentThread();
   newEntry.requestCycle = RequestCycle.get();
   pageMapsUsedInRequest.put(pageMap, newEntry);
   final String id = Strings.firstPathComponent(path,
   Component.PATH_SEPARATOR);
   Page page = pageMap.get(Integer.parseInt(id), versionNumber);
   if (page == null)
   {
   pageMapsUsedInRequest.remove(pageMap);
   pageMapsUsedInRequest.notifyAll();
   }
   else
   {
   // attach the page now.
   page.onPageAttached();
   touch(page);
   }
   return page;
  
   In Jetty, it effectively returns a Page instance, but in BEA keeps
  returning
   null.
  
   Is there any setting I'm not aware of that may be causing this strange
   behavior ? I use a custom session class (extending WebSession, and
  instanced
   by means of Application.newSession), but do not override any of its
   methods...
  
   Thanks!
   Xavier
  
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 
 
 
 
  --
  Klein bottle for rent--inquire within.
 

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




-- 
Klein bottle for rent--inquire within.


Re: Combination CompoundPropertyModel and ChoiceRenderer on DropDownChoice gives problems

2009-11-10 Thread Xavier López
Hi Alex,

Expose description and id on your model's object.


If I understand what you're saying, this was the problem, we did want the
Component's Model to be i.e. a String, while giving the choices an
id-descr-like bean... But this is not working (must have same object type on
choices and component model), so the code above returns a List of Strings as
choices, and uses a suitable choiceRenderer in order to retrieve
descriptions from the 'description-enhanced' choice model, which consists of
a Map id, description...

public final static ChoiceRenderer listRenderer = new
 ChoiceRenderer(description, id);


If i'm not wrong, this one will work when there is no Model object but when
there is one, it will throw out an exception, complaining it doesn't find
property 'id' nor 'description' in class String (which will be the class of
the Component's Model object)..

I don't know If i got your point though,
Thanks!
Xavier

2009/11/9 Alex Rass a...@itbsllc.com

 I am a newb here, so I may be way off, but this works for me:

 public final static ChoiceRenderer listRenderer = new
 ChoiceRenderer(description, id);

 Expose description and id on your model's object.

 And just add the listRenderer to the DDChoice (last param).
 Seems a lot simpler than what you are doing.


 -Original Message-
 From: Xavier López [mailto:xavil...@gmail.com]
 Sent: Monday, November 09, 2009 9:37 AM
 To: users@wicket.apache.org
 Subject: Re: Combination CompoundPropertyModel and ChoiceRenderer on
 DropDownChoice gives problems

 Got it!

 Here is the code i got into. Improvements and critics are welcome !

 class MappedModel extends Model {
protected Map map;
public String getDescription(Object id){
return (String) map.get(id);
}
 }

 // Localized choices
 final MappedModel countryModel = new MappedModel(){
public Object getObject() {
super.map = referenceData.getCountries(getLanguage());
return new ArrayList(super.map.keySet());
}
};
DropDownChoice ddcCountry= new
 DropDownChoice(country,countryModel);
ddcCountry.setChoiceRenderer(new IChoiceRenderer() {
   public Object getDisplayValue(Object object) {
   return countryModel.getDescription(object);
   }
   public String getIdValue(Object object, int index) {
   return object.toString();
   }
});


 Thanks to everyone on this list not only for the heads up on this one but
 for many more I did not need to ask ;)


 2009/11/9 Xavier López xavil...@gmail.com

  Hi Sven,
 
  Absolutely awesome. So sweet how problems vanish away when you know the
  right way to address them on Wicket: ).
 
  But, what if I had a list of countries in the database (better example
 than
  gender in this case), with its descriptions in it? Should I store a
 Country
  entity in my bean, instead of simply and Id (taking into account this
 entity
  possibly contains the descriptions and other unuseful stuff) ? Could I
  manage someway, using the countryId's in the ddc's choiceList model, to
 look
  for those descriptions in i.e. a memory-stored Map ?
 
  Thanks a lot!
  Xavier
 
  2009/11/9 svenmeier s...@meiers.net
 
 
  You want to select one value from a list of values, so obviously
  everything
  has to have the same type.
 
  These 'IdDescrBeans' smell like Struts, such constructs are not needed.
  What's wrong with the following:
 
   ListString genders = new ArrayListString();
   list.add(M);
   list.add(F);
   form.add(new DropDownChoice(gender, genders) {
 protected boolean localizeDisplayValues() {
   return true;
 }
   });
 
  Creating an enum would be a nice alternative to strings though.
  Put the following keys in you page's property file:
 
   gender.M = male
   gender.F = female
 
  i18n for free.
 
  Sven
 
 
  Xavier López-2 wrote:
  
   Hi Ann,
  
   I've also encountered this problem, but with RadioChoice instead of
   DropDownChoice.
  
   This is the thread I started about it:
  
  
 
 http://mail-archives.apache.org/mod_mbox/wicket-users/200911.mbox/browser
  
   After all this thread, I still don't know what should I do to model,
 for
   instance, a gender radioChoice which would be backed by a String
  property
   (M of F), providing a list of choices (multilingual) with
  IdDescrBeans
   like you propose.
   Should I change my bean's 'String gender' property to 'IdDescrBean
  gender'
   ?
   Why should I store description's information on my model entity ?
  
   Although I agree with having same object's on choices and model when
  it's
   about more complex data...
  
   Possible solutions I've thought of so far:
  
  - Ideally, do not use different object types in
  compundpropertymodel's
  bean and choice List. Use same object type instead.
  - When using RadioChoice, it works if you substitute it with a
   RadioGroup

Mapping an association with Models

2009-11-10 Thread Xavier López
Hi,

I'm wondering if I'm doing things straight regarding this subject.

I have an Entity A with PK properties a1, a2. There is another entity B with
PK properties b1, b2. Between them there is an association class AB (with PK
a1, a2, b1, b2). Let's suppose I have a Form for editing A objects, in which
the user can choose many B values by means of a CheckBoxMultipleChoice cbmc,
with model object and choice list of type ListB.
In the form's submit method, I create as many as necessary AB objects,
combining selected B's id's with current A's id.

class APanel extends Panel(){

private ListB selectedBs;

public APanel(){

}


Re: Mapping an association with Models

2009-11-10 Thread Xavier López
Hi,

Sorry, posted the previous one by error, this is what's missing in the code:


class APanel extends Panel(){
private ListB selectedBs;
public APanel(){
A a = getA();
ListB choices = getBChoices();
cbmc = new CheckBoxMultipleChoice(id, choices);
cbmc.setModel(new PropertyModel(this, selectedBs));
Form f = new Form(form){
onSubmit(){
  ListAB abs = a.getAB();
  abs.removeAll();
  for (B b : selectedBs){
 AB ab = new AB(a, b);
 abs.add(ab);
  }
  // a contains properly initialized ab elements
}
}
f.add(cbmc);
}

Question is, does 'selectedBs' get serialized in pageMaps ? If so, I suppose
it would be better to store only selectedB's id's...

Thanks, and sorry again for the double-posting inconvenience !
Xavier


Re: Combination CompoundPropertyModel and ChoiceRenderer on DropDownChoice gives problems

2009-11-09 Thread Xavier López
Hi Ann,

I've also encountered this problem, but with RadioChoice instead of
DropDownChoice.

This is the thread I started about it:

http://mail-archives.apache.org/mod_mbox/wicket-users/200911.mbox/browser

After all this thread, I still don't know what should I do to model, for
instance, a gender radioChoice which would be backed by a String property
(M of F), providing a list of choices (multilingual) with IdDescrBeans
like you propose.
Should I change my bean's 'String gender' property to 'IdDescrBean gender' ?
Why should I store description's information on my model entity ?

Although I agree with having same object's on choices and model when it's
about more complex data...

Possible solutions I've thought of so far:

   - Ideally, do not use different object types in compundpropertymodel's
   bean and choice List. Use same object type instead.
   - When using RadioChoice, it works if you substitute it with a RadioGroup
   and Radio's, using the 'id' property as the Radio's model and the
   'description' property as the label's model. However, when it's about
   DropDownChoice, I'm clueless about it at the moment (already having problems
   with them).
   - Provide a list of choices in which each element is an Id, and then
   provide a ChoiceRenderer display expression such that gets the proper
   description (I don't like that at all).
   - Modify IdDescrBean so that it returns the 'id' property in its
   'toString' method, and, assuming the compundpropertymodel's bean related
   property is String, provide an implementation for some useless method
   ('trim' for example), so that it returns the desctiption. Then, in the
   ChoiceRenderer, you can set the displayExpression to 'trim()', which will
   ensure that when the component model's object is a String, this error will
   not happen (also, it will return the trimmed id as description, but that
   will have no effect). But there is more to it, in order to achieve
   AbstractSingleSelectChoice's getModelValue() to identify the selected choice
   element, it calls 'indexOf' on the Choice List, using the
   compundpropertymodel's bean related property value. That is, it searches in
   a List of IdDescrBean a String. Problem is 'indexOf' invokes
   'searchedElement.equals(choices[i])', which will never return true. I got it
   to work overriding 'getModelObject' and doing this search with the opposite
   comparation (choices[i].equals(searchedElement), and providing a suitable
   implementation of 'equals' in the IdDescrBean class... But that's extremely
   hacky and ugly, and... it would not work for ListMultipleChoice, as
   getModelValue is final...



2009/11/9 Ann Baert ann.ba...@tvh.be

 I've created a jira issue with more information and an example for this
 problem:
 https://issues.apache.org/jira/browse/WICKET-2565
  DISCLAIMER 

 http://www.tvh.com/newen2/emaildisclaimer/default.html

 This message is delivered to all addressees subject to the conditions
 set forth in the attached disclaimer, which is an integral part of this
 message.




-- 
To err is human; to make real mess, you need a computer.


Re: Combination CompoundPropertyModel and ChoiceRenderer on DropDownChoice gives problems

2009-11-09 Thread Xavier López
Hi Ernesto, Sven,

Regarding the usage of localizeDisplayValues, I see that if I put simply M
or F it also works. Wonderful! Now I can define a general description for
M and F, and provide specialized ones in case of need (thinking about
yes/no literals). But, could I someway define 'groups' of yes/no
descriptions (i.e. yes/no, positive/negative) and tell someway the component
to look for one or antoher having only the Y, N literals? (maybe out of
scope on this question)


Why not use IChoiceRenderer?


I suppose you mean anonimously subclassing ChoiceRenderer and overriding
getDisplayValue in order to get the proper description... Something like
what Pedro proposed here maybe?
http://mail-archives.apache.org/mod_mbox/wicket-users/200911.mbox/%3c341aa5500911040801j3f2cb9e0tc1109314522d5...@mail.gmail.com%3e

That could be good, although maybe pulling out the description for each
choice could penalize performance...

Igor also proposed a solution to another problem that might come in handy in
http://www.mail-archive.com/wicket-u...@lists.sourceforge.net/msg26881.html

I'd like to do something like this:

// Localized choices
final Model countryModel = new Model(){
public Object getObject() {
return referenceData.getCountries(getLanguage());
}
};
DropDownChoice ddcCountry = new DropDownChoice(country,countryModel);
ddcCountry.setChoiceRenderer(new IChoiceRenderer() {
   public Object getDisplayValue(Object object) {
   return ((Map)countryModel.getObject()).get(object);
   }
   public String getIdValue(Object object, int index) {
   return object.toString();
   }
};

Only that countryModel's getObject should return a List instead of a Map
(and I'd like the model to be dynamic)

Thanks a lot!
Xavier


2009/11/9 Ernesto Reinaldo Barreiro reier...@gmail.com

 Why not use IChoiceRenderer?

 Ernesto

 On Mon, Nov 9, 2009 at 2:27 PM, Xavier López xavil...@gmail.com wrote:

  Hi Sven,
 
  Absolutely awesome. So sweet how problems vanish away when you know the
  right way to address them on Wicket: ).
 
  But, what if I had a list of countries in the database (better example
 than
  gender in this case), with its descriptions in it? Should I store a
 Country
  entity in my bean, instead of simply and Id (taking into account this
  entity
  possibly contains the descriptions and other unuseful stuff) ? Could I
  manage someway, using the countryId's in the ddc's choiceList model, to
  look
  for those descriptions in i.e. a memory-stored Map ?
 
  Thanks a lot!
  Xavier
 
  2009/11/9 svenmeier s...@meiers.net
 
  
   You want to select one value from a list of values, so obviously
  everything
   has to have the same type.
  
   These 'IdDescrBeans' smell like Struts, such constructs are not needed.
   What's wrong with the following:
  
ListString genders = new ArrayListString();
list.add(M);
list.add(F);
form.add(new DropDownChoice(gender, genders) {
  protected boolean localizeDisplayValues() {
return true;
  }
});
  
   Creating an enum would be a nice alternative to strings though.
   Put the following keys in you page's property file:
  
gender.M = male
gender.F = female
  
   i18n for free.
  
   Sven
  
  
   Xavier López-2 wrote:
   
Hi Ann,
   
I've also encountered this problem, but with RadioChoice instead of
DropDownChoice.
   
This is the thread I started about it:
   
   
  
 
 http://mail-archives.apache.org/mod_mbox/wicket-users/200911.mbox/browser
   
After all this thread, I still don't know what should I do to model,
  for
instance, a gender radioChoice which would be backed by a String
  property
(M of F), providing a list of choices (multilingual) with
   IdDescrBeans
like you propose.
Should I change my bean's 'String gender' property to 'IdDescrBean
   gender'
?
Why should I store description's information on my model entity ?
   
Although I agree with having same object's on choices and model when
  it's
about more complex data...
   
Possible solutions I've thought of so far:
   
   - Ideally, do not use different object types in
  compundpropertymodel's
   bean and choice List. Use same object type instead.
   - When using RadioChoice, it works if you substitute it with a
RadioGroup
   and Radio's, using the 'id' property as the Radio's model and the
   'description' property as the label's model. However, when it's
  about
   DropDownChoice, I'm clueless about it at the moment (already
 having
problems
   with them).
   - Provide a list of choices in which each element is an Id, and
 then
   provide a ChoiceRenderer display expression such that gets the
  proper
   description (I don't like that at all).
   - Modify IdDescrBean so that it returns the 'id' property in its
   'toString' method, and, assuming the compundpropertymodel's bean

Re: Combination CompoundPropertyModel and ChoiceRenderer on DropDownChoice gives problems

2009-11-09 Thread Xavier López
Got it!

Here is the code i got into. Improvements and critics are welcome !

class MappedModel extends Model {
protected Map map;
public String getDescription(Object id){
return (String) map.get(id);
}
}

// Localized choices
final MappedModel countryModel = new MappedModel(){
public Object getObject() {
super.map = referenceData.getCountries(getLanguage());
return new ArrayList(super.map.keySet());
}
};
DropDownChoice ddcCountry= new
DropDownChoice(country,countryModel);
ddcCountry.setChoiceRenderer(new IChoiceRenderer() {
   public Object getDisplayValue(Object object) {
   return countryModel.getDescription(object);
   }
   public String getIdValue(Object object, int index) {
   return object.toString();
   }
});


Thanks to everyone on this list not only for the heads up on this one but
for many more I did not need to ask ;)


2009/11/9 Xavier López xavil...@gmail.com

 Hi Sven,

 Absolutely awesome. So sweet how problems vanish away when you know the
 right way to address them on Wicket: ).

 But, what if I had a list of countries in the database (better example than
 gender in this case), with its descriptions in it? Should I store a Country
 entity in my bean, instead of simply and Id (taking into account this entity
 possibly contains the descriptions and other unuseful stuff) ? Could I
 manage someway, using the countryId's in the ddc's choiceList model, to look
 for those descriptions in i.e. a memory-stored Map ?

 Thanks a lot!
 Xavier

 2009/11/9 svenmeier s...@meiers.net


 You want to select one value from a list of values, so obviously
 everything
 has to have the same type.

 These 'IdDescrBeans' smell like Struts, such constructs are not needed.
 What's wrong with the following:

  ListString genders = new ArrayListString();
  list.add(M);
  list.add(F);
  form.add(new DropDownChoice(gender, genders) {
protected boolean localizeDisplayValues() {
  return true;
}
  });

 Creating an enum would be a nice alternative to strings though.
 Put the following keys in you page's property file:

  gender.M = male
  gender.F = female

 i18n for free.

 Sven


 Xavier López-2 wrote:
 
  Hi Ann,
 
  I've also encountered this problem, but with RadioChoice instead of
  DropDownChoice.
 
  This is the thread I started about it:
 
 
 http://mail-archives.apache.org/mod_mbox/wicket-users/200911.mbox/browser
 
  After all this thread, I still don't know what should I do to model, for
  instance, a gender radioChoice which would be backed by a String
 property
  (M of F), providing a list of choices (multilingual) with
 IdDescrBeans
  like you propose.
  Should I change my bean's 'String gender' property to 'IdDescrBean
 gender'
  ?
  Why should I store description's information on my model entity ?
 
  Although I agree with having same object's on choices and model when
 it's
  about more complex data...
 
  Possible solutions I've thought of so far:
 
 - Ideally, do not use different object types in
 compundpropertymodel's
 bean and choice List. Use same object type instead.
 - When using RadioChoice, it works if you substitute it with a
  RadioGroup
 and Radio's, using the 'id' property as the Radio's model and the
 'description' property as the label's model. However, when it's about
 DropDownChoice, I'm clueless about it at the moment (already having
  problems
 with them).
 - Provide a list of choices in which each element is an Id, and then
 provide a ChoiceRenderer display expression such that gets the proper
 description (I don't like that at all).
 - Modify IdDescrBean so that it returns the 'id' property in its
 'toString' method, and, assuming the compundpropertymodel's bean
  related
 property is String, provide an implementation for some useless method
 ('trim' for example), so that it returns the desctiption. Then, in
 the
 ChoiceRenderer, you can set the displayExpression to 'trim()', which
  will
 ensure that when the component model's object is a String, this error
  will
 not happen (also, it will return the trimmed id as description, but
  that
 will have no effect). But there is more to it, in order to achieve
 AbstractSingleSelectChoice's getModelValue() to identify the selected
  choice
 element, it calls 'indexOf' on the Choice List, using the
 compundpropertymodel's bean related property value. That is, it
  searches in
 a List of IdDescrBean a String. Problem is 'indexOf' invokes
 'searchedElement.equals(choices[i])', which will never return true. I
  got it
 to work overriding 'getModelObject' and doing this search with the
  opposite
 comparation (choices[i].equals(searchedElement), and providing a
  suitable
 implementation

CompoundPropertyModel in conjunction with RadioChoiceChoiceRenderers

2009-11-04 Thread Xavier López
Hi,

I have a question regarding the use of RadioChoice and ChoiceRenderer's in
conjunction with CompoundPropertyModel. I'm new to Wicket (but already a
convinced user ;) ), so maybe my approach on this one is not at all as it
should be... Any comments are welcome !

I'll get into details. Let's say I have a class in my domain model named
Person. This entity has a property named 'deptId' of type String. The Person
entity is the backing for a CompundPropertyModel applied to the whole form.
The 'deptId' field is inputted by the user, let's say, by means of a
RadioChoice (I guess it makes no difference from a DropDownChoice taking
into account the point of the question). The choice list for the RadioChoice
component is a List made up of DTO objects with properties id and
description. To ensure proper rendering of labels, I use a suitable
ChoiceRenderer.

Now, problems come when the 'deptId' property has a value in the Person
entity used in the CompoundPropertyModel. I get an error saying that class
String does not have any property called 'id' (I suppose this error comes
from having a ModelObject of type String and also having a ChoiceRenderer
refering to 'id' property).

I'll provide some sample code:

markup
-
...
form wicket:id=form
...
span valign=top wicket:id=deptId/span
...
/form
...

Java
-

...
ListSimpleElementDTO choices = contextData.getChoices();
Person p = new Person(...);
Form f = new Form(form){...};
f.setModel(new CompoundPropertyModel(p));
ChoiceRenderer cr = new ChoiceRenderer(deptId, choices, new
ChoiceRenderer(id, description));
f.add(cr);
...


I suppose the 'normal' way of doing things would be providing a custom Model
to 'cr', but I'd like to know if there is a possibility to achieve this
point still using CompoundPropertyModel...

The stack trace I get is the following:

WicketMessage: No get method defined for class: class java.lang.String
expression: id
Root cause:
org.apache.wicket.WicketRuntimeException: No get method defined for class:
class java.lang.String expression: id
at
org.apache.wicket.util.lang.PropertyResolver.getGetAndSetter(PropertyResolver.java:440)
at
org.apache.wicket.util.lang.PropertyResolver.getObjectAndGetSetter(PropertyResolver.java:282)
at
org.apache.wicket.util.lang.PropertyResolver.getValue(PropertyResolver.java:91)
at
org.apache.wicket.markup.html.form.ChoiceRenderer.getIdValue(ChoiceRenderer.java:140)
at
org.apache.wicket.markup.html.form.AbstractSingleSelectChoice.getModelValue(AbstractSingleSelectChoice.java:144)
at
org.apache.wicket.markup.html.form.FormComponent.getValue(FormComponent.java:797)
at
org.apache.wicket.markup.html.form.RadioChoice.onComponentTagBody(RadioChoice.java:407)
at org.apache.wicket.Component.renderComponent(Component.java:2480)
at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1411)
at org.apache.wicket.Component.render(Component.java:2317)
at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1297)
...


Re: CompoundPropertyModel in conjunction with RadioChoiceChoiceRenderers

2009-11-04 Thread Xavier López
Hi Sven, Pedro,

Thanks both for your quick reply.

Ideally you would just set a Department instance into your Person objects


the best way is you have your depid property of type Department

This was the first approach to take into account, but the idea was discarded
in benefit of SimpleElementDTO, in order to provide only the necessary
information to Wicket Models, with the intention of not wasting any memory
on PageMaps due to Department object serializations... Also, this
SimpleElementDTO would be reusable throughout the whole application when
it's about Radio and DropDown Choices...

write some specialized render

This kinda 'dirty-fix' idea was already crawling in my mind, trying to come
out someway. Thanks for providing a concrete implementation.

So, in the end I'm trying to provide a custom model. Something like:

Java

final Person p;

Model crModel = new Model(){
  getObject(){
 return p.getDeptId();
   }
  setObject(Object o){
 // o is String!
 p.setDeptId( (String) o);
  }
};
ChoiceRenderer cr = new ChoiceRenderer(deptId, choices, new
ChoiceRenderer(id, description));
cr.setModel(crModel);

But i'm stucking into the same error, as this Model it's kind like a
PropertyModel which would be assumed by having the former
CompoundPropertyModel...

Any thoughts ? Maybe rendering labels independently ?

It's strange nobody has bumped into this situation before.. Maybe it's
because i'm still thinking like I was using Struts...

Thanks to both again,
Cheers !


2009/11/4 Pedro Santos pedros...@gmail.com

 Hi Sven, he stell can write some specialized render... but I think the best
 way is you have your depid property of type Department. Than all this
 thread
 would not have started :)

 class YourCustomRender
{
@Override
public String getIdValue(Object object, int index)
{
if (object instanceof DTO)
{
return ((DTO)object).getDeptId()
}
else
{
return (String)object;//already is the depid string
}
}

@Override
public Object getDisplayValue(Object object)
{
if (object instanceof DTO)
{
return ((DTO)object).getDescription();
}
else
{
return contextData.getDTOBasedOnDepid(object);
 }
}
}

 On Wed, Nov 4, 2009 at 1:29 PM, Xavier López xavil...@gmail.com wrote:

  Hi,
 
  I have a question regarding the use of RadioChoice and ChoiceRenderer's
 in
  conjunction with CompoundPropertyModel. I'm new to Wicket (but already a
  convinced user ;) ), so maybe my approach on this one is not at all as it
  should be... Any comments are welcome !
 
  I'll get into details. Let's say I have a class in my domain model named
  Person. This entity has a property named 'deptId' of type String. The
  Person
  entity is the backing for a CompundPropertyModel applied to the whole
 form.
  The 'deptId' field is inputted by the user, let's say, by means of a
  RadioChoice (I guess it makes no difference from a DropDownChoice taking
  into account the point of the question). The choice list for the
  RadioChoice
  component is a List made up of DTO objects with properties id and
  description. To ensure proper rendering of labels, I use a suitable
  ChoiceRenderer.
 
  Now, problems come when the 'deptId' property has a value in the Person
  entity used in the CompoundPropertyModel. I get an error saying that
 class
  String does not have any property called 'id' (I suppose this error comes
  from having a ModelObject of type String and also having a ChoiceRenderer
  refering to 'id' property).
 
  I'll provide some sample code:
 
  markup
  -
  ...
  form wicket:id=form
 ...
 span valign=top wicket:id=deptId/span
 ...
  /form
  ...
 
  Java
  -
 
  ...
  ListSimpleElementDTO choices = contextData.getChoices();
  Person p = new Person(...);
  Form f = new Form(form){...};
  f.setModel(new CompoundPropertyModel(p));
  ChoiceRenderer cr = new ChoiceRenderer(deptId, choices, new
  ChoiceRenderer(id, description));
  f.add(cr);
  ...
 
 
  I suppose the 'normal' way of doing things would be providing a custom
  Model
  to 'cr', but I'd like to know if there is a possibility to achieve this
  point still using CompoundPropertyModel...
 
  The stack trace I get is the following:
 
  WicketMessage: No get method defined for class: class java.lang.String
  expression: id
  Root cause:
  org.apache.wicket.WicketRuntimeException: No get method defined for
 class:
  class java.lang.String expression: id
  at
 
 
 org.apache.wicket.util.lang.PropertyResolver.getGetAndSetter(PropertyResolver.java:440)
  at
 
 
 org.apache.wicket.util.lang.PropertyResolver.getObjectAndGetSetter(PropertyResolver.java:282

Re: CompoundPropertyModel in conjunction with RadioChoiceChoiceRenderers

2009-11-04 Thread Xavier López
Wonderful !

Now I understand better. If only I could set the String deptId in an inner
variable inside the Model and link it to the property with another model !
This comes from the fact that the building of the RadioChoice is made inside
a Helper Class...

Probably this is an atrocity, but I hope it'll transmit the idea...

Helper.java
--
public static RadioChoice getDeptRadioChoice(String id){
RadioChoice cr = new RadioChoice(id,
getDeptsAsDTOList(),
new SimpleElementChoiceRenderer());

Model crModel = new Model(){
String id;
getObject(){
return getDptDTO(id);
}
setObject(Object o){
id = ( ((DTO) o).getId());
}
};
cr.setModel(crModel);
return cr;
}

PersonForm.java
-

RadioChoice cr = Helper.getDeptRadioChoice(deptId);
cr.setModel(new Model(cr.getModel()){
public Object getObject(){
return ((Model)super.getObject()).getObject();
}
public void setObject(Object o){
((Model)getObject()).setObject(o);
p.setDeptId((String)m.getObject());
}
});

Thanks !

2009/11/4 Pedro Santos pedros...@gmail.com

 Model crModel = new Model(){
 getObject(){
 return contextData.getDTO(p.getDeptId());
  }
 setObject(Object o){
p.setDeptId( ((DTO) o).getId());
 }
 };

 On Wed, Nov 4, 2009 at 2:32 PM, Xavier López xavil...@gmail.com wrote:

  Hi Sven, Pedro,
 
  Thanks both for your quick reply.
 
  Ideally you would just set a Department instance into your Person objects
 
 
  the best way is you have your depid property of type Department
 
  This was the first approach to take into account, but the idea was
  discarded
  in benefit of SimpleElementDTO, in order to provide only the necessary
  information to Wicket Models, with the intention of not wasting any
 memory
  on PageMaps due to Department object serializations... Also, this
  SimpleElementDTO would be reusable throughout the whole application when
  it's about Radio and DropDown Choices...
 
  write some specialized render
  
  This kinda 'dirty-fix' idea was already crawling in my mind, trying to
 come
  out someway. Thanks for providing a concrete implementation.
 
  So, in the end I'm trying to provide a custom model. Something like:
 
  Java
  
  final Person p;
 
  Model crModel = new Model(){
   getObject(){
  return p.getDeptId();
}
   setObject(Object o){
  // o is String!
  p.setDeptId( (String) o);
}
  };
  ChoiceRenderer cr = new ChoiceRenderer(deptId, choices, new
  ChoiceRenderer(id, description));
  cr.setModel(crModel);
 
  But i'm stucking into the same error, as this Model it's kind like a
  PropertyModel which would be assumed by having the former
  CompoundPropertyModel...
 
  Any thoughts ? Maybe rendering labels independently ?
 
  It's strange nobody has bumped into this situation before.. Maybe it's
  because i'm still thinking like I was using Struts...
 
  Thanks to both again,
  Cheers !
 
 
  2009/11/4 Pedro Santos pedros...@gmail.com
 
   Hi Sven, he stell can write some specialized render... but I think the
  best
   way is you have your depid property of type Department. Than all this
   thread
   would not have started :)
  
   class YourCustomRender
  {
  @Override
  public String getIdValue(Object object, int index)
  {
  if (object instanceof DTO)
  {
  return ((DTO)object).getDeptId()
  }
  else
  {
  return (String)object;//already is the depid string
  }
  }
  
  @Override
  public Object getDisplayValue(Object object)
  {
  if (object instanceof DTO)
  {
  return ((DTO)object).getDescription();
  }
  else
  {
  return contextData.getDTOBasedOnDepid(object);
   }
  }
  }
  
   On Wed, Nov 4, 2009 at 1:29 PM, Xavier López xavil...@gmail.com
 wrote:
  
Hi,
   
I have a question regarding the use of RadioChoice and
 ChoiceRenderer's
   in
conjunction with CompoundPropertyModel. I'm new to Wicket (but
 already
  a
convinced user ;) ), so maybe my approach on this one is not at all
 as
  it
should be... Any comments are welcome !
   
I'll get into details. Let's say I have a class in my domain model
  named
Person. This entity has a property named 'deptId' of type String. The
Person
entity is the backing for a CompundPropertyModel applied to the whole
   form.
The 'deptId' field is inputted by the user, let's say, by means of a
RadioChoice (I guess