ajax links produce too long javascript

2010-09-01 Thread Vladimir Kovalyuk
Consider this javascript generated by AjaxFallbackLink:

wicketShow('overlapping-div');var
wcall=wicketAjaxGet('../../?x=Gusbl7hNSWOo5OPifLRHlQ',function() {
;wicketHide('overlapping-div');}.bind(this),function() {
;wicketHide('overlapping-div');}.bind(this), function() {return
Wicket.$('link8f') != null;}.bind(this));return !wcall;

I believe it is worth extracting redudant code from this snipped into a
function. The result would take less space:

wicketAjaxGet2('../../?x=Gusbl7hNSWOo5OPifLRHlQ', this, 'overlapping-div')


AjaxRequestTarget.addComponent does not work after RequestCycle.setResponsePage was called

2010-08-25 Thread Vladimir Kovalyuk
Once setResponsePage is called the AjaxRequestTarget is pushed down in the
list of request targets and AjaxRequestTarget won't be called anymore
because AbstractRequestCycleProcessor.respond invokes the current request
target only.

My page has some ajax links that delegates handling to different module and
link does not know whether redirect happens. The link still has to update
some components. But in case of redirect all the updates aren't applied and
backbuttoning shows old state (actually with ajax indicator covering all the
page so any element is not clickable).

I believe it makes sence to defer switching to different request target
until finishing responding on ajax request.
https://issues.apache.org/jira/browse/WICKET-3010


possible bug?

2010-03-31 Thread Vladimir Kovalyuk
It seems the following trick does not work for nested forms:

protected void onRender(final MarkupStream markupStream)
{
// clear multipart hint, it will be set if necessary by the visitor
this.multiPart = ~MULTIPART_HINT;

// Force multi-part on if any child form component is multi-part
visitFormComponents(new FormComponent.AbstractVisitor()
{
@Override
public void onFormComponent(FormComponent? formComponent)
{
if (formComponent.isVisible() 
formComponent.isMultiPart())
{
multiPart |= MULTIPART_HINT;
}
}
});

super.onRender(markupStream);
}

Since multiPart is serializable it will remember multipart hint for the next
render on nested form even when the component tree does not contain file
upload component anymore. As the result the form will be multipart encoded
(see onComponentTag) but then handled with stardard request handler because
the hint in nested form is cleared only on its own onRender invocation.

Does it sound like a bug? Should I proceed with creating a test for that?


Client side events in Wicket, what do you think about that?

2010-03-05 Thread Vladimir Kovalyuk
Some thought ...

Last week I thought a bit about reacting on events without client-server
round-trip and without having to write JS. I had an idea - to write event
handlers as methods and annotate them with special annotation
@ClientSideEvent. Then feeding the class to the Java-JS compiler we would
obtain the JS we need to embed into the page. And something similar about
component model - properties annotated with @ClientSide would be available
to client-side events (and marshalled to the server as path scoped cookies
for instance).
To start experiment with that I downloaded GWT 2 devkit and had a look to
their compiler. Unfortunately it is not capable to compile single class into
JS. It requires a bunch of configuration and core infrastructure and it
always generates HTML. The class of your interest would be the inlined JS
script within the generated HTML. That does not suits. And BTW gwt compiler
is slow as hell (minutes!!!), how people are happy developing GWT
applications?

Then I realized what I'm looking for - the decompiler from .class file to
.js file with some filtering capabilities.
Having such a tool it becomes possible to add dynamically decompiled .js
resources to the components (js accessible via URLs) and write client-side
state in Java, along with server-side state. All we would need to implement
are client side context and client-state marshalling.

Although it seems doable I'm afraid it may be extremely expensive to develop
and support such a tool. And it would require some changes in Wicket
rendering process (opeate with attributes in dom manner instead of handling
onComponent rendering event).

The next generation of HTML/JS would evolve towards client programming
capabilities. I like Wicket for its full freedom of HTML (contrary to GWT)
and I would like to use similar model when programming rich web client
applications. And it is less about the Wicket way of splitting html and
java. It is more about binding to dynamically loadable data with any deep of
structure displayed on users demand. The GWT way would require to program it
in any way when Wicket does it transparently. Another story is authorization
that can be done transparently. But web development evolves and client side
programming becomes more and more demanded. I tried to think about how
technically we could use the best of both worlds.

What do you think about all that?


Proposal: Fake implementation of AjaxRequestTarget instead of null

2009-10-23 Thread Vladimir Kovalyuk
I believe all those null-checks of request target can be omited in user code
if fallback components would provide fake implementation of
AjaxRequestTarget instead of passing null.

Does it make sense?


