javafx scenebuilder 1.1 inserts namespaces which cause parse errors - javafx-2

The latest javafx scenebuilder 1.1 inserts namespaces when I save my fxml file
xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2"
When I open the file in the Netbeans 7.3.1 editor, I get errors like "Controller is not defined on root component". I delete the '1' to fix it.
and in the NetBeans IDE Retriever Pane:
Aug 29, 2013 10:37:32 AM : Retrieving Location:
http://javafx.com/javafx/2.2
Error: Unknown Host: javafx.com URL Resource
There is a controller. The problem is why it is creating
xmlns:fx="http://javafx.com/fxml/1"
instead of
xmlns:fx="http://javafx.com/fxml"?

SB developers knew about this bug. At this moment I resolve it by download Netbeans Developer version. Also I install jdk-8. Resoult: any bugs. But yet little tested id.

1.) When creating an application with SceneBuilder you most likely will not yet have a controller class in place which handles the events and everything else in your application. Saving the *.fxml file will give you something like the following:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="800.0"
xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
<children>
...more here...
</children>
</AnchorPane>
You need to create your application controller and add it the main node <AnchorPane ...> as the following shows (use full package path):
<AnchorPane id="AnchorPane" ... fx:controller="application.ListAndTableViewController">
2.) If you have a controller already, you can just specify it in SceneBuilder as shown in the attached picture.
By following one of the two approaches, Netbeans will not give you the error when opening your by the SceneBuilder created file.

Related

f:validateRegex always checked when deploy a jsf2.1 project into weblogic12c

I am going to deploy a jsf2.1(jsf2.1+spring3+primface-3.0.M3) project to weblogic 12c(jdk1.8).
Its a long story to make it work in weblogic12c,but there are still some problems,such as <f:validateRegex component, it always checked no matter whether there is empty or not,but it works fine in weblogic10.3.6(jdk1.7)
How can i fix it without change the pattern or other attributes?
My code:
<f:validateRegex pattern="^[0-9a-zA-Z;\s\r\*]+$" />
My weblogic.xml:
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
<container-descriptor>
<prefer-web-inf-classes>false</prefer-web-inf-classes>
<prefer-application-packages>
<package-name>javax.faces.*</package-name>
<package-name>com.sun.faces.*</package-name>
<package-name>com.bea.faces.*</package-name>
<package-name>net.sf.cglib.*</package-name>
<package-name>javax.annotation.*</package-name>
<package-name>org.primefaces.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>javax.faces.*</resource-name>
<resource-name>com.sun.faces.*</resource-name>
<resource-name>com.bea.faces.*</resource-name>
<resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</resource-name>
<resource-name>META-INF/services/com.sun.faces.spi.FacesConfigResourceProvider</resource-name>
<resource-name>META-INF/resources/javax.faces/jsf.js</resource-name>
<resource-name>META-INF/resources/javax.faces/jsf-uncompressed.js</resource-name>
</prefer-application-resources>
<!-- <prefer-web-inf-classes>true</prefer-web-inf-classes> -->
</container-descriptor>
</weblogic-web-app>
Thanks for your reading.
To avoid validation of empty field you can add this parameter to your web.xml (works in jsf 2.1)
<context-param>
<param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name>
<param-value>false</param-value>
</context-param>
In this post you can find some explanation and many others parameters.

JSF2: NullpointerException at custom composite component

I've been trying to create an own component to "replace" the Richfaces spacer, which is no longer available in Richfaces 4.
I have found this link for the actual implementation: https://community.jboss.org/wiki/SpacerImplementationForJSF2OrRichFaces4
I tried to register the new taglib:
richext.taglib.xml
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
version="2.0">
<namespace>http://java.sun.com/jsf/composite/richext</namespace>
<tag>
<tag-name>spacer</tag-name>
<source>../richext/spacer.xhtml</source>
</tag>
web.xml
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>WEB-INF/richext.taglib.xml</param-value>
</context-param>
changed the spacer.xhtml a little bit to:
<composite:implementation>
<h:panelGroup rendered="#{cc.attrs.height > 0}">
<br/>
</h:panelGroup>
<h:graphicImage value="../img/spacer.gif"
width="#{cc.attrs.width}px"
height="#{cc.attrs.height}px"/>
</composite:implementation>
I added
xmlns:richext="http://java.sun.com/jsf/composite/richext"
to the pages where I want to use the spacer.
My Files:
WebContent/WEB-INF/richext.taglib.xml
WebContent/richext/spacer.xhtml
WebContent/img/spacer.gif
Now, when accessing a page where I use the spacer (other pages work fine) I get a NullpointerException in the browser, not in the server log.
java.lang.NullPointerException
at org.apache.myfaces.view.facelets.tag.composite.CompositeComponentDefinitionTagHandler.apply(CompositeComponentDefinitionTagHandler.java:113)
at org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:57)
at org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:48)
at org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:394)
at org.apache.myfaces.view.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:448)
at org.apache.myfaces.view.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:390)
at org.apache.myfaces.view.facelets.tag.UserTagHandler.apply(UserTagHandler.java:138)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:51)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:59)
at org.richfaces.view.facelets.html.BehaviorsAddingComponentHandlerWrapper.applyNextHandler(BehaviorsAddingComponentHandlerWrapper.java:53)
at org.apache.myfaces.view.facelets.tag.jsf.ComponentTagHandlerDelegate.apply(ComponentTagHandlerDelegate.java:294)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:54)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:51)
at org.apache.myfaces.view.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:57)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:51)
at org.apache.myfaces.view.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:48)
at org.apache.myfaces.view.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:179)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.buildView(FaceletViewDeclarationLanguage.java:417)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:78)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1188)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:763)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:454)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:125)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:77)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:919)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1016)
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:895)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1659)
Where did I go wrong? Am I missing something?
My Server is a Websphere 8.0.0.2 if that's important.
Thanks in advance
You don't need that richext.taglib.xml file and that web.xml entry at all. Just put the composite component in /resources/richext folder, exactly as explained in the answer you found. Your concrete problem is caused because you attempted to register a composite component as a tag file (which are two entirely separate concepts). The incorrect taglib file might have caused MyFaces to choke like that.
See also:
Composite component info
When to use <ui:include>, tag files, composite components and/or custom components?

