Re: Modal window - update main page on close

2008-07-29 Thread damnitjim
Have you tried adding target.addComponent() call in the CancelButton submit
?

On Mon, Jul 28, 2008 at 4:19 PM, steve222 [EMAIL PROTECTED] wrote:


 Hi. Using Wicket 1.3.4.

 I have a main page with a panel.  Page contains a form for editing a main
 record.  Panel contains a DataView containing a list of related sub
 records.
 In the java code for the pabel, create a ModalWindow and pop this for
 adding
 more sub-records.  Uses AJAX.

 Got this working OK similar to:


 Main page code:


public MainRecordEdit(PageParameters p) {

Integer id = p.getInt(mainRecord);

// uses application scope Spring bean to get record from
 database
final MyRecord myRecord = getRecordManager().findById(id);

...
// stuff form main record CRUD on main page
...


// add the panel for the sub records
add(new MyListingPanel(myListingPanel, myRecord));

}



 Panel code for sub records:

public MyListingPanel(String id, final MyRecord myRecord) {

super(id);

Collection mySubs = myRecord.getSubRecords();

DataView dataView = new DataView(dataView, new
 ListDataProvider(new
 ArrayList(mySubs))) {

public void populateItem(final Item item) {
final MySub ms = (MyRecord) item.getModelObject();
item.add(new Label(id, ms.getId()));
...
}
};

final WebMarkupContainer listContainer = new
 WebMarkupContainer(theContainer);

listContainer.setOutputMarkupId(true);
listContainer.add(dataView);

   ...

   payawayWindow.setWindowClosedCallback(new
 ModalWindow.WindowClosedCallback() {
public void onClose(AjaxRequestTarget target) {

// not sure what to put here to refresh the list in
 dataview

target.addComponent(listContainer);
}
});


   final ModalWindow modalWindow = new ModalWindow(modalWindow);
   modalWindow.setOutputMarkupId(true);
   add(modalWindow);

   add(new AjaxLink(modalLink) {
   public void onClick(AjaxRequestTarget target) {
modalWindowshow(target);
}
});


 In the jave code for the Modal window - also a Panel - I do normal CRUD
 stuff via AJAX with feedback going into a FeedbackPanel on the modal window
 panel when I save (or hit validation errors).  No problems here - my AJAX
 updates work OK.

 I close the popup panel using a button:

   private void addCancelButton(Form form, final ModalWindow
 window) {

AjaxFallbackButton cancel = new
 AjaxFallbackButton(cancelbutton, form)
 {

@Override
protected void onSubmit(AjaxRequestTarget
 target, Form form) {

// not sure if I need to do anything
 here to make the new
// sub record appear on main page
 when I close this window

info(Cancel was pressed!);
window.close(target);
}
};

cancel.setDefaultFormProcessing(false);
form.add(cancel);
}


 Window closes.  Main page does not show new sub record in the DataView on
 the main Panel.

 Page refresh reloads the list OK.

 Thanks.


















 --
 View this message in context:
 http://www.nabble.com/Modal-window---update-main-page-on-close-tp18701883p18701883.html
 Sent from the Wicket - User mailing list archive at Nabble.com.


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




Re: Strict 4 digit year for DateTextField?

2008-07-28 Thread damnitjim
Larry,
I think setLenient(false) should work if you use java.text.DateFormat but
did you write your own custom implementation of IConverter interface? Thats
the only way I can think of at this point.
Aye

On Fri, Jul 25, 2008 at 2:25 PM, Zappaterrini, Larry 
[EMAIL PROTECTED] wrote:

 I've had the same problem using java.text.DateFormat to validate the
 same pattern you are using. The solution I use is to check the string
 length to ensure that it is 10 characters. It might be nice if
 PatternDateConverter were to be enhanced to have a required length value
 to enforce this in an encapsulated manner, but it isn't required.


 Larry

 -Original Message-
 From: damnitjim [mailto:[EMAIL PROTECTED]
 Sent: Friday, July 25, 2008 2:03 PM
 To: users@wicket.apache.org
 Subject: Strict 4 digit year for DateTextField?

 Hi,
 Has anyone been able to enforce that the year is 4 digits instead of two
 for
 the DateTextField? Right now, if my format is MM/dd/ the
 DateTextField
 is still allowing two digit fields to be submitted.

 final String dateFormat = MM/dd/;
 PatternDateConverter pdc = new PatternDateConverter( dateFormat, false
 );
 add(DateTextField.withConverter(obligationDate,  pdc));

 I looked at the JODA javadoc for DateTimeFormat that
 PatternDateConverter is
 using but didn't see anything that would help (I saw ISODateTimeFormat
 that
 came close but it doesn't allow you to pass in the format).

 This seems like a reasonably straight forward problem so what am I
 missing?
 Thanks!
 Aye

 _

 The information contained in this message is proprietary and/or
 confidential. If you are not the
 intended recipient, please: (i) delete the message and all copies; (ii) do
 not disclose,
 distribute or use the message in any manner; and (iii) notify the sender
 immediately. In addition,
 please be aware that any message addressed to our domain is subject to
 archiving and review by
 persons other than the intended recipient. Thank you.
 _

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




Re: Strict 4 digit year for DateTextField?

2008-07-28 Thread damnitjim
Lary,
I've been looking at the APIs some more and found this different
DateTextField (I'm not sure which one you're using):

org.apache.wicket.extensions.markup.html.form.DateTextField

I was using this one:

org.apache.wicket.datetime.markup.html.form.DateTextField

It looks like the the one in the extensions package supports passing in
SimpleDateFormat but you're saying that it might also have issues. I'll try
it and see. Thanks bud!


On Mon, Jul 28, 2008 at 8:52 AM, Zappaterrini, Larry 
[EMAIL PROTECTED] wrote:

 Aye,

 The use of DateFormat is actually in Spring's CustomDateEditor object.
 See
 http://static.springframework.org/spring/docs/2.5.x/api/org/springframew
 ork/beans/propertyeditors/CustomDateEditor.html#CustomDateEditor(java.te
 xt.DateFormat,%20boolean,%20int)http://static.springframework.org/spring/docs/2.5.x/api/org/springframework/beans/propertyeditors/CustomDateEditor.html#CustomDateEditor%28java.text.DateFormat,%20boolean,%20int%29where
  it mentions that
 setLenient(false) does not enforce strict parsing as you might expect. I
 think you are correct in thinking that creating your own IConverter
 would be the best solution. I'd probably give subclassing
 PatternDateConverter a shot.

 Larry

 -Original Message-
 From: damnitjim [mailto:[EMAIL PROTECTED]
 Sent: Monday, July 28, 2008 11:43 AM
 To: users@wicket.apache.org
 Subject: Re: Strict 4 digit year for DateTextField?

 Larry,
 I think setLenient(false) should work if you use java.text.DateFormat
 but
 did you write your own custom implementation of IConverter interface?
 Thats
 the only way I can think of at this point.
 Aye

 On Fri, Jul 25, 2008 at 2:25 PM, Zappaterrini, Larry 
 [EMAIL PROTECTED] wrote:

  I've had the same problem using java.text.DateFormat to validate the
  same pattern you are using. The solution I use is to check the string
  length to ensure that it is 10 characters. It might be nice if
  PatternDateConverter were to be enhanced to have a required length
 value
  to enforce this in an encapsulated manner, but it isn't required.
 
 
  Larry
 
  -Original Message-
  From: damnitjim [mailto:[EMAIL PROTECTED]
  Sent: Friday, July 25, 2008 2:03 PM
  To: users@wicket.apache.org
  Subject: Strict 4 digit year for DateTextField?
 
  Hi,
  Has anyone been able to enforce that the year is 4 digits instead of
 two
  for
  the DateTextField? Right now, if my format is MM/dd/ the
  DateTextField
  is still allowing two digit fields to be submitted.
 
  final String dateFormat = MM/dd/;
  PatternDateConverter pdc = new PatternDateConverter( dateFormat, false
  );
  add(DateTextField.withConverter(obligationDate,  pdc));
 
  I looked at the JODA javadoc for DateTimeFormat that
  PatternDateConverter is
  using but didn't see anything that would help (I saw ISODateTimeFormat
  that
  came close but it doesn't allow you to pass in the format).
 
  This seems like a reasonably straight forward problem so what am I
  missing?
  Thanks!
  Aye
 
  _
 
  The information contained in this message is proprietary and/or
  confidential. If you are not the
  intended recipient, please: (i) delete the message and all copies;
 (ii) do
  not disclose,
  distribute or use the message in any manner; and (iii) notify the
 sender
  immediately. In addition,
  please be aware that any message addressed to our domain is subject to
  archiving and review by
  persons other than the intended recipient. Thank you.
  _
 
  -
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
 
 

 _

 The information contained in this message is proprietary and/or
 confidential. If you are not the
 intended recipient, please: (i) delete the message and all copies; (ii) do
 not disclose,
 distribute or use the message in any manner; and (iii) notify the sender
 immediately. In addition,
 please be aware that any message addressed to our domain is subject to
 archiving and review by
 persons other than the intended recipient. Thank you.
 _

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




Re: Strict 4 digit year for DateTextField?

2008-07-28 Thread damnitjim
I ended up having to use a custom date pattern. I'm not saying wicket has to
be US-centric but this is such a common validation that most US customers
have included in their requirements.

public class StrictPatternDateConverter extends PatternDateConverter {

public static final String REGEX_PATTERN =
^(\\d{1,2})/(\\d{1,2})/(\\d{4})$;

public StrictPatternDateConverter(String datePattern, boolean
applyTimeZoneDifference) {
super(datePattern, applyTimeZoneDifference);
}

@Override
public Object convertToObject(String value, Locale locale) {
final Pattern pattern = Pattern.compile(REGEX_PATTERN);
if (value != null  !pattern.matcher(value).matches()) {
throw new ConversionException(Invalid date format);
}
return super.convertToObject(value, locale);
}
}


Strict 4 digit year for DateTextField?

2008-07-25 Thread damnitjim
Hi,
Has anyone been able to enforce that the year is 4 digits instead of two for
the DateTextField? Right now, if my format is MM/dd/ the DateTextField
is still allowing two digit fields to be submitted.

final String dateFormat = MM/dd/;
PatternDateConverter pdc = new PatternDateConverter( dateFormat, false );
add(DateTextField.withConverter(obligationDate,  pdc));

I looked at the JODA javadoc for DateTimeFormat that PatternDateConverter is
using but didn't see anything that would help (I saw ISODateTimeFormat that
came close but it doesn't allow you to pass in the format).

This seems like a reasonably straight forward problem so what am I missing?
Thanks!
Aye


CheckGroup with custom Model problem

2008-07-11 Thread damnitjim
Hey guys,
I'm back to using Wicket after a 3 year break! Anyway, if any of you can
help with this delightful pain I'd return the favor (eventually!).

Background:
- I have a DTO/VO that has a property that is a list of strings (e.g.
String[] propertyA)
- The lookup items (choices) for this property is a list of name/value pairs
(e.g. EnumerationValue class)  and the values  will be the ones that need to
be passed onto the DTO/VO property.

public class EnumerationValue  implements Serializable
{
private String code;
private String description;

public String getCode()
{
return code;
}

public void setCode(String code)
{
this.code = code;
}

public String getDescription()
{
return description;
}

public void setDescription(String description)
{
this.description = description;
}
}

I had setup a custom model to handle the translation between the collection
of EnumerationValues coming from the UI and into the DTO/VO object:

private IModel createFundInstrumentTypeCodeModel(final
ListEnumerationValue choices) {
return new IModelListEnumerationValue() {
// this gets the value from the model object backing the form
public ListEnumerationValue getObject() {
final ListString codes=  wizard.getFundingInstrumentCodes
();
// loop through the 'choices' and compare
the code of each choice with the string list
// pick out all the matching items from the
choices
return CollectionHelper.get(choices, codes);
}

// this sets the value from the form into the model object
backing the form
public void setObject(ListEnumerationValue object) {
  // convert the list into a string list and set the DTO/VO
wizard.setFundingInstrumentCodes(CollectionHelper.convertToStringList(object));
}

public void detach() {
}


};
}
This custom model was working fine when I was using CheckBoxMultipleChoice
but I changed to CheckGroup since I wanted more control over the HTML being
produced. CheckGroup doesn't call the setObject() everytime the form is
submitted; accoridng to the updateModel() method, it only gets called when
the backing model object is null.


public void updateModel()
{
Collection collection = getModelObject();
if (collection == null)
{
collection = getConvertedInput();
setModelObject(collection);
}
else
{
modelChanging();
collection.clear();
collection.addAll(getConvertedInput());
setModelObject(collection); // TODO: Added this to allow
conversion of list of enumerated values into list of strings
modelChanged();
}
}

I've added the TODO line in there so that correct trnslation between list of
strings and list of EnumerartionValue can occur. Am I doing this correctly
or am I on the wrong ttrack.
Thanks!
Aye