I was designated as a developer to upgrade our old wicket app from 6.x to 8.x. I am resolving multiple errors one by one, but (since I never worked with wicket) one I am unable to move on with.
In version 6.x it had DropDownChoice with overriden onSelectionChanged which no longer exists in version 8.x and I am unable to find any info about deprecation (going through 7.x versions...) so it seems they just removed it .. what are my alternatives here? The aforementioned code:
booleanType = new DropDownChoice<BooleanType>("booleanType", new PropertyModel<>(this, "selectedBooleanType"), booleanTypes) {
#Override
protected void onSelectionChanged(BooleanType newSelection) {
super.onSelectionChanged(newSelection);
selectedBooleanType = newSelection;
}
};
EDIT:
Similar question that I found only later
Wicket 6 to 8 upgrade: RadioGroup.onSelectionChanged() replacement
for those wondering how to update the value since it is not coming as an argument of the method anymore:
selectedType = (YourChoiceType) super.getFormComponent().getDefaultModelObject();
wantOnSelectionChangedNotifications moved to FormComponentUpdatingBehavior. From the changelog:
// Wicket 7.x
new CheckBox("id", model) {
protected boolean wantOnSelectionChangedNotifications() {
return true;
}
protected void onSelectionChanged(Boolean newSelection) {
// do something, page will be rerendered;
}
};
// Wicket 8.x
new CheckBox("id", model)
.add(new FormComponentUpdatingBehavior() {
protected void onUpdate() {
// do something, page will be rerendered;
}
protected void onError(RuntimeException ex) {
super.onError(ex);
}
});
(The example uses a CheckBox but it also applies to DropDownChoice).
For another example see the wiki.
Related
I use Wicket 1.5
When i change color it is really changed on the page only after refreshing using F5. How to refresh it in backend?
I use this lines for changing color:
dateDescription.add(AttributeModifier.replace("style", "color:red;"));
add(dateDescription);
UPDATE #1
Now i use AJAX but still have to refresh page for changing color. Could you tell me what i did wrong?
// in page class
public class FilterUpdateBehavior extends AjaxFormComponentUpdatingBehavior {
public FilterUpdateBehavior(String event) {
super(event);
}
#Override
protected void onUpdate(AjaxRequestTarget target) {
RefreshResult result = getResult(target);
if (result.getStatus() == RefreshResultStatus.DATE_NOT_SET) {
dateIntervalFilterPanel.setAlarmDateStatus(true);
} else {
dateIntervalFilterPanel.setAlarmDateStatus(false);
}
}
}
// in date panel class
dateDescription.add(new AttributeModifier("style", new AbstractReadOnlyModel<String>() {
private static final long serialVersionUID = 1L;
#Override
public String getObject() {
String cssClass = null;
if (isAlarmDateStatus()) {
cssClass = "color:red;";
} else {
cssClass = "color:black;";
}
return cssClass;
}
}));
add(dateDescription);
UPDATE #2
public RefreshResult getResults(AjaxRequestTarget target) {
// ... somewhere here additional logic of getting particulate RefreshResult
target.add(table);
target.add(paging);
target.add(loadingPanel);
return new RefreshResult(resultType);
}
UPDATE #3 FINAL (IT HELPED ME)
I miss this code line when i change isAlarmDateStatus, now it works fine. Thanks to Andrea!
target.add(dateDescription);
your code line looks right but you must use AJAX to reflect your changes without reloading the entire page. Unfortunately Wicket 1.5 is really outdated and there are few resources online to provide you an example of AJAX support. You might try to look into the old 1.5 AJAX examples code here:
https://github.com/apache/wicket/tree/build/wicket-1.5.17/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin
I have my JNLP application which work perfectly fine with Oracle JDK.
But when I tried running it with openJDK 1.8.0.252 and IcedTea WS (provided by default with openJDK).
I see My application can be launched with multiple instances although there is implementation of SingleInstanceListener .
I never got the logger "Start newActivation method" printed in console.
Also I wanted (tried) to Launch the application with parameter.
Can anyone help me with this
Code ::
// Code from Main class
private void startSingleInstance() {
log.info("Initializing single instance Web Start");
boolean didAddListener = false;
final SingleInstanceListener singleInstanceListener = new SingleInstanceListener() {
#Override
public void newActivation(String[] args) {
log.info("Start newActivation method");
log.info("newActivation(args:{}) in env {} Frame visible? {}",
new Object[] {args, System.getProperty("app.environment"), frame != null ? frame.isVisible() : false});
if (args.length > 1) {
// some logic
}
SwingHelper.frameToFront(frame);
}
};
try {
SingleInstanceService singleInstanceService =
(SingleInstanceService) ServiceManager.lookup("javax.jnlp.SingleInstanceService");
log.info("singleInstanceService {} ",singleInstanceService);
// add the listener to this application!
log.info("Add singleInstanceListener");
singleInstanceService.addSingleInstanceListener(singleInstanceListener);
didAddListener = true;
} catch (UnavailableServiceException e) {
log.info("Unable to register single WebStart instance (Not Web Start environment?).");
}
At the OpenWebStart Repo you can find an issue that current discuss how the SingleInstanceListener should work. Since the people that Maintain OpenWebStart are the same people that maintain IcedTeaWeb it would be good if you can add your input to that issue :)
I got the task to migrate to wicket 1.4 to wicket 1.5. Despite lack of information in migration guide I was somehow able to refactor most issues. Unfortunetly I'm stuck with "resource" - atm I'm getting this error
java.lang.IllegalArgumentException: Argument 'resource' may not be null.
What I understand by that is that something was change and wicket can no longer "get" to my resources. So I used to have (in wicket 1.4) that piece of code that was responsible for creating image and passing it (the method is in class that extends WebPage) :
private void addImageLogo() {
Resource res = new Resource() {
#Override
public IResourceStream getResourceStream() {
String logo = ConfigurationManager.getInstance().getPathValue(ConfigurationManager.LOGO_FILE_PATH);
return new FileResourceStream(new File(logo));
};
Image logo = new Image("logo", res);
add(logo);
}
Now Resource class no longer exists or I can't find it. While searching internet I was able to change it into this
private void addImageLogo() {
String logoTxt = ConfigurationManager.getInstance().getPathValue(ConfigurationManager.LOGO_FILE_PATH);
ResourceReference res = new ResourceReference(logoTxt) {
#Override
public IResource getResource() {
return null;
}
};
Image logo = new Image("logo", res);
add(logo);
}
This is responsible for obtaining path (and its working): ConfigurationManager.getInstance().getPathValue(ConfigurationManager.LOGO_FILE_PATH)
Unfortunetly I'm still getting this error that I mentioned above. The method getResource() generated automaticly and I believe this is an issue because I'm retuning null but I have no idea what (or how) should I return.
Since it worked with a IResourceStream in 1.4.x then you can just use org.apache.wicket.request.resource.ResourceStreamResource as a IResource for the Image.
Your first code snippet is not complete so I cannot give you exact replacement code.
I am trying to set up the SuperDevMode on a Vaadin project.
I have basically 3 problems related to this feature.
I have the following widget (created using the "New Vaadin Widget" wizard, below the code for the client-side widget, connector, state and server-side component):
// Widget:
public class CountedTextFieldWidget extends Composite {
private TextBox textBox = new TextBox();
private Label countLabel = new Label("0");
private HorizontalPanel panel = new HorizontalPanel();
public static final String CLASSNAME = "countedtextfield";
public CountedTextFieldWidget() {
initWidget(panel);
setStylePrimaryName(CLASSNAME);
textBox.setStylePrimaryName(CLASSNAME + "-field");
countLabel.setStylePrimaryName(CLASSNAME + "-label");
setStylePrimaryName(CLASSNAME);
panel.add(textBox);
panel.add(countLabel);
}
public String getText() {
return textBox.getText();
}
public void setText(String text) {
textBox.setText(text);
}
public void setCount(int count) {
countLabel.setText("" + count);
}
public int getCount() {
return Integer.parseInt(countLabel.getText());
}
// HandlerRegistration can be used to remove the key up handler (listener)
// added with this method
public HandlerRegistration addKeyUpHandler(KeyUpHandler handler) {
return textBox.addKeyUpHandler(handler);
}
}
/********************************************************/
// Connector:
#Connect(CountedTextField.class)
public class CountedTextFieldConnector extends AbstractComponentConnector {
public CountedTextFieldConnector() {
getWidget().addKeyUpHandler(new KeyUpHandler() {
#Override
public void onKeyUp(KeyUpEvent event) {
String text = getWidget().getText();
getWidget().setCount(text.length());
}
});
}
#Override
protected Widget createWidget() {
return GWT.create(CountedTextFieldWidget.class);
}
#Override
public CountedTextFieldWidget getWidget() {
return (CountedTextFieldWidget) super.getWidget();
}
#Override
public CountedTextFieldState getState() {
return (CountedTextFieldState) super.getState();
}
#Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
final String text = getState().text;
getWidget().setText(text);
getWidget().setCount(text.length());
}
}
/********************************************************/
// State
public class CountedTextFieldState extends com.vaadin.shared.ui.textfield.AbstractTextFieldState {
{
primaryStyleName = null;
}
}
/********************************************************/
// Server-side component:
public class CountedTextField extends com.vaadin.ui.TextField {
#Override
public String getValue() {
return getState().text;
}
public void setValue(String value) {
getState().text = value;
}
#Override
public CountedTextFieldState getState() {
return (CountedTextFieldState) super.getState();
}
}
This widget is rendered as following:
Now, I have followed the following guide on the Vaadin's wiki:
https://vaadin.com/wiki/-/wiki/Main/Using%20SuperDevMode
The CodeServer starts as expected:
The code server is ready.
Next, visit: http://localhost:9876/
But when I open the project and append ?superdevmode to the URL, get the Recompilation failed... message and there's are some errors in the browser's console:
So my first problem is related to this issue:
1) Why does recompilation fail sometimes? And what are those SEVERE: JSONP compile call failed and SEVERE: Timeout Excecution?
Then if I ... click to retry sometimes the superdevmode starts, but the custom widget is not rendered as in the previous screenshot I posted.
Instead, I get a standard Vaadin's v-textfield...
2) WTF... Why? Where is my custom component?
I noticed that I get the same issue also if I open localhost:9876, drag the Dev Mode On button to the bookmarks toolbar and then click on it while on localhost:8080/project. My custom widget is disappears and instead I get the Vaadin's v-textfield widget...
And about the Enable Source Map feature. On the wiki, they say:
To be able to debug Java code in Chrome, open the Chrome Inspector
(right click -> Inspect Element), click the settings icon in the lower
corner of the window and check "Scripts -> Enable source maps".
Refresh the page with the inspector open and you will see Java code
instead of JavaScript code in the scripts tab.
In my Chrome, I don't have a settings icon on the lower corner of the window, I clicked the gear icon on the right and went to General -> Sources and checked Enable JavaScript Source Map (There's no generic Enable source maps entry on my settings tab).
I can see the Java sources, but they are all sources for GWT and Vaadin's components:
So my third issue and related question:
3) How can I see my custom widget code also?
Thanks for the attention! Hope I was clear.
I also had a similar problem trying to use SuperDev Mode with Vaadin. I'm not quite sure why recompilation fails on occasion, but I suspect it envolves the same issue I had trying to send my Java source maps. The problem I had seemed to be a caching issue due to the fact that the code server creates a persistent cache directory in my /tmp folder. So I deleted every folder it created (they usually have "gwt" in the name somewhere) and relaunched the code server. I suggest also adding the -src <complete-path-to-project> argument in the code server configurations to specify the directory containing GWT source to be prepended to the classpath for compiling and possibly changing the log level to TRACE or DEBUG. Heres an example those arguments:
com.example.AppWidgetSet -src /home/workspace/widgetset/src/main/java
-logLevel TRACE
I should mention that the log levels are quite verbose, but can be quite useful. The log should also show the location of the cache folder.
MyFaces seems to be ignoring my call to getStateHelper.put() in this component:
public class BFTableComponent extends UINamingContainer {
...
private void setCurrentPageNumber(int currentPageNumber) {
getStateHelper().put(PropertyKeys.currentPageNumber, currentPageNumber);
}
public int getCurrentPageNumber() {
return (Integer) getStateHelper().eval(PropertyKeys.currentPageNumber, 0);
}
public void nextPage() {
setCurrentPageNumber(getCurrentPageNumber() + 1);
updateCurrentPage();
}
public void previousPage() {
setCurrentPageNumber(getCurrentPageNumber() - 1);
updateCurrentPage();
}
...
}
As you can see, when the frontend component calls nextPage, the goal is to advance the page number by one. However, when running this in MyFaces, the eval() call will work for the immediate request lifecycle, but the next request, it will return 0. If I put null instead of 0, I gett an NPE.
The pageNumber state needs to carry for the lifetime of the component, not just the current request. What am I doing wrong? This code runs fine under Mojarra, but not in MyFaces.
Turns out it actually was a bug somewhere in MyFaces. I was running this in Apache TomEE beta2. It included MyFaces 2.1.2. I replaced the jars with 2.1.7 and the problem fixed itself.
Thanks for looking!