I'm using Richfaces 3, Facelets (a pre-JSF 2 version), and Tomcat. I am working on adding a Richfaces Tree to my page, but get this error:
org.richfaces.model.TreeNodeImpl cannot be cast to javax.swing.tree.TreeNode
Here is the code I'm using to build the list of nodes:
int i = 0;
TreeNodeImpl<String> rootNode = new TreeNodeImpl<String>();
for( Recommendation recommendation : m_recommendationsBean.getRecommendations() )
{
final TreeNodeImpl<String> childNode = new TreeNodeImpl<String>();
childNode.setData( recommendation.getEventDescription() );
rootNode.addChild( i, childNode );
i++;
}
m_treeNodes.add( rootNode );
And then:
#NotNull
public List<TreeNodeImpl<String>> getTreeNodes ()
{
return m_treeNodes;
}
And my page just has this:
<rich:tree value="#{DmsRecommendationsPage.treeNodes}" var="recommendation">
<rich:treeNode>
#{recommendation}
</rich:treeNode>
</rich:tree>
Any ideas? Thanks!
Check your imports. RichFaces' own org.richfaces.model.TreeNode interface should be used in the property declaration. You've likely picked the first option of the IDE autosuggestion to import the Swing one instead of the RichFaces one while declaring the TreeNode.
Replace
import javax.swing.tree.TreeNode;
by
import org.richfaces.model.TreeNode;
For other readers:
The javax.swing.tree.TreeNode is used in the Richfaces showcase here:
http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=tree&skin=blueSky
It seems both are possible. The documentation states:
The data model must be either an org.richfaces.model.TreeNode
interface, an org.richfaces.model.TreeDataModel interface, or a
javax.swing.tree.TreeNode interface.
package org.richfaces.demo.tree.model;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import javax.swing.tree.TreeNode;
import com.google.common.collect.Iterators;
public class Country extends NamedNode implements TreeNode {
Related
I'm getting an unresolved compilation error. Getting these errors:
The method addActionListener(ActionListener) in the type
AbstractButton is not applicable for the arguments (Gui.HandlerClass)
The method addActionListener(ActionListener) in the type
AbstractButton is not applicable for the arguments (Gui.HandlerClass)
ActionListener cannot be resolved to a type ActionEvent cannot be
resolved to a type
import java.awt.*;
import javax.swing.*;
public class Gui extends JFrame{
private JButton reg;
private JButton custom;
public Gui(){
super("The title");
setLayout(new FlowLayout());
reg = new JButton("Regular Button");
add(reg);
Icon b = new ImageIcon(getClass().getResource("foto 1.png"));
Icon c = new ImageIcon(getClass().getResource("foto 2.png"));
custom = new JButton("Custom", b);
custom.setRolloverIcon(c);
add(custom);
HandlerClass handler = new HandlerClass();
reg.addActionListener(handler);
custom.addActionListener(handler);
}
private class HandlerClass implements ActionListener{
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand()));
}
}
}
Avoid using * in imports. Your problem here is that ActionListener and ActionEvent classes are not imported. Therefore, you must import them:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Also, what IDE are you using? Most IDEs would spot the problem and recommend you something in order to be fixed.
I am trying to learn JSF using netbeans with glass fish.
Everything is up to date. From the sdk to netbeans. I am following some examples from a book published in 2009.
In out of the examples, the writer has used the #Current annotations and imported javax.inject.Current.
When i try out the code using netbeans, netbeans throws an error. I have added the java EE 7 library but nothing doing.
In your answer(s) 1- Explain why netbeans cannot find the class and 2- Give step by step procedures for adding the class to my project.
Here's the code I'm using.
` package hello;
import java.util.*;
import javax.faces.bean.RequestScoped;
import javax.inject.Named;
import javax.inject.Inject.Current;
#Named
#RequestScoped
public class QuoteRequest {
private String symbol;
#Current
private StockService service;
private Date quoteDate = new Date();
public QuoteRequest() {
}
public String getSymbol() {
return symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public double getStockValue(){
return service.getStockValue(this);
}
public Date getQuoteDate() {
return quoteDate;
}
public void setQuoteDate(Date qouteDate) {
this.quoteDate = qouteDate;
}
}
`
You need to do two things
Use #Inject annotation from javax.inject package instead of #Current annotation as the book says.
Make sure you have an empty beans.xml file in your WEB-INF folder. This file is important to treat your beans as CDI beans.
I have a problem in below code, this frmChinese.append(txtField); is not working for me.
What is the correct way to bind this text field with my form? The header files and libraries that I have used have also been mentioned.
package com.lbs;
import com.lbs.MidletSplashScreen;
import com.sun.lwuit.*;
import com.sun.lwuit.Button;
import com.sun.lwuit.Command;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.Border;
import java.io.IOException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.TextField;
public class Chinese extends Form implements ActionListener {
Form frmChinese = null;
Command cmdExit = null;
TextField txtField = null;
Chinese() {
frmChinese = this;
frmChinese.setTitle("Chinese");
frmChinese.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
this.getStyle().setBgColor(0xFF5240);
ShowUi();
cmdExit = new Command("Exit");
Command cmdBack = new Command("Back"); // new command with name Back
frmChinese.addCommand(cmdExit);// add command in Form
frmChinese.addCommand(cmdBack);// add command in Form
frmChinese.setBackCommand(cmdBack); // setting back command
frmChinese.addCommandListener(this); // register action listener in form
}
private void ShowUi() {
txtField = new TextField("","Search", 20, TextField.ANY);
frmChinese.append(txtField);
}
What you need to use is te addComponent method from the Form Class. In lwuit the basic interface elements are Components. Adding this Components to your Form's Layout, you can built some cool designs.
Take a look here:
LWUIT Layouts
By default the generated XText artifacts generate code from my DSL to the default outlet (which defaults to src-gen folder). I know that you can explicitly pass the outlet configuration name in fsa.generateFile("myfile.txt", "MY_OUTLET_NAME", "Some file content").
I it because I want to generate code with my XText DSL and want to use the generation gap pattern and generate code in a folder called "src-once".
I'am using XText 2.2.1.
My questions:
1) Where and how do I define my outlets like "MY_OUTLET_NAME"?
2) Is there a way to prevent overwriting existing files in a specific outlet?
The hint form Christian Dietrich pointed me in the right direction. Below is the code that I ended up with.
I have created a new class MyOutputConfigurationProvider that implements IOutputConfigurationProvider. The getOutputConfigurations method returns two output configurations, the default src-gen and a custom src-gen-once with the correct settings for generating sources only once.
package com.my.dsl;
import static com.google.common.collect.Sets.newHashSet;
import java.util.Set;
import org.eclipse.xtext.generator.IFileSystemAccess;
import org.eclipse.xtext.generator.IOutputConfigurationProvider;
import org.eclipse.xtext.generator.OutputConfiguration;
public class MyOutputConfigurationProvider implements
IOutputConfigurationProvider {
public final static String DEFAULT_OUTPUT_ONCE = "DEFAULT_OUTPUT_ONCE";
/**
* #return a set of {#link OutputConfiguration} available for the generator
*/
public Set<OutputConfiguration> getOutputConfigurations() {
OutputConfiguration defaultOutput = new OutputConfiguration(IFileSystemAccess.DEFAULT_OUTPUT);
defaultOutput.setDescription("Output Folder");
defaultOutput.setOutputDirectory("./src-gen");
defaultOutput.setOverrideExistingResources(true);
defaultOutput.setCreateOutputDirectory(true);
defaultOutput.setCleanUpDerivedResources(true);
defaultOutput.setSetDerivedProperty(true);
OutputConfiguration onceOutput = new OutputConfiguration(DEFAULT_OUTPUT_ONCE);
onceOutput.setDescription("Output Folder (once)");
onceOutput.setOutputDirectory("./src-gen-once");
onceOutput.setOverrideExistingResources(false);
onceOutput.setCreateOutputDirectory(true);
onceOutput.setCleanUpDerivedResources(false);
onceOutput.setSetDerivedProperty(true);
return newHashSet(defaultOutput, onceOutput);
}
}
To use the MyOutputConfigurationProvider implementation add a configure method to your module class:
/**
* Use this class to register components to be used within the IDE.
*/
public class MyDslUiModule extends com.my.dsl.ui.AbstractMyDslUiModule {
public MyDslUiModule(AbstractUIPlugin plugin) {
super(plugin);
}
#Override
public void configure(Binder binder) {
super.configure(binder);
binder.bind(IOutputConfigurationProvider.class).to(MyOutputConfigurationProvider.class).in(Singleton.class);
}
}
implement a custom IOutputConfigurationProvider should do the trick
Im trying use a Java annotation in a Groovy class but have trouble to set a static field of a java class as a parameter:
The Annotation: Id.java
package x.y.annotations;
import java.lang.annotation.ElementType;
#Retention(RetentionPolicy.RUNTIME)
#Target(ElementType.FIELD)
public #interface Id {
public Class<Adapter> adapter();
public Class<Object> targetType();
public String targetAttribute();
public String onDelete();
}
The java class with the static fields: XPerson.java
package x.y.static.domain;
public class XPerson {
public static String ID;
}
And the groovy class, where the problem occurs: Person.groovy
package x.y.domain
import x.y.annotations.Id
import x.y.static.domain.XPerson
class Person {
#Id(adapter = Adapter, targetType = XPerson, targetAttribute = XPerson.ID, onDelete = "delete")
long id
}
Eclipse marks the "targetAttribute = XPerson.ID" part with:
Groovy:expected 'x.y.domain.XPerson.ID' to be an inline constant of type java.lang.String not a property expression in #x.y.annotations.Id
I also tried things like "XPerson.#ID" or defining a getter for the ID field, but nothing helped.
Any hints would be great.
Regards,
michael
I have found a related issue in the Groovy JIRA. It is a bug. Should work. See https://issues.apache.org/jira/browse/GROOVY-3278
Annotation values may only be compile-time constant expressions. Making the field final is an option. (With the caveat that the field can't be initialized in a static initializer/etc. as the snippet implies.)