You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Bruno Borges (JIRA)" <ji...@apache.org> on 2011/09/02 01:16:09 UTC

[jira] [Commented] (WICKET-4007) New tag wicket:var

    [ https://issues.apache.org/jira/browse/WICKET-4007?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13095667#comment-13095667 ] 

Bruno Borges commented on WICKET-4007:
--------------------------------------

What is the difference between this feature and wicket:message?

With wicket:message you can reference a (static) String (from a resource bundle) in several places within the same markup. If one wants to add such a String, he/she does not need to modify the Java side, just the HTML.

The Wicket way is been kept here. wicket:var injects a Label component per reference for a variable. So models would be converted properly with registered Converters. If one wants to use a different converter, so better use the current "Wicket way" or register a custom data type and converter.

This feature seems to be stupid, but I starting to get tired of writing codes like this:

add(new Label("address1", addressPropertyModel));
add(new Label("address2", addressPropertyModel));
add(new Label("address3", addressPropertyModel));
add(new Label("address4", addressPropertyModel));

Or: 

add(addressLabel(1));
add(addressLabel(1));
add(addressLabel(1));
add(addressLabel(1));

Label addressLabel(int i) { return new Label("address" + i, addressPropertyModel); }

Or 

addAddressLabel(1);
addAddressLabel(2);
addAddressLabel(3);
addAddressLabel(4);

void addAddressLabel(int i) { add(new Label("address" + i, addressPropertyModel)); }

Or

for(int i = 1; i <= 4; i++) addAddressLabel(i);

And everytime I must display that information somewhere else in the same page, I must edit the Java code.

Really, this feature is not something like EL ${JSF}. It's similar, but differente because inside of this tag implementation, the "Wicket way" is being respected. A label is being created for each reference of that variable.

wicket:var IS a component. It's a hint for a Label component referencing a model. Just like wicket:message is a Container component. In fact, this feature is basically WicketMessage. I didn't have to make lots of changes.

If wicket:var is considered to be against the Wicket way, so wicket:message should be considered as well.

> New tag wicket:var
> ------------------
>
>                 Key: WICKET-4007
>                 URL: https://issues.apache.org/jira/browse/WICKET-4007
>             Project: Wicket
>          Issue Type: New Feature
>          Components: wicket
>            Reporter: Bruno Borges
>              Labels: tag,, variable, wicket,
>         Attachments: wicket-var-feature.diff
>
>
> This will facilitate users to reference models in several places of the markup.
> One can do: 
> class Page extends WebPage {
>   public Page() {
>     putVariable("username", "Peter Johnson");
>   }
> }
> <html>
> <body>
>   <div class="header">
>     <wicket:var name="name" />
>   </div>
>   <div class="container">
>     <wicket:var name="name" />
>   </div>
>   <div class="footer">
>     <wicket:var name="name" />
>   </div>
> </body>
> </html>
> It will be possible too to do such a thing:
>   Java:  putVariable("css", "blue-header");
>   HTML:   <div wicket:var="class:css">
> And render: <div class="blue-header">
> These variables can be rendered multiple times and my also be accessed from child objects (but not the opposite), like:
>   add(new WebMarkupContainer("header"));
> <div wicket:id="header">
>   <span wicket:var="class:css">Header</span>
> </div>

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira