Re: Form validation without a form component

2009-04-03 Thread triswork

Thanks for the suggestion Martijn. 
I tried return new FormComponent[0]; and got exactly the same error.

I think my use-case is quite fringe, so I have resigned myself to using the
hidden field that you previously suggested.

 - Tristan


Martijn Dashorst wrote:
> 
> You might try to return an empty array..
> 
> Martijn
> 

-- 
View this message in context: 
http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22866535.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: FormComponentPanel woes

2009-03-26 Thread triswork

Thanks Linda,

That was very helpful.
I also figured out that I am a complete cretin... I forgot to replace the
 tags with  tags in my original markup (where I replaced the
TextArea with my LimitedTextArea *sigh*). At least that explains why I was
getting weird content all the time :)

T


Linda van der Pal wrote:
> 
> Arg, I wanted to make my changes bold. But now I see stars. Not sure if 
> you get those too, but if you do: leave out the stars :)
> 

-- 
View this message in context: 
http://www.nabble.com/FormComponentPanel-woes-tp22720502p22721785.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: FormComponentPanel woes

2009-03-26 Thread triswork

Hi Stefan

You have completely lost me on this one. 
All I want to do is have my TextArea (contained within my
FormComponentPanel) to render properly without sticking arbitrary bits of
markup inside itself.
That markup you have quoted is being generated by Wicket - not by me :(


Stefan Lindner wrote:
> 
> 
> 
> 
> Should do it
> 

Linda,

I don't have that book unfortunately. The javadocs do mention those two
methods, but it seems targeted at compound components. Mine is pretty
simple. I just want to decorate my textarea with some text and some
Javascript...


Linda van der Pal wrote:
> 
> I found it in the book Wicket in Action.
> 

-- 
View this message in context: 
http://www.nabble.com/FormComponentPanel-woes-tp22720502p22721375.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: FormComponentPanel woes

2009-03-26 Thread triswork

Sorry... That last bit isn't my markup. It is the text that is appearing in
my textarea component.
My markup looks like this:



(Maximum characters: 100) 


T


Steve Flasby wrote:
> 
> shoudn't that be:
> 
> 
> 
> or am I missing something?
> 
> Cheers - Steve
> 

-- 
View this message in context: 
http://www.nabble.com/FormComponentPanel-woes-tp22720502p22720956.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: FormComponentPanel woes

2009-03-26 Thread triswork

Hi Linda,

No, I haven't :( 
I didn't realise I had to... Do you know where I can find some documentation
explaining this?

Thanks

T


Linda van der Pal wrote:
> 
> Hi
> 
> Did you override onBeforeRender and convertInput?
> 
> Regards,
> Linda
> 

-- 
View this message in context: 
http://www.nabble.com/FormComponentPanel-woes-tp22720502p22720806.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



FormComponentPanel woes

2009-03-26 Thread triswork

Hi

I am getting really frustrated here because I can't figure out what I am
doing wrong. I am creating a new TextArea form component that is limited to
a particular number of characters. The trouble is, that my text area is
always rendered containing its own HTML.

Basically, I have:

public class LimitedTextArea extends FormComponentPanel implements
IHeaderContributor {
public LimitedTextArea(String id, IModel model, int limit) {
super(id, model);
TextArea textField = new TextArea("content", model);
add(textField);
...
}
}

And it is being called like this:
form.add(new LimitedTextArea("content", new PropertyModel(message,
"content"), 160));

And the TextArea always contains this text:


This is driving me absolutely mad! Anyone have any ideas?
-- 
View this message in context: 
http://www.nabble.com/FormComponentPanel-woes-tp22720502p22720502.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: Form validation without a form component

2009-03-26 Thread triswork

Thanks igor,

I had a go at implementing the form level validator, but it still requires a
FormComponent to attach its error message to.

For example:
form.add(new IFormValidator() {
  @Override
  public void validate(Form f) {
if (myList.size() == 0)  {
  f.error(new ValidationError().addMessageKey("error.myErrorMessage"));
}
  }

  @Override
  public FormComponent[] getDependentFormComponents() {
return null;
  }
});

If I don't return a FormComponent in getDependentFormComponents(), I get the
following message in my Feedback Panel:
[ValidationError message=[null], keys=[error.myErrorMessage],
variables=[null]]

Is there a way around this that you are aware of?

T


igor.vaynberg wrote:
> 
> see IFormValidator
> 
> -igor
> 

-- 
View this message in context: 
http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22717797.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: Form validation without a form component

2009-03-25 Thread triswork

Nope. As far as I can tell, you can only add Validators to subclasses of
FormComponent.


James Carman-3 wrote:
> 
> You could add a validator to the form itself, right?
> 

-- 
View this message in context: 
http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22705787.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: Form validation without a form component

2009-03-24 Thread triswork

Hi Martijn,
The hidden worked fine. 
I thought there might be a more elegant way though :)