[offtopic[ how to attach sources to wicket jars when debugging

2009-09-29 Thread Vladimir Kovalyuk
I believe it must be something extremely simple.
I set up a project in Eclipse Galileo using m2eclipse from Sonatype.
I'm trying to debug the wicket class. I set breakpoints and the execution
stops exactly at those points. The wicket sources are actually attached. I
can see the source code. But when the execution stops at breakpoint eclipse
says that there is no sources and variables panel does not show local
variables.

Could somebody give me a hint how I can debug wicket sources?


how to control visibility of Border's markup?

2009-09-20 Thread Vladimir Kovalyuk
I would like to control programmatically the visibility of the border
itself, meaning that components within the border are always visible.

I can create two different borders and switch between them but it looks too
complicated.


defaultFormProcessing is no longer considered when processing multipart form in ajax request

2009-09-09 Thread Vladimir Kovalyuk
I added AjaxFallbackButton(Cancel).setDefaultFormProcessing(false) to the
multipart form and when it is pressed the form is handled as well as the
button would have defaultFormProcessing=true.

It happens because request parameters does not contain the name of the
submitting button.

The magic is in the new code in wicket-ajax.js

// Submits a form using ajax.
// This method serializes a form and sends it as POST body.
submitForm: function(form, submitButton) {
if (this.handleMultipart(form)) {
return true;
}
var body = function() {
var s = Wicket.Form.serialize(form);
if (submitButton != null) {
s += Wicket.Form.encode(submitButton) + =1;
}
return s;
}
return this.request.post(body);
},

I believe the problem is caused by handleMultipart(form) invocation.
submitForm function accepts submitButton parameter but does not passes it to
handleMultipart function.

Igor could you clarify that?


css filter that evaluates expressions

2009-09-09 Thread Vladimir Kovalyuk
Richfaces has one useful feature. It parses .xcss files, finds expressions,
evaluates them and replaces expressions with evaluated values.

for instance:

td.odd {
   background-color: ${some.expression};
}

Does anybody know something similar that could be employed in Wicket?


intercomponent communications

2009-07-28 Thread Vladimir Kovalyuk
I don't see much buzz about this topic here, just a request for the trick
for the forthcoming Johnatan Locke book. So it seems for now that just a few
poople are interested in.

I experienced problems in different places with approaches where components
are loosely coupled and they try on their own to find the component which is
supposed to be the source of events.

I ended up with a form that serves as a subscription service for the
components and dispatches the events. Let me know if somebody is interested
in the implementation.


how do you implement OpenEntityManagerInView for JEE applications?

2009-07-25 Thread Vladimir Kovalyuk
I came to Wicket from JSF where I used Seam for managing persistence
contexts.
Actually the latest stable version of Seam is incompatible with Wicket 1.4,
and I realized that the project uses just three things from Seam. One of the
critical things is Seam-managed persistence context. When you don't use Seam
long-running conversations it just degrades to something like Open Session
in View.

What solution do you use for JEE applications? AFAIK there are several
projects that use JPA in contextless form. But it does not work so simply
with JNDI and JTA in JEE container.


how to create a BookmarkablePageLink for the particular page instance

2009-07-25 Thread Vladimir Kovalyuk
I created a breadcrumbs panel that automatically creates a series of
bookmarkable links from the home page to the page that displays a details of
currently viewing entity instance.
Usually it looks like for instance home|folders|folder1|folder1.1|document

From the other hand when the user comes to this particular document by
opening folders and then the document itself she produces a page versions
that makes page history. There is an button back or close on the page
that returns the user to the previous page in the history.

As the result breadcrumbs and history forms two different ways of navigation
but they both are natural and required.

The problem is that clicking on the particular link in breadcrumb panel
leads to creating a new version of page. I use HybridUrlCodingStrategy and
it seems pretty possible to add version attributes to the url. But I don't
know how to do it in compatible manner. It seems that the only link that
forms the bookmarkable URL using hybrid strategy is the
BookmarkablePageLink. But it does not accept anything from the particular
page version.

Please help


How to determine which behavior corresponds to the currently handled request target

2009-07-23 Thread Vladimir Kovalyuk
I'm trying to design a joda time based DateTime field. There are two reasons
 - I use joda time only
 - I have to wire tree components - start date, finish date and duration, so
I have to add

I managed to get it working but I'm concerned about the approach I took. So
please critics are welcome. Below is the source code of the component.

My question is about the isAjaxRequest() method. I believe I should check
whether the AjaxFormComponentUpdatingBehavior's request target is handled.
But I don't know how. Please suggest.

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.behavior.IBehavior;
import org.apache.wicket.datetime.DateConverter;
import org.apache.wicket.datetime.StyleDateConverter;
import org.apache.wicket.datetime.markup.html.form.DateTextField;
import org.apache.wicket.extensions.yui.calendar.DateField;
import org.apache.wicket.markup.html.form.FormComponentPanel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.protocol.http.WebRequest;
import org.joda.time.DateTime;

public class JodaDateField extends FormComponentPanelDateTime {

protected class LocalDateField extends DateField {

protected final class LocalDateTextField extends DateTextField {
public LocalDateTextField(String id, IModelDate model,
DateConverter converter) {
super(id, model, converter);
}

@Override
protected void onModelChanged() {
super.onModelChanged();
if (isAjaxRequest()) {
Date date = getModelObject();
LocalDateField.this.setModelObject(date);
}
}
}

public LocalDateField(String id, IModelDate model) {
super(id, model);
}

@Override
protected DateTextField newDateTextField(String id, PropertyModel
dateFieldModel) {
@SuppressWarnings(unchecked)
IModelDate model = dateFieldModel;
return new LocalDateTextField(id, model, new
StyleDateConverter(true));
}

@Override
protected void onModelChanged() {
super.onModelChanged();
if (isAjaxRequest()) {
Date date = getModelObject();
JodaDateField.this.setModelObject(date == null ? null : new
DateTime(date));
}
}
}

private DateField dateField;;

public JodaDateField(String id, IModelDateTime model) {
super(id, model);

dateField = new LocalDateField(field, new ModelDate());
add(dateField);
}

@Override
public Component add(IBehavior... behaviors) {
ListIBehavior correct = new ArrayListIBehavior();
for (IBehavior behavior : behaviors) {
if (behavior instanceof AjaxFormComponentUpdatingBehavior)
dateField.get(date).add(behavior);
else
correct.add(behavior);
}
return super.add(correct.toArray(new IBehavior[correct.size()]));
}

@Override
protected void convertInput() {
Date date = dateField.getConvertedInput();
setConvertedInput(date == null ? null : new DateTime(date));
}

@Override
public String getInput() {
return dateField.getInput();
}

private boolean isAjaxRequest() {
return getRequest() instanceof WebRequest  ((WebRequest)
getRequest()).isAjax();
}

@Override
protected void onBeforeRender() {
DateTime date = getModelObject();
dateField.setDate(date == null ? null : date.toDate());
dateField.setRequired(isRequired());
super.onBeforeRender();
}
}


how to strip wicket tags for particular component

2009-07-20 Thread Vladimir Kovalyuk
I'm trying to convert main menu into components to control visibility of
items depending on the user logged in and the context.
I use borders to wrap menu item into li tags.

The problem is that the rendered markup contains additional wicket:border
and wicket:body tags. They breaks the menu and it is eventually displayed
as the simple list.

Stripping wicket tags at the application level would obviously solve the
problem. But I'd like to keep wicket tags for most markup and strip only for
menu.

Can I override Border class somehow and strip wicket tags manually?


MixedHybridUrlCodingStrategy wanted

2009-07-12 Thread Vladimir Kovalyuk
Is there a worked combination of HybridUrlCodingStrategy and
MixedParamUrlCodingStrategy? What is missed in the latter is ability to stay
bookmarkable after reaction on actions.


How to turn ModalWindow form into multipart form?

2009-06-25 Thread Vladimir Kovalyuk
How to turn ModalWindow form into multipart form?
The problem is that the markup code for that particular form is hard-coded
into modal.js script (surprise!, surprise!).

ModalWindow form submission problems han't been fixed yet, I mean rc5


how to split application properties file into several properties files

2009-06-19 Thread Vladimir Kovalyuk
I would like to split the application properties file into several
properties files.
I know that I can share resources of base component and page among their
descendants and at that I can use package propeties files. I just don't want
to go this way because most of messages are organized in different way than
components and pages.
I wanna just split one file into several distinct files.

What is the best way?


Is inversion of selection of tree item a reasonable default behavior?

2009-06-09 Thread Vladimir Kovalyuk
When in multiple selection mode it makes sense to inverse the selection
state of tree item when user clicks on link of LinkIconPanel.
But in single selection mode it is not an expected behavior. At least in MS
Windows environment.

Please consider the following implementation:

LinkIconPanel {
...
protected void onNodeLinkClicked(Object node, BaseTree tree,
AjaxRequestTarget target)
{
tree.getTreeState().selectNode(node,
!tree.getTreeState().isNodeSelected(node) ||
!tree.getTreeState().isAllowSelectMultiple());
tree.updateTree(target);
}
...
}


Editable select

2009-05-07 Thread Vladimir Kovalyuk
Does anybody know any editable select wicket-component that supports
attaching 'onchange' AjaxFormComponentUpdatingBehavior?


confirm leave page when a page contains unsaved data

2009-04-30 Thread Vladimir Kovalyuk
Do wicket has a generic approach to handling the following scenario?

1. user opens a page with details of some entity, for instance a user.
2. user starts to type in fields
3. user clicks some link, then she is informed that the form contains
unsaved data and asked to press discard and proceed, save and proceed or
cancel.


DefaultDataTable: How to add a DDChoice to change rows per page

2009-04-26 Thread Vladimir Kovalyuk
I would like to add some component, say DropDownChoice, to allow user to
change default rows per page setting for data table.

I've investigated two ways: 1) extend NavigationToolbar or PagingNavigator
2) extends NavigationToolbar to add extra panel right to PagingNavigator

Althought it is possible to completely override PagingNavigator component it
is not so straightforward as I expected.

Please improve DefaultDataTable so it will be capable to change rows per
page.

I also suggest creating child components in all the non-final components via
createXXX methods instead of new keyword in order to simplify overriding.