Wicket - Display same text on multiple places - java

I am building my site for the first time with Wicket and I want to create a portal, where the username would be displayed on multiple places (user menu, header, maybe somewhere else on the page..). Wicket apparently doesn't like labels with the same wicket:id, because I get:
The component [Component id = userName] was rendered already. You can render it only once during a render phase.
Is there some other way to display the same dynamic text on different places without creating a new label for each and every one?

No, there isn't. Best you can do is to subclass a Label that will retrieve the username and use this label in multiple places with different wicket:id's. Like this:
public class UserNameLabel extends Label{
public UserNameLabel(String id) {
super(id, getTheUsernameSomewhereFrom());
}
}

Wicket builds the page to render as a hierarchy parallel to the Dom (HTML) tree. Everything inside Wicket is a component with its own id, mapping to an insertion point within the Dom tree. Rendering would not be deterministic, if components with the same id would be reusable (this would result in a math. graph obscuring the hierarchy and, as a graph, would result in cycles).
The simple answer is that you cannot reuse components.
I would not recommend to fiddle with the ids. Just use the OOP way and create a base component that adds/provides the labels.

Related

ADF Web Application: how to add and modify UI components on page loading (before it's displayed)?

I would like to know which are the different available approaches to add, modify and delete UI components before a page loaded.
A practical example that I should handle is the following:
In my ADF Fusion Web Application (developed with JDev12.1.3) there are the pages login.jspx and main.jspx: if the user logs in correctly navigation to main.jspx happens.
In main.jspx there is an empty menu bar that at runtime I would like to fill with menus and menu items when the page loads, in function of the logged in user.
In the same page, in function of the logged in user, I also would like to add at runtime some UI components (output texts, buttons, ...) whith the chance to set their properties.
Could you kindly advice me which approaches I can follow to accomplish these duties?
Thanks,
Federico
Why not using the rendered attribute? Based on the condition the components will be rendered or not.
Personally the two approaches i've used on my works where:
1. Using the beforePhaseListener on the f:view component. Example: Before Phase on JSF page. But it might cause you some problems when taking account of adf lifecycle, especially if you have integrated parts (or even some simple jQuery components...).
2. And i think this would just do fine in your case, use a f:event component of type "preRenderComponent". Example: How to use prerendercomponent. I suggest this second option
Note: It's true that these aren't ADF Faces components, but since it's built on top of JSF, they work as they should. I can assure you they do work on 11g and don't expect any problems on 12c.
I see two approaches. Use addChild() and related methods to physically add/remove menu items, or have the menu pre-built and use the visible property to show hide items.
As far as making this happen in custom code, you can use a Backing Bean (Managed Bean) that contains the code to determine what items to add/remove or make visible based on whatever criteria you choose. To call this code, you can 1) use the Invoke action in the rebinding layer - have it call the desired backing bean method - make sure to drag the Invoke action the TOP of the executables list. This is the older, less preferred method. The newer, more preferred method is to add the backing bean method to the Task flow and have it navigate to the deserted page. This method can be part of the navigation form another page. Ex: After successful Login, navigate to your method an chav sit navigate to the Main page. The method will execute before the page loads and will set values to have the items added or visible or not.
RichSelectOneChoice choiceList;
List child = choiceList.getChildren();
child.clear();
for (int i = 0; i < child.size(); i++){
child.remove(i);
}
if ("1..1".equalsIgnoreCase(ccCode)){
UISelectItem addChild = new UISelectItem();
addChild.setItemLabel("1..1");
addChild.setItemValue("1..1");
child.add(addChild);
} else if ("0..1".equalsIgnoreCase(ccCode)){
UISelectItem addChild1 = new UISelectItem();
addChild1.setItemLabel("0..1");
addChild1.setItemValue("0..1");
child.add(addChild1);
UISelectItem addChild2 = new UISelectItem();
addChild2.setItemLabel("1..1");
addChild2.setItemValue("1..1");
child.add(addChild2);
}
Have you posted this question to he ADF forum, here?

Eclipse Plugin - TreeViewer display large amount of Text

I am currently writing on a Plugin that uses a view with a TreeViewer. The thing is, as content for my Nodes I get plain HTML. I would like to display the HTML styled or, if not possible, the simple plain text without any HTML. But the issue I run into is that the TreeViewer is not displaying enough text.
As you can see the HTML is not completly displayed and that everyting is only one line is not pretty aswell. I would like to have a box or something that can display the text (doesnt matter if the box does not support the HTML-styling, I can do this from hand).
Currently I'm using a LabelProvider that is returning the Text of a Node as string (and from what I can see this is the only possible Option with a LabelProvider).
As workaround I could only think of cutting the text into serval nodes but I would like to know if there are better options out there ;)
If it's your own LabelProvider, you can truncate or manipulate the text shown however you wish. Since it ultimately ends up as a native control, you're basically stuck with text label with a single image (plus whatever IColorLabelProvider offers) as long as you're using a tree control.
You could experiment with the Figures from the GEF project or the Nebula CompositeTable as alternatives.
you can use a editor to show the content, this would be appropriate with your requirement. View can also be think for it. tableviewer clould also be least choice. TreeViewer generaly use to deal with hierarchical data.
There are several label providers available in Eclipse in the org.eclipse.jface.viewers package. You can choose to implement your own or extend one of them to choose your need.
Looking at the image, I would recommend to display only few words in the tree and the entire content of the node could be in a different pane/tool tip.