FXML Loader can't create FXMLCollections

I'm trying to create a ComboBox using fxml. and there is this error that says : Instances of javafx.collctions.FXCollections cannot be created by FXMLLoader. And here is the code:
<ComboBox fx:id="setBeginWidth" blendMode="DIFFERENCE" layoutX="325.0" layoutY="262.0"prefHeight="21.0" prefWidth="196.0" promptText="Set the Width of the Map">
<items>
<FXCollections fx:factory="observableArrayList">
<Integer fx:value="4" />
<Integer fx:value="5" />
<Integer fx:value="6" />
<Integer fx:value="7" />
<Integer fx:value="8" />
<Integer fx:value="9" />
<Integer fx:value="10" />
</FXCollections>
</items>
</ComboBox>
Thanks for your help.
I built a small demo application around your FXML snippet. The first thing that failed me is that the part
layoutY="262.0"prefHeight="21.0"
is missing a space.
When I fixed that, it worked for me after importing
<?import javafx.collections.*?>
<?import java.lang.*?>
The first is for FXCollections, the second for constructing Integer.
Did you add those imports?
You must declare the namespace for the shorthand fx. Add
xmlns:fx="http://javafx.com/fxml"
to the xml root node.
layoutY="262.0"prefHeight="21.0"
this line giving error so please give space between "262.0" and prefHeight.
It will be layoutY="262.0" prefHeight="21.0"
Hope it will help you

Is It Possible To Import Classes into FXML <fx:script> block (JavaFX-2)

I'm trying out JavaFX-2 and one of the features is said to be that we can create event handler functions using Javascript in our FXML file. One thing that bugged me is I can't access the System class right away. It needs to be fully referenced, like "java.lang.System". That becomes ugly when we need a simple output on the console, I mean come on, "System.out.println" is ugly enough to get something printed.
And, even though my FXML has all the <?import java.lang.*?> statements, apparently it doesn't affect inside of the <fx:script> tags.
Sample code: (Notice the <?language javascript?> directive)
<?xml version="1.0" encoding="UTF-8"?>
<?language javascript?>
<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.collections.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>
<AnchorPane fx:id="rootPane">
<fx:script>
function buttonAction(event){
java.lang.System.out.println("finally we get to print something.");
// System.out.println("This wouldn't work even if it wasn't a comment line, anyway");
}
</fx:script>
<children>
<Button id="close" mnemonicParsing="false" onAction="buttonAction(event)" text="">
<graphic>
<ImageView pickOnBounds="true">
<image>
<Image url="#../resources/close.png" preserveRatio="true" smooth="true" />
</image>
</ImageView>
</graphic>
</Button>
</children>
</AnchorPane>
So my question is: Is there any way to import classes into <fx:script>? I remember I was doing this in Actionscript3.0 really easy: import flash.events.MouseEvent ...
Use javascript build-in importPackage or importClass functions.
<fx:script>
importPackage(java.lang);
function buttonAction(event){
System.out.println("finally we get to print something.");
}
</fx:script>
For more details, see: http://docs.oracle.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html#jsimport
This is all a bit confusing but the link from Sergey gives good context to what's going on in the background (ie extending java into the scripting world).
Although Sergey's solution works, it mixes java class methods inside the inline script which is presumably meant to be javascript (as per the page language declaration). There's no browser, so no "console.log()", so maybe it would be best to avoid the potential java/js confusion and just use print():
<fx:script>
function reactToClick(event) {
print("I was clicked");
}
</fx:script>
The next question is where does the print() method originate from .... it's not java and it's not js. The answer I think lies in the Nashorn javascript engine used to underpin the java/js integration. Print() is a built-in function: Nashorn shell commands.

XPages - SSJS calling a bean

I am attempting to call some java code from an XPage and was attempting to do this via SSJS. Just trying to get even a basic hello world example working. Ideally the return from the java code could be stuffed into a variable.
Goal: (Xpage contents)
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:label value="#{javascript:helloWorld.anyoneThere}" id="label1"></xp:label>
</xp:view>
would print 'Yo!' when the page loads. Instead I get a Runtime Error that helloWorld is not found.
Created a package
package testBean;
public class helloWorld {
public String anyoneThere(){
return "Yo!";
}
}
Then I modified the faces-config file
<?xml version="1.0" encoding="UTF-8"?>
<faces-config>
<managed-bean>
<managed-bean-name>helloWorld</managed-bean-name>
<managed-bean-class>testBean</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>
</faces-config>
Not sure what I need to do to initialize / call the java function. Some examples I've seen are hooking into views or are on events but the intended code for what I'm doing would more likely be run in the beforePageLoad section.
Your managed-bean-class has you include the class name as well.
<managed-bean-class>testBean.helloWorld</managed-bean-class>
Also your label has to have parenthesis
<xp:label value="#{javascript:helloWorld.anyoneThere();}" id="label1"></xp:label>
I have written a small tutorial on the basics of creating and using a simple managed bean with XPages.
The tutorial also shows how to add getters and setters to your variables so that you can use EL to reference them. So in your example you will be able to do the following to reference the anyoneThere variable (assuming that you have set up a getter and setter for it):
<xp:label value="#{helloWorld.anyoneThere}" id="label1"></xp:label>

Resources