Something like:
ThisComponent.html:
<wicket:panel>
<script wicket:id="script"> void(); </script>
</wicket:panel>
ThisComponent.java:
//..
final PackagedTextTemplate template = new
PackagedTextTemplate(ThisComponent.class, "ThisComponent.js.template");
Label script = new Label("script", new Model() {
private static final long serialVersionUID = 1L;
@Override
public Object getObject() {
Map<String, String> variables = new HashMap<String,
String>();
variables.put("markupId", ThisComponent.this.getMarkupId());
return template.interpolate(variables).asString();
}
});
script.setEscapeModelStrings(false);
add(script);
ThisComponent.js.template:
|document.getElementById("${markupId}").onmouseover = function() {|| alert("Hello
world!"); ||};
||||
|
Cheers,
Matthijs
Ritz123 wrote:
Matthijs,
Those are good suggestions. I would have gone server side myself. There is a
trade off user experience vs. more robust and it just so happened this time
we are going with better user experience hence the use of javascript. The
javascript, I want to use is very basic, thats the reason why I am not doing
AJAX as there is no need to even go to server side partially. Javascript
will be used purely on the client just to update inner html. Just to give
you an idea - this is for the e-commerce checkout where the entire checkout
can be done from 1 page only with very few clicks, it wont be possible
without the use of javascript.
I didnt find any documentation on using templates for javascript - will
appreciate any pointers.
Thanks
Matthijs Wensveen-2 wrote:
Is there any specific reason you don't want to do this server side? Not
using javascript would make the application more accessible, and
probable also more robust and secure. Unless you're targeting some very
specific user group, I always try not to depend on javascrip / ajax
(that's why I love the AjaxFallback stuff in wicket so much).
Just my 2c.
Matthijs
PS. If you must use javascript, why not use the hidden field's id, which
can be controlled with setMarkupId. But it might be better not to use
setMarkupId (to avoid id collisions). You could write some javascript
(with use of templates) that fills in the markupId (getMarkupId)
dynamically.
Ritz123 wrote:
Hi,
Is it possible to set specific name to the hidden field component?
Here is my usage scenario -
1. I have radio group for shipping options on a page.
2. Depending on the shipping option selected, I need to show the order
total
changed
2. radio has associated model which obviously contains more information
than
just the shipping price
The only way I can think of doing this efficiently without going to the
server side is by using hidden fields for shipping costs. Using the
javascript to update the total on the page. Problem is, seems like hidden
field names cannot be specified or controlled and hence cannot be
referenced
by javascript precisely.
Correct me if I am wrong, also let me know if there is a better way of
doing
this.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]