Tristan


Martijn Dashorst wrote:
> 
> You could try adding a hidden field and register a validator to that
> field...
> 
> I have no idea if that would work though
> 
> Martijn
> 

-- 
View this message in context: 
http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22683664.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



Form validation without a form component

2009-03-24 Thread triswork

One of my forms is used to dynamically construct a linked list using Ajax.

I would like to apply some form of validation to this form that will show an
error unless the size of the list is greater than 0. 

The trouble is that there is no form component that I can add my validator
to. Is there a sensible way to do this?
-- 
View this message in context: 
http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22682572.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: Panel data interchange - concept validation

2009-03-17 Thread triswork

Well, after a reasonable nights sleep, I have figured out the answers to most
of my own questions. Here they are for anyone that comes along in the
future...


triswork wrote:
> 
> 2) Is manually calling the detach() method of the model the best way to
> get it to refresh when the Ajaxified link is clicked on? It seems like a
> bit of a bodge, but I can't think of any other way :(
> 
You don't have to call detach manually. The Ajax call is a new request and
Wicket handles the detach() and load() methods fine without any help.


triswork wrote:
> 
> 3) I have passed references to my WMC containers in the constructors of my
> Panels (not shown in the above code). This is really ugly and I am
> convinced there must be a better way. I originally tried calling
> getParent() assuming it must refer to the component above my Panel in the
> component hierarchy. As it turns out, it doesn't. Can anyone give me a
> definitive answer on what getParent() refers to? I couldn't figure it out
> from the API docs :(
> 
This question was the result of a typo. As it turns out, getParent() works
just the way I thought and, (ironically), code fragment in my OP worked...
The code in my IDE didn't :)


-- 
View this message in context: 
http://www.nabble.com/Panel-data-interchange---concept-validation-tp22541467p22553730.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



Panel data interchange - concept validation

2009-03-16 Thread triswork

I have written some code that *seems* to work fine, but I am a little
concerned over whether my approach is (a) valid and (b) optimal. I am hoping
that some of the experienced Wicket programmers can provide me with some
feedback.

Basically, I have a page with four panels on it that is very similar to the
Gmail "contacts" page. The first panel displays a list of user groups. The
second displays a list of the users in the selected group. The third and
fourth contain contextual information and can be ignored for the purposes of
this discussion.

The basic use-case here is to click on an Ajaxified link in the one panel
(such as the user groups) and have the other panels update accordingly.

My approach looks something like this:

The Page class just instantiates the panels and wraps each of them in a
WebMarkupContainer with setOutputMarkupId(true); Nothing too interesting.

The UserPanel is reasonably straight-forward. The only thing worth
mentioning is that I hold a reference to userListModel so that I can ask it
to detach itself when I perform an update.

public class UserPanel extends Panel {
  @SpringBean
  private UserDao userDao;
  private UserGroup group; // A reference to the user group so I can extract
bits of info from it
  public IModel userListModel; // A reference to my model so that I can ask
it to update itself.

  public UserPanel(String id, final UserGroup group) {
super(id);
this.group = group;

userListModel = new LoadableDetachableModel() {
  @Override
  protected Object load() {
return userDao.findByGroup(UserPanel.this.group);
  }
};
ListView users = new ListView("users", userListModel) {
  // List the users here
};

The last thing I add to this class is the setGroup(Group g) accessor method
that allows me to set the group when it is changed by the user.

Pretty simple really and I am reasonably confident that there isn't too much
wrong so far :)
The next class (the GroupPanel) is a bit more complicated and this is where
I feel I am on really shaky ground...

It starts of pretty much the same as UserPanel...

class GroupPanel extends Panel
{
  @SpringBean
  private GroupDao groupDao; 
  private Panel userPanel; // Reference to the user panel so that I can ask
it to update itself.

  IModel userGroupListModel = new LoadableDetachableModel()  {
@Override
protected Object load() {
  return userGroupDao.find(null); // Return all the groups
}
};


Now for the hard part...

ListView groups = new ListView("groups", userGroupListModel) {
  @Override
  protected void populateItem(ListItem item) {
final Group group = (Group)item.getModelObject();
Link groupSelectorLink = new AjaxFallbackLink("groupSelector",
item.getModel()) {
   @Override
   public void onClick(AjaxRequestTarget target) {
 UserPanel panel = (UserPanel)GroupPanel.this.userPanel; // Really
ugly 
 panel.userListModel.detach();
 panel.setUserGroup(group);
 target.addComponent(container); // "container" refers to the WMC
set in the Page class
   }
};
 

As I said earlier, this code seems to work fine, but I have a couple of
nagging worries:
1) Is is advisable/wise to pass object references around between panels. I
saw a post elsewhere on this list that mentioned it may be a bad idea
because the Serialization will break these references. It doesn't seem to,
but I am only a single user running on a development server at the moment. I
would hate for everything to break at a later stage.
If this *is* a bad practice, what is the correct way to do this?

2) Is manually calling the detach() method of the model the best way to get
it to refresh when the Ajaxified link is clicked on? It seems like a bit of
a bodge, but I can't think of any other way :(

3) I have passed references to my WMC containers in the constructors of my
Panels (not shown in the above code). This is really ugly and I am convinced
there must be a better way. I originally tried calling getParent() assuming
it must refer to the component above my Panel in the component hierarchy. As
it turns out, it doesn't. Can anyone give me a definitive answer on what
getParent() refers to? I couldn't figure it out from the API docs :(

If you got this far, thanks for reading though all this. I know it is a bit
long-winded :)
Any feedback will be *greatly* appreciated.

-- 
View this message in context: 
http://www.nabble.com/Panel-data-interchange---concept-validation-tp22541467p22541467.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: counting/summing items in a list view

2009-03-11 Thread triswork

Hi

It isn't working because you are using a static model on your Label.

So, when your label component calls the model's getObject() method, the
underlying object is the String value originally returned by
adder.getValue(), NOT the actual adder itself.

An easy fix is to make your model dynamic. Something like this should do it:
add(new Label("mySum", new Model()
{
  @Override
  public Object getObject()
  {
return adder.getValue();
  }
});

Have a look at PropertyModels for a more elegant solution :)



Brill Pappin wrote:
> 
> I have an issue I'm sure someone else must have come across at one  
> point or another.
> It's essentially to do with rendering order. Take the following example:
> 
> final BigDecimalCalc adder = new BigDecimalCalc();
> 
> add(new ListView<...>("myListView", yModel(...)) {
>   ...
>   protected void populateItem(ListItem<...> item) {
>   ...
>   BigDecimal total = ...;
>   adder.add(total);
>   }}
> });
> 
> add(new Label("mySum", adder.getValue());
> 
> So of course the mySum label gets rendered before the listView items  
> have been rendered, which in turn means that the result for mySum is  
> always zero.
> 
> Now I could likely pre-load my data and make my calculations before  
> sending it to the components, but it seems to me that since I'm  
> iterating over the data anyway, I'd like to use that loop for doing  
> something like sum the elements in the list.
> 
> Does anyone have a solution for this or is there some Wicket magic I  
> haven't found yet?
> 
> - Brill
> 
> -
> 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://www.nabble.com/counting-summing-items-in-a-list-view-tp22448946p22450359.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



Updating Main Page From Modal Using AJAX

2009-03-10 Thread triswork

Hi

I am having a problem that I hope someone can shed some light on.
On my main page, I have a panel that simply displays a list of users (using
a LinkedList as a model).

Next to the panel, there is a link to open my modal window that contains a
list of all my users. I am trying to implement a solution in which I can
click that "add" button next to each user in the Modal window and have it
populate the panel on the main page (without closing the window).

I have tried a number of solutions without any success so far.

My code looks something like this:

public class MainPage() {
  private List users = new LinkedList();
  MainPage() {
WebMarkupContainer wmc = new WebMarkupContainer("userPanelContainer");
wmc.setOutputMarkupId(true);
wmc.add(new UserPanel("userPanel", users)
...
  }
}

I have set the model of my UserPanel to my linked list and wrapped it with a
WebMarkupContainer so that the panel can be easily replaced using AJAX.

I then create my modal window like this:
final ModalWindow userSelector = new ModalWindow("userSelector");
and
recipientSelector.setPageCreator(new ModalWindow.PageCreator() {
  public Page createPage() {
return new RecipientSelectionWindow(MainPage.this.users, 
   MainPage.this.wmc);
  }
});

The idea here being that I can add the user in my modal window to the
underlying LinkedList and have a handle to the wmc for any AJAX
updates.


In my modal window, I have the following onClick() method for my "add" link:
public void onClick(AjaxRequestTarget target) {
  User selected = (User)getModelObject();
  userList.add(selected);
  if (target != null) {
target.addComponent(markupContainer);
  }
}

I thought that this approach should be OK, but if fails miserably. The panel
on the main page never updates. Even if I refresh the page manually (F5).

The funny thing is though, that if I look at the AJAX DEBUG window, the
response seems fine and the ID tags are all correct. I suspect that the AJAX
response is being applied to my Modal window rather than my main page.

If I use my debugger, I can see the underlying LinkedList being
updated too, but che changes are never displayed.

I am quite new to wicket, so I expect that I am doing something really
daft...  I just can't figure out what it is. I am also sure that my current
approach is not optimal. Any suggestions on the "correct" way to do this
will also be greatly appreciated.
-- 
View this message in context: 
http://www.nabble.com/Updating-Main-Page-From-Modal-Using-AJAX-tp22441758p22441758.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: A massive flaw in my understanding of Wicket

2009-03-06 Thread triswork

Hi Daniel

Thanks for that. It solves the problem completely. I still don't understand,
however, what actually happens under-the-hood (i.e. What does Wicket do if I
don't call setRedirect(true) - and why does this break my application?)

Regards,

Tristan



Daniel Peters-2 wrote:
> 
> Hi tristan,
> 
> try adding setRedirect(true) before calling setResponsePage. I think that
> should work:
> 
> public TestLogoutPage()
> {
> MySession.get().invalidate();
>   setRedirect(true); // <---
> setResponsePage(getApplication().getHomePage());
> }
> 
> 
> regards
> Daniel
> 
> -
> 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://www.nabble.com/A-massive-flaw-in-my-understanding-of-Wicket-tp22369056p22371850.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



A massive flaw in my understanding of Wicket

2009-03-06 Thread triswork

Hi 

I am new to wicket and have run into a problem in the development of my
application. The problem has a few workarounds, but I am afraid it is
pointing to a far larger gap in my understanding of Wicket. If anyone can
tell my what is going on here, I will be *very* grateful. I put together a
test app to illustrate:

public class TestPage1 extends TestBasePage
{
public TestPage1()
{
User user = MySession.get().getUser();
String userDescription = (user == null? "No User" :
user.toString());

add(new Link("login")
{
@Override
public void onClick()
{
MySession.get().setUser(new User(1, "Mr", "T", "Test",
"t...@test.com", "12", "test", "test"));
setResponsePage(getApplication().getHomePage());
}

@Override
public boolean isVisible()
{
return !MySession.get().isAuthenticated();
}

});

add(new Label("user", userDescription));

//add(new Link("logout")
//{
//@Override
//public void onClick()
//{
//MaiaSession.get().invalidate();
//setResponsePage(getApplication().getHomePage());
//}
//
//@Override
//public boolean isVisible()
//{
//return MySession.get().isAuthenticated();
//}
//});

add(new BookmarkablePageLink("logout", TestLogoutPage.class)
{
@Override
public boolean isVisible()
{
boolean result = MySession.get().isAuthenticated();
return result;
}
});
}
}


The TestLogoutPage is very simple:
public class TestLogoutPage extends BasePage
{
public TestLogoutPage()
{
MySession.get().invalidate();
setResponsePage(getApplication().getHomePage());
}
}

If I use the commented out code for the logout link, it works as expected.
If, however, I use the BookmarkableLink to the TestLogoutPage, the
application breaks. If I click "logout", the page doesn't refresh unless I
do it manually (F5). If I click logout again, then the page refreshes, but
any subsequent clicks (of either login or logout) give me a Page Expired
message.

I dont understand
1. Why the Bookmarkable page version isn't working and
2. Why the pages expire if I call logout multiple times.
-- 
View this message in context: 
http://www.nabble.com/A-massive-flaw-in-my-understanding-of-Wicket-tp22369056p22369056.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