How to create a left navigation pane using facelets in JSF?

I need to create a user interface where the content changes every time the user moves to a new page. However, the header and footer remains the same.
But, within the content, there is sometimes a left pane visible on some of the pages.
I'm not sure how can this be achieved since I'm new to using JSF.
Can someone please suggest a way?
Thanks!
You can achieve this by creating 2 different layouts and using for the correct layout
one with left rail
another without left rail
You need to look at JSF template with Facelets
Here are some links that you can refer
Link 1
Link 2
For the 'puzzly' composition of pages you need to use templating. Great overview can be found in the answer to How to include another XHTML in XHTML using JSF 2.0 Facelets?. The layout itself is HTML/CSS-related, so you need to check that out first.
If you want to produce one part of a template conditionally, there are two possibilities: to do that from a master template, or to do it from a template client. Of course, you could create many templates, as others recommend, but this is counterproductive and hard to maintain in my opinion.
If you want to render a part of template conditionally, you can include rendered="#{view.viewId = '...'}" attribute to JSF components in master template.
Alternatively, if you want to 'overwrite' the default part of a template, that for example has a left panel, just define the target area as an empty one in a template client like <ui:define name="left" />.

Multiple Page Development in Java with Eclipse and GWT

I have been writing some basic code for an application I am designing. I have learned the basics and gotten some simple database connection working with RPC calls etc. What I need to do now and am completely lost (as I am traditionally a c# developer with windows forms).
In c# if I wanted a new form I would just create it, and then call the show method.
How does one create multiple pages in GWT, and switch between them?
Thanks in advance,
Chris
The simplest way would be to
Make a new java class (GwtHome.java, GwtHelp.java etc)
Extend these classes by using the Composite class
Make the equivalent of a Master Page and add it to the rootPanel as a class with the appropriate headers, menu, footer and Content Placeholder (Could be any of the AbsolutePanel, VerticalPanel, HorizontalPanel objects provided by the GWT Framework)
By clicking on the menu clear the Placeholder and add the appropriate object of GwtHome, GwtHelp etc.
After getting aquanted with the above procedure, you might want to break up the code in many files using a design pattern as suggested by Andrei.
Simply clear the root panel (RootPanel.get().clear()) and add the widget for your new "page", the same way you added your first one.
If you're using LayoutPanels, do RootLayoutPanel.get().clear() instead.
Look at Activities and Places design pattern: https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces
I highly recommend it for a multipage GWT app. It explains pretty well how you create different "views", that are driven by their "activities", and tied to specific "places" (pages) that users can navigate.
Typically you use a LayoutPanel as your "page" container that occupies the entire available browser window. You split this LayoutPanel into 2-3 layers (zones), like top menu, side menu, main area. Each area contains one widget, usually a ScrollPanel, FlowPanel, or HtmlPanel. Then you use different widgets or HTML inside each of these widgets to display whatever you need. You may also create your own composite widgets that you can reuse in different pages.

how to detect Html elements of webpages rendered in JeditorPane

I am designing a web application testing tool with integrated webbrowser in Java, to implement the browser i used the HTMLEditorKit of JeditorPane which provides bare minimum functionality which is ok for me.
Now I wanna detect all the html elements such as buttons, lists, dropdownList, textfields etc. and record the behaviour of these elements when user interacts with them.(e.g. User types in textboxes of webpage)
I tried using actionListeners on the JeditorPane to detect events of adding components with no positive result.All the eventsListeners for JeditorPane will not work on the html elements such as textbox(webpage form) displayed in it.
Is there any way i can detect and listen to action of the html elememts(especially web form) rendered in JeditorPane which is dynamically loaded when i supply url.
To render such elements (let's name them controls) EditorKit uses ComponentView and extensions. On paint() ComponentView creates a container - inner class Invalidator. The Invalidator actually contains control from Element attributes.
So after paint() is done you can get list of children of your JEditorPane. I think the list will contains the Invalidators only. And ask each Invalidator about inner component. Thus you'll have list of actual controls created in the JEditorPane.
Then you can add any listeners depending on the component type to register any activity.
On each document change event (insert/delete/update) you should recheck changhes in the list after the next paint() and update your data accordingly.

Categories

Resources