Wicket Internationalization : Multiple Properties file for Multiple Pages? - internationalization

the wicket internationalization example available has the following file structure
HomePage.java
HomePage.html
HomePage.properties
WicketApplication.java
HomePage_nl.properties
Now when creating a project with multiple HTML pages, for example i have
HomePage.html and Login.html, is there a way that i can save all key-value pair in single property for a particular language
or
i will have to have to create all these files
HomePage.properties
HomePage_nl.properties
Login.properties
Login_nl.properties

Wicket will try to find message resources using the following rules:
Wicket will try to find the message starting from the Page and drilling down to the specific Component through the component hierarchy of the Page. Notice this is a top-down search.
When a message is not found in the component hierarchy, it will be looked for in the Application class.
The lookup for a resource in every class works in the following way :
Localised searches appending the locale to the file name (Login_nl.properties, then Login.properties), just like Java's ResourceBundles do.
Down-top through the class hierarchy. That means that if a resource is not found in a class, it will be searched in its superclasses all the way until it hits java.lang.Object.
So, in your specific case, if Login is a Panel inside HomePage, you can just define the resources in HomePage(_nl).properties. Also, if there are specific application-wide messages, remember that you can define them in WicketApplication(_nl).properties.
You might find the following Wicket wiki page : Everything about Wicket internationalization useful, it elaborates on this matter.
(...). This is facilitated by first looking up the message
(following the algorithm above) for every parent in the component
hierarchy (aka page hierarchy). Every component can override the
messages of its child components, so the search starts at the page's
properties and then trickles down to the component that uses it (yes,
its top-down). In order to make overrides specific to a certain child
component, you can prefix the message key with the component id of the
child. See ComponentStringResourceLoader for more details.
If no message was found in the page hierarchy, another search starts
which will look at your application class and its super classes. So
Wicket first looks at MyApplication.properties (provided MyApplication
is the name of your application) and then up the class hierarchy,
passing org.apache.wicket.Application, up to java.lang.Object. This is
how Wicket provides its many default i18n texts.

Related

How to re-render certain object descriptions with Sphinx docs?

Using Sphinx's domain-aware ObjectDescriptions I can create fancy rendered documentation for them. For example:
.. py:function:: pyfunc()
Describes a Python function.
This renders the content in a nice way, and this works really well with module indices, references and so on. Cool so far!
Now, let's say I have that directive in a source document src/mymodule/functions.rst, and I have a bunch of text in src/guide/getting-started.rst, I can reference to the objects like
:py:func:`pyfunc`
Also cool!
Now, my actual question; Could I also tell the Sphinx writer to re-render the same documentation snippet for that object? To ease the user in not having to navigating away from the Getting Started page where I just want to include a single piece of content again.
What I've tried to do:
Simply copy the contents. This results in a warning that the object is defined multiple times, hurts the index and as a result references don't point to the "authoritative" place in your project, if unlucky. Not okay.
Document each object in its own file and then use .. include:: rel/path/to/pyfunc.rst in each document where I want to render it. As those includes are literal on ReST-level, this results in the same downsides as the option above. :-(
Thus, I'm looking for a solution where I would tell the renderer/writer of Sphinx to simply re-render the contents of a reference instead of producing a link. It should not add it to the index for a simple re-render.
I'm okay with a custom extension or a domain-specific custom solution - I'm already using my own custom domain, but I just used the general Python domain above as a well-known example.
Context for the use case: I'm building a Protobuf domain. Protobuf messages and enums are reused a lot and I would like to show the context of commonly reused objects inline on pages where this is useful to the reader. This means it is repeated over the whole project on purpose where it is deemed useful rather than navigating away all the time. Yet only the reference page should be "authoritative".
I've been successful with a dirty hack: abusing the XRef role logic. Cross-references in Sphinx render dynamically (e.g. Table 23) by producing arbitrary 'nodes'. By:
keeping a copy of the parent node during parsing in a custom Domain
registering a custom Sphinx/ReST XRef role to render a whole set of nodes (the saved parent node)
re-running the ReferencesResolver another time
... this basically does what I need. But yuck, it's rather ugly.
Working example I implemented in a Protobuf Domain extension.

Best Practices: how to design Page Object test suites for multiple similar web sites

I'm starting to re-design all my test suites with the Page-Object model, but, every documentation or tutorial I've found show examples in single-site projects, and in my case, I have like 10 or more sites (and the list is growing, next year there will be like 20 or 30 sites) that share near 90% of the UI elements and data, and other sites that share like 50-80% of the UI elements and data. Also, the sites have mobile versions that have somewhat different UI elements from the Desktop versions, say they are 80% similar than the Desktop versions.
What is the best approach to design something with this scenario in mind? Should I design it like to have a different Page-Object class for every site and for Desktop/mobile versions? or should I group them in Desktop and Mobile versions respectively naming the elements with the prefix name of the Site? I cannot seem to found any standard for situations like this.
In a Page Object Model, you should ideally have 1 class for each screen/page which encapsulates all your objects and methods within that page.
Create a new page class for each screen. I would suggest have an abstract class for each page (with all the common say 90% objects defines ) and make sure your methods are overridable from the child classes. There can be multiple child classes of each page object abstarct class (eg different technologies Modile/Desktop) where you can override any method that doesnt use the common abstract method in that particular technology.
Maintain separate object classes(per page) which will maintain properties of all your objects in that page. To read more on page objects model visit:
http://testautomationlove.blogspot.in/2016/02/page-object-design-pattern.html

How to architect bean retrieval from DAO vs. User Entered Data bean

I am a total newb to Spring. Even though I understand the concepts of individual annotations (and dependency injection), I am having difficulty "seeing the forest for the trees." Here, in this example, I have a page that has a dropdown box. It also stores the user's selected option from that box. So there are three beans, only one of which is properly called a domain bean:
DropDownEntry *domain
SelectedOption (which could be String or a whole DropDownEntry type stored at Session Scope)
PageModel (containing a List of #1 above, and a single instance of #2)
Below is an image of my best guess as how to use Spring to:
1. Retrieve a List from the persistence layer via DAO
2. Retrieve/Store the user's selection
Is this design remotely near correct? Is there an alternate "best practices" way to architect this scenario?
I think Spring MVC Forms might be what you are looking for.
http://www.javacodegeeks.com/2013/07/spring-mvc-form-handling-vol-5-select-option-options-tags.html
Model
The model is a map of entries for the drop down box.
Controller
You can fetch these entries from a database using the DAO Pattern and turn it into a map in a controller class.
View
The drop down box is generated using a mix of HTML, a JSP tags and map of 'drop-down' entries.
Hard to tell. But from the looks of it, you've made things awfully complicated.
My advice: stop drawing UML, re-read the specification, and start coding. Start with a simple model class that represents the selectable entity. Don't name it DropDownEntry (unless you're creating software to model dropdowns), but something that actually describes the selectable entity. Don't worry about data access (DAOs) at this point.
Then create a controller class that allows you to render a view that contains the said dropdown UI element. Then pass the selectable entities (as reference data) to the view in the model. Then make the view render the selectable entities appropriately. Then allow the user to post the selection back to your controller.
Once you have this, you can think about saving the selected entity to persistent storage. At that point you will probably find out that you need to link the selected entity to a user etc.
Good luck.

Magnolia Blossom : Two pages sharing the same area

I'm using the Magnolia Spring Integration (Blossom) for my web app and I definitely don't understand how (if it's even possible) to share a unique area between two pages.
This is how I've worked so far :
I have three templates main-template, template-1 and template-2.
template-1 and template-2 both redirect to main-template by redefining their own "body" areas.
In the class of template-1 I have three areas : content-area, area-1 and area-2
In the script of template-1 I include the three areas with the following directives : [#cms.area name="content-area"/], [#cms.area name="area-1"/] and [#cms.area name="area-2"/]
The same areas are defined in the template-2 class and script
What I want is to share, lets say, area-1 between template-1 and template-2. The problem is that by redefining them in each class they are considered like different areas...
Through my tests and the magnolia documentation, what I understand is that an area can only be defined within a template class so it can be accessed in the script of this template and only the areas defined directly in the template class associated with the page will be process/rendered.
No matter what I try, as long as the areas are not defined in the page's template class they cannot be accessed and therefore included pages don't have their areas rendered.
Does anyone have a clue in how I can "include" or process "areas" from other templates in another one ? Or am I doing it all wrong ?
Thank you for your time.
regards.
I know this is an old question, but it is still a valid question, so let me answer it:
As far as I know areas can inherit from other areas (normal Java class inheritance using "extends ..."). As far as I know this wasn't available in 2013 yet, but it is now. I know this because I filed this as a feature request once and it was marked as solved at some point, and I think I also successfully used it once (don't remember clearly).
If for some reason it's still not possible to extend areas from super classes, then you could still use conventional tools like putting the logic to a helper class and making the actual areas very slim (that is just calls into the shared helper class). And the actual template (.jsp or .ftl file) can be shared anyway.

Generating Navigation for different user types, MVC, PHP

I have this idea of generating an array of user-links that will depend on user-roles.
The user can be a student or an admin.
What I have in mind is use a foreach loop to generate a list of links that is only available for certain users.
My problem is, I created a helper class called Navigation, but I am so certain that I MUST NOT hard-code the links in there, instead I want that helper class to just read an object sent from somewhere, and then will return the desired navigation array to a page.
Follow up questions, where do you think should i keep the links that will only be available for students, for admins. Should i just keep them in a text-file?
or if it is possible to create a controller that passes an array of links, for example
a method in nav_controller class -> studentLinks(){} that will send an array of links to the helper class, the the helper class will then send it to the view..
Sorry if I'm quite crazy at explaining. Do you have any related resources?
From your description it seems that you are building some education-related system. It would make sense to create implementation in such way, that you can later expand the project. Seems reasonable to expect addition of "lectors" as a role later.
Then again .. I am not sure how extensive your knowledge about MVC design pattern is.
That said, in this situation I would consider two ways to solve this:
View requests current user's status from model layer and, based on the response, requests additional data. Then view uses either admin or user templates and creates the response.
You can either hardcode the specific navigation items in the templates, from which you build the response, or the lit of available navigation items can be a part of the additional information that you requested from model layer.
The downside for this method is, that every time you need, when you need to add another group, you will have to rewrite some (if not all) view classes.
Wrap the structures from model layer in a containment object (the basis of implementation available in this post), which would let you restrict, what data is returned.
When using this approach, the views aways request all the available information from model layer, but some of it will return null, in which case the template would not be applied. To implement this, the list of available navigation items would have to be provided by model layer.
P.S. As you might have noticed from this description, view is not a template and model is not a class.
It really depends on what you're already using and the scale of your project. If you're using a db - stick it there. If you're using xml/json/yaml/whatever - store it in a file with corresponding format. If you have neither - hardcode it. What I mean - avoid using multiple technologies to store data. Also, if the links won't be updated frequently and the users won't be able to customize them I'd hardcode them. There's no point in creating something very complex for the sake of dynamics if the app will be mostly static.
Note that this question doesn't quite fit in stackoverflow. programmers.stackexchange.com would probably be a better fit

Resources