Bug on #XmlElementWrapper inside <xml-elements> MoXy? - eclipselink

I found a tricky bug:
If I define the metadata-xml-binding as below
<?xml version="1.0"?>
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="package" xml-mapping-metadata-complete="true">
<xml-schema element-form-default="QUALIFIED" />
<java-types>
<java-type name="SearchResult">
<xml-root-element/>
<java-attributes>
<xml-element java-attribute="count"/>
<xml-element java-attribute="requestParameters"/>
<xml-element java-attribute="pageSize"/>
<xml-element java-attribute="sortDirection"/>
<xml-elements java-attribute="results">
<xml-element name="GaDictionaryElement" type="it.ga.model.GaDictionary">
<xml-element-wrapper name="GaDictionaryElementWrapper" />
</xml-element>
<xml-element name="OrganizationUnitElement" type="it.ga.model.OrganizationUnit">
<xml-element-wrapper name="OrganizationUnitElementWrapper" />
</xml-element>
<xml-element name="PersonElement" type="it.ga.model.Person">
<xml-element-wrapper name="PersonElementWrapper" />
</xml-element>
<xml-element name="Empty" type="java.lang.String">
<xml-element-wrapper name="EmptyWrapper" nillable="true"/>
</xml-element>
</xml-elements>
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
I have seen that the <xml-element-wrapper> tag doesn't work because it's into the <xml-element> tag that is surrounded from the <xml-elements> tag. So I was looking to find a way to solve this problem in a clean way. Because I need an empty node when the List<?> results of my class is empty.
A really bad workaround is creating a lot of different binding file as many type I have for the List<?> results but I don't like that!
Furthermore did someone try to create a binding file that could be useful for classes that implements a particular interface? E.g. In a way that I can see only the property of the object defined on the binding file and specifying as type the name of the interface? I have seen this: [blog]: http://blog.bdoughan.com/2010/07/moxy-jaxb-map-interfaces-to-xml.html#comment-form

You aren't permitted to have an <xml-element-wrapper> per <xml-element> inside an <xml-elements> in terms of what MOXy will process. You could have a single <xml-element-wrapper inside of <xml-elements>.
oxm.xml
<?xml version="1.0"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="forum16943280"
xml-mapping-metadata-complete="true">
<java-types>
<java-type name="SearchResult">
<xml-root-element/>
<java-attributes>
<xml-elements java-attribute="results">
<xml-element name="GaDictionaryElement" type="forum16943280.GaDictionary"/>
<xml-element name="OrganizationUnitElement" type="forum16943280.OrganizationUnit"/>
<xml-element-wrapper name="results"/>
</xml-elements>
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
SearchResult
package forum16943280;
import java.util.List;
public class SearchResult {
private List<Object> results;
public List<Object> getResults() {
return results;
}
public void setResults(List<Object> results) {
this.results = results;
}
}
GaDictionary
package forum16943280;
public class GaDictionary {
}
OrganizationUnit
package forum16943280;
public class OrganizationUnit {
}
Demo
package forum16943280;
import java.io.File;
import java.util.*;
import javax.xml.bind.*;
import org.eclipse.persistence.jaxb.JAXBContextProperties;
public class Demo {
public static void main(String[] args) throws Exception {
Map<String, Object> properties = new HashMap<String , Object>();
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, "forum16943280/oxm.xml");
JAXBContext jc = JAXBContext.newInstance(new Class[] {SearchResult.class}, properties);
Unmarshaller unmarshaller = jc.createUnmarshaller();
File xml = new File("src/forum16943280/input.xml");
SearchResult result = (SearchResult) unmarshaller.unmarshal(xml);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(result, System.out);
}
}
input.xml/Output
<?xml version="1.0" encoding="UTF-8"?>
<searchResult>
<results>
<OrganizationUnitElement/>
<OrganizationUnitElement/>
</results>
</searchResult>
input.xml/Output
<?xml version="1.0" encoding="UTF-8"?>
<searchResult>
<results>
<GaDictionaryElement/>
<GaDictionaryElement/>
</results>
</searchResult>

If you want separate element wrappers you could split the results property up per type.
SearchResult
package forum16943280;
import java.util.List;
public class SearchResult {
private List<GaDictionary> gaDictionaryResults;
private List<OrganizationUnit> organizationUnitResults;
public List<GaDictionary> getGaDictionaryResults() {
return gaDictionaryResults;
}
public void setGaDictionaryResults(List<GaDictionary> results) {
this.gaDictionaryResults = results;
}
public List<OrganizationUnit> getOrganizationUnitResults() {
return organizationUnitResults;
}
public void setOrganizationUnitResults(
List<OrganizationUnit> organizationUnitResults) {
this.organizationUnitResults = organizationUnitResults;
}
}
oxm.xml
<?xml version="1.0"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="forum16943280"
xml-mapping-metadata-complete="true">
<java-types>
<java-type name="SearchResult">
<xml-root-element/>
<java-attributes>
<xml-element
java-attribute="gaDictionaryResults"
name="GaDictionaryElement">
<xml-element-wrapper name="GaDictionaryElementWrapper"/>
</xml-element>
<xml-element
java-attribute="organizationUnitResults"
name="OrganizationUnitElement">
<xml-element-wrapper name="OrganizationUnitElementWrapper"/>
</xml-element>
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
Demo
package forum16943280;
import java.io.File;
import java.util.*;
import javax.xml.bind.*;
import org.eclipse.persistence.jaxb.JAXBContextProperties;
public class Demo {
public static void main(String[] args) throws Exception {
Map<String, Object> properties = new HashMap<String , Object>();
properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, "forum16943280/oxm.xml");
JAXBContext jc = JAXBContext.newInstance(new Class[] {SearchResult.class}, properties);
Unmarshaller unmarshaller = jc.createUnmarshaller();
File xml = new File("src/forum16943280/input.xml");
SearchResult result = (SearchResult) unmarshaller.unmarshal(xml);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(result, System.out);
}
}
input.xml/Output
<?xml version="1.0" encoding="UTF-8"?>
<searchResult>
<GaDictionaryElementWrapper>
<GaDictionaryElement/>
<GaDictionaryElement/>
</GaDictionaryElementWrapper>
</searchResult>
input.xml/Output
<?xml version="1.0" encoding="UTF-8"?>
<searchResult>
<OrganizationUnitElementWrapper>
<OrganizationUnitElement/>
<OrganizationUnitElement/>
</OrganizationUnitElementWrapper>
</searchResult>

<?xml version="1.0"?>
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="it.core.widget.dto" xml-mapping-metadata-complete="true">
<xml-schema element-form-default="QUALIFIED" />
<java-types>
<java-type name="JaxbSearchResult" xml-accessor-type="NONE">
<xml-root-element />
<xml-type prop-order="count pageSize requestParameters sortDirection results" />
<java-attributes>
<xml-element java-attribute="count" />
<xml-element java-attribute="requestParameters" />
<xml-element java-attribute="pageSize" />
<xml-element java-attribute="sortDirection" />
<xml-elements java-attribute="results">
<xml-element name="gaDictionaryElement" type="it.ga.model.GaDictionary" />
<xml-element name="organizationUnitElement" type="it.ga.model.OrganizationUnit" />
<xml-element name="personElement" type="it.ga.model.Person" />
<xml-element-wrapper />
</xml-elements>
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
This is the xml and works if I remove <xml-element-wrapper />
Furthermore without that tag it produces the above output
<?xml version="1.0" encoding="UTF-8"?>
<jaxbSearchResult>
<count>3</count>
<pageSize>30</pageSize>
<style>1</style>
<discriminator>equipment</discriminator>
<posting>1</posting>
<CLEAR>1</CLEAR>
<sortDirection> ASC </sortDirection>
<gaDictionaryElement>
<id>24964</id>
<startDate>2013-03-12T00:00:00</startDate>
<gaDictionaryMap />
<booleanMap />
<integerMap />
<numberMap />
<clobMap />
<parentGaDictionaryLinkSet />
<childGaDictionaryLinkSet />
<displayValue>Equipment 2</displayValue>
</gaDictionaryElement>
<gaDictionaryElement>
<id>24962</id>
<startDate>2013-03-12T00:00:00</startDate>
<gaDictionaryMap />
<booleanMap />
<integerMap />
<numberMap />
<clobMap />
<parentGaDictionaryLinkSet />
<childGaDictionaryLinkSet />
<displayValue>Equipment 1</displayValue>
</gaDictionaryElement>
<gaDictionaryElement>
<id>25185</id>
<startDate>2013-04-22T00:00:00</startDate>
<gaDictionaryMap />
<booleanMap />
<integerMap />
<numberMap />
<clobMap />
<parentGaDictionaryLinkSet />
<childGaDictionaryLinkSet />
<displayValue>Attrezzatura test</displayValue>
</gaDictionaryElement>
</jaxbSearchResult>
I need to wrap gaDictionaryElement accordingly the type that has been marshalled.
Any help is appreciated.
Furthermore did someone try to create a binding file that could be useful for classes that implements a particular interface? E.g. In a way that I can see only the property of the object defined on the binding file and specifying as type the name of the interface? I have seen this: [blog]: http://blog.bdoughan.com/2010/07/moxy-jaxb-map-interfaces-to-xml.html#comment-form

Related

ui:repeat: Regardless of validation error inner component keeps in state "valid"

I would like to mark a single component within ui:repeat as not valid. My attempt:
Bean:
#Named
#RequestScoped
public class TestBean {
private List<String> strLst;
#PostConstruct
public void init() {
strLst = Arrays.asList("a", "b", "c");
}
public String send() {
return null;
}
public List<String> getStrLst() {
return strLst;
}
}
Validator:
#FacesValidator(value = "TestValidator", managed = true)
public class TestValidator implements Validator<String> {
#Override
public void validate(FacesContext arg0, UIComponent comp, String foo) throws ValidatorException {
throw new ValidatorException(new FacesMessage("Error"));
}
}
Facelet:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
</h:head>
<h:body>
<h:form>
<h:messages />
<!-- After validation error component keeps in state 'valid' - wrong! -->
<ui:repeat var="str" value="#{testBean.strLst}">
<h:inputText value="#{str}" validator="TestValidator"
styleClass="#{component.valid ? 'foo' : 'error'}" />
</ui:repeat>
<!-- After validation error the component switches in state 'not valid' - correct! -->
<h:dataTable var="str" value="#{testBean.strLst}">
<h:column>
<h:inputText value="#{str}" validator="TestValidator"
styleClass="#{component.valid ? 'foo' : 'error'}" />
</h:column>
</h:dataTable>
<h:commandButton action="#{testBean.send}" value="Send" />
</h:form>
</h:body>
</html>
My problem: The component in ui:repeat keeps in state valid, so the styleClass error is not set. With h:dataTable no such problems. But I need a horizontal list, so h:dataTable is not an option here.
Also not working with Omnifaces 1.14.1 as described in https://stackoverflow.com/a/9195360/802058:
<ui:repeat var="str" value="#{testBean.strLst}">
<h:inputText value="#{str}" styleClass="#{component.valid ? 'foo' : 'error'}">
<o:validator validatorId="TestValidator" />
</h:inputText>
</ui:repeat>
Is this a bug or a feature?
Mojarra 2.3.9.SP01

GeofenceTransitionsIntentService' has no default constructor

Im working with geofencing.
I wrote the serivice class GeofenceTransitionsIntentService, and its showing red mark and saying has no Default constructor. please help me.
Its my manifest file :
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<!--optional (needed if default theme has no action bar) -->
<activity android:name=".loginpage"></activity>
<activity android:name=".Userlogin" />
<activity android:name=".Register" />
<activity android:name=".MainActivity">
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyB9DNBzfrYiTcmUThheWGNdAKY3lRU3pi8" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".GeofenceTransitionsIntentService"/> // here's the error. it turned up red.
</application>
here is my java class. it has a constructor but not a default one, if i put a constructor manually, it is showing error.
package com.example.foodtag;
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.location.Geofence;
import com.google.android.gms.location.GeofencingEvent;
import java.util.ArrayList;
import java.util.List;
public class GeofenceTransitionsIntentService extends IntentService {
GeofencingEvent geofencingEvent;
/**
* Creates an IntentService. Invoked by your subclass's constructor.
*
* #param name Used to name the worker thread, important only for debugging.
*/
public GeofenceTransitionsIntentService(String name) { //here is the constructor but it is not default constructor.
super(name);
}
GeofenceTransitionsIntentService(){ // and if i create constructor without parameters, it is showing an error "There is no default constructor available in 'android.app.IntentService'"
}
#Override
protected void onHandleIntent( Intent intent) {
geofencingEvent = GeofencingEvent.fromIntent(intent);
if(geofencingEvent.hasError()){
Toast.makeText(this, "Event has error", Toast.LENGTH_SHORT).show();
return;
}
int geoFenceTransition = geofencingEvent.getGeofenceTransition();
if (geoFenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER){
List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences();
// String geofenceTransitionDetails = getGeofenceTransitionDetails(this, geoFenceTransition,triggeringGeofences);
// sendNotofication();
}else {
Toast.makeText(this, "geofence transition invalid", Toast.LENGTH_SHORT).show(); }
}
private String getGeofenceTransitionDetails(
Context context,
int geofenceTransition,
List<Geofence> triggeringGeofences){
// String geofenceTransitionString = getTransitionString(geofenceTransition);//getTransitionString(geoFenceTransition)
ArrayList triggeringgeofencesIdsList = new ArrayList();
for (Geofence geofence : triggeringGeofences){
triggeringgeofencesIdsList.add(geofence.getRequestId());
}
String triggeringgeofencesIdsString = TextUtils.join(",",triggeringgeofencesIdsList);
return triggeringgeofencesIdsString;
}
}
Create a default constructor (without parameters) and put super with class name.
public GeofenceTransitionsIntentService(){
super("GeofenceTransitionsIntentService"); //add this to avoid the error.
}

<html:select> with Yes/No options inside <logic:iterate> passing null to form in struts

adminpage.jsp
I am iterating the users list from map and showing it in UI. Trying to send Yes/No values selected by user for agRestricted and processing it in the approve action.
<logic:iterate name="usersDetails" id="user" indexId="index">
<td><bean:write name="user" property="agName" /></td>
<td>
<html:select property="agRestricted" name="user">
<html:option value="Yes">Yes </html:option>
<html:option value="No">No</html:option>
</html:select>
</td>
<td>
<html:button property="Approve" value="" title="Approve" onclick="adminApprove()"></html:button>
</td>
</logic:iterate>
ApproveAction.java
In the approve action I am trying to read agRestricted value sent in form on submission. but Iam getting null here. Am I doing anything wrong.
public ActionForward approve(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
RegistrationForm registrationForm = (RegistrationForm) form;
if (loggingService.isInfoEnabled()) {
loggingService.logInfo(this, "is AG Restricted", agRestricted);
} // if{}//printing null
}
RegistrationForm.java
POJO Class for setting the form variables.
public class RegistrationForm extends org.apache.struts.action.ActionForm {
private String agRestricted;
private String agName;
public String getAgRestricted() {
return agRestricted;
}
public void setAgRestricted(String agRestricted) {
if (loggingService.isInfoEnabled()) {
loggingService.logInfo(this, "is AG Restricted", agRestricted);
} // if{}//printing null
this.agRestricted = agRestricted;
}
public String getAgName() {
return agName;
}
public void setAName(String agName) {
this.agName = agName;
}
}
adminpage.js
function adminApprove() {
var newUrl2 = './adminpage.do';
document.forms[0].action = newUrl2;
document.forms[0].submit();
}
struts-config.xml
<action input="/adminApprove" name="RegistrationForm"
path="/adminpage" scope="request"
type="com.cts.assetserv.core.web.action.ApproveAction" parameter="method">
<forward name="Success" path="/adminpage.do" />
<forward name="Error" path="/adminpage.do" />
</action>

javafx8 resize grows never shrinks

I have the following sample code fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.*?>
<?import javafx.scene.canvas.*?>
<?import org.cornova.javafx.*?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<SplitPane dividerPositions="0.5" maxHeight="Infinity" maxWidth="Infinity" minHeight="0" minWidth="0" orientation="VERTICAL" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.cornova.javafx.PanController">
<items>
<HBox prefHeight="246.0" prefWidth="603.0">
<children>
<VBox HBox.hgrow="ALWAYS">
<children>
<StackPane fx:id="stackPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="165.0" prefWidth="570.0">
<children>
<ResizableCanvas fx:id="spectrum" height="195.0" width="573.0" StackPane.alignment="TOP_LEFT" />
</children>
</StackPane>
<ResizableCanvas fx:id="freqScale" height="10.0" width="570.0" VBox.vgrow="NEVER" />
</children>
</VBox>
<ResizableCanvas fx:id="dbmScale" height="195.0" width="30.0" HBox.hgrow="NEVER" />
</children>
</HBox>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" />
</items>
</SplitPane>
I couple that with the following controller
/*
* Here comes the text of your license
* Each line should be prefixed with *
*/
package org.cornova.javafx;
/**
* Sample Skeleton for 'PanView.fxml' Controller Class
*/
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.scene.layout.StackPane;
import org.cornova.javafx.ResizableCanvas;
public class PanController {
#FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;
#FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;
#FXML // fx:id="stackPane"
private StackPane stackPane; // Value injected by FXMLLoader
#FXML // fx:id="spectrum"
private ResizableCanvas spectrum; // Value injected by FXMLLoader
#FXML // fx:id="freqScale"
private ResizableCanvas freqScale; // Value injected by FXMLLoader
#FXML // fx:id="dbmScale"
private ResizableCanvas dbmScale; // Value injected by FXMLLoader
#FXML // This method is called by the FXMLLoader when initialization is complete
void initialize() {
assert stackPane != null : "fx:id=\"stackPane\" was not injected: check your FXML file 'PanView.fxml'.";
assert spectrum != null : "fx:id=\"spectrum\" was not injected: check your FXML file 'PanView.fxml'.";
assert freqScale != null : "fx:id=\"freqScale\" was not injected: check your FXML file 'PanView.fxml'.";
assert dbmScale != null : "fx:id=\"dbmScale\" was not injected: check your FXML file 'PanView.fxml'.";
spectrum.widthProperty().bind(stackPane.widthProperty());
spectrum.heightProperty().bind(stackPane.heightProperty());
freqScale.widthProperty().bind(stackPane.widthProperty());
dbmScale.heightProperty().bind(stackPane.heightProperty());
spectrum.widthProperty().addListener((observable, oldValue, newValue) -> {
System.out.println("spectrum width changed from " + oldValue + " to " + newValue);
});
spectrum.heightProperty().addListener((observable, oldValue, newValue) -> {
System.out.println("spectrum height changed from " + oldValue + " to " + newValue);
});
freqScale.widthProperty().addListener((observable, oldValue, newValue) -> {
System.out.println("Freq scale width changed from " + oldValue + " to " + newValue);
});
dbmScale.heightProperty().addListener((observable, oldValue, newValue) -> {
System.out.println("dbm scale height changed from " + oldValue + " to " + newValue);
});
stackPane.widthProperty().addListener((observable, oldValue, newValue) -> {
System.out.println("stackpane width changed from " + oldValue + " to " + newValue);
});
stackPane.heightProperty().addListener((observable, oldValue, newValue) -> {
System.out.println("stackpane height changed from " + oldValue + " to " + newValue);
});
}
}
Given these two, as I recall, my sample app
package org.cornova.portablesdr;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
*
* #author walt
*/
public class PanadapterView extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
try {
URL url = getClass().getResource("/PanView.fxml");
SplitPane root = (SplitPane)FXMLLoader.load(url);
Scene scene = new Scene(root, 600,400);
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
Logger.getLogger(PanadapterView.class.getName()).log(Level.SEVERE, null, e);
}
}
public static void main(String[] args) {
launch();
}
}
worked pretty much as I expected except the enlargement of the window only went so far and I could not shrink it, at all. I added a change listener to the vbox and hbox and they both perform properly with respect to growth and shrinkage.
The two scales I want fixed on one axis, the HBox contains a VBox and a resizableCanvas as described in FXControl. It has a fixed width and its height is paired to the height of the stackpane, a child VBox and parent of another ResizableCanvas.
In the current fxml file I believe the stackpane appear to be fine in width, I can grow and shrink it just fine but the height never exceeds 200, which I was forced to use for prefHeight. It can, however, override prefWidth just fine.
At this point I kind of find myself just guessing at what to change next. I really have been trying to research this issue..so far with no luck, clearly.
Here is the final fxml file.
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<SplitPane dividerPositions="0.5" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0" minWidth="0" orientation="VERTICAL" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.cornova.javafx.PanController">
<items>
<HBox fx:id="hbox" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0">
<children>
<VBox fx:id="vbox" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="170.0" prefWidth="570.0" HBox.hgrow="ALWAYS">
<children>
<StackPane fx:id="stackPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="570.0">
<children>
<ResizableCanvas fx:id="spectrum" />
</children>
</StackPane>
<ResizableCanvas fx:id="freqScale" height="30.0" width="570.0" VBox.vgrow="NEVER" />
</children>
</VBox>
<ResizableCanvas fx:id="dbmScale" height="200.0" width="30.0" HBox.hgrow="NEVER" />
</children>
</HBox>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" />
</items>
</SplitPane>
I hope this all makes sense. Clearly there is something I am missing.
Thanks!
The answer is the Stackpane had (in SceneBuilder) a Vgrow setting of inherit, which I can't find explained anywhere and it doesn't appear to be a value in the Priority enum.
If someone would illuminate the purpose of inherit I, and I am sure others, would appreciate it.

Dynamic list constraint not updating in alfresco on a datalist

I tried to create a dynamic list constraint. The data in the drop down is not getting refreshed when an item is added to the database.
ListOfValuesQueryConstraint.java
package org.alfresco.ryden;
import java.util.ArrayList;
import java.util.List;
import java.io.Serializable;
import java.sql.*;
import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.alfresco.web.bean.generator.BaseComponentGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.faces.model.SelectItem;
public class ListOfValuesQueryConstraint extends ListOfValuesConstraint implements Serializable {
private static Log logger = LogFactory.getLog(BaseComponentGenerator.class);
private static final long serialVersionUID=1;
private List allowedLabels;
public void setAllowedValues(List allowedValues) {}
public void setCaseSensitive(boolean caseSensitive) {}
public void initialize() {
super.setCaseSensitive(false);
this.loadDB();
}
public List getAllowedValues() {
this.loadDB();
return super.getAllowedValues(); // In earlier post there is no return statement..
//return this.getAllowedValues();
}
public List getAllowedLabels() {
return this.allowedLabels;
}
public void setAllowedLabels(List allowedLabels) {
this.allowedLabels=allowedLabels;
}
public List getSelectItemList() {
List result = new ArrayList(this.getAllowedValues().size());
for(int i=0;i<this.getAllowedValues().size();i++) {
result.add(new SelectItem((Object)this.getAllowedValues().get(i),this.allowedLabels.get(i)));
}
return result;
}
protected void loadDB() {
String driverName = "com.mysql.jdbc.Driver";
String serverName = "localhost:3307";
String mydatabase = "propertyrecord";
String username = "propertyrecord";
String password = "rydenproperty";
List av = new ArrayList();
List al=new ArrayList();
try {
Connection connection = null;
Class.forName(driverName);
String url = “jdbc:mysql://” + serverName + “/” + mydatabase;
connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(“select propertyRef from propertyrecord”);
while (rs.next()) {
av.add(rs.getString(“propertyRef”));
al.add(rs.getString(“propertyRef”));
System.out.println(“value of prop pavani “+rs.getString(“propertyRef”));
logger.debug(“value of prop pavani “+rs.getString(“propertyRef”));
}
rs=null;
}
catch (Exception e) {}
super.setAllowedValues(av);
this.setAllowedLabels(al);
}
}
CustomListComponentGenerator.java
package org.alfresco.ryden;
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.component.UISelectOne;
import javax.faces.context.FacesContext;
import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.alfresco.service.cmr.dictionary.Constraint;
import org.alfresco.service.cmr.dictionary.ConstraintDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.web.bean.generator.TextFieldGenerator;
import org.alfresco.web.ui.repo.component.property.PropertySheetItem;
import org.alfresco.web.ui.repo.component.property.UIPropertySheet;
import org.apache.log4j.Logger;
import org.alfresco.ryden.ListOfValuesQueryConstraint;
public class CustomListComponentGenerator extends TextFieldGenerator {
private static Logger log = Logger.getLogger(CustomListComponentGenerator.class);
// private String tutorialQuery =
// “( TYPE:\”{http://www.alfresco.org/model/content/1.0}content\” AND
// (#\\{http\\://www.alfresco.org/model/content/1.0\\}name:\”tutorial\”
// TEXT:\”tutorial\”))”
// ;
private boolean autoRefresh = false;
public boolean isAutoRefresh() {
return autoRefresh;
}
/**
* This gets set from faces-config-beans.xml, and allows some drop downs to
* be automaticlaly refreshable (i.e. country), and others not (i.e. city).
*/
public void setAutoRefresh(boolean autoRefresh) {
this.autoRefresh = autoRefresh;
}
#Override
#SuppressWarnings(“unchecked”)
protected UIComponent createComponent(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem item) {
UIComponent component = super.createComponent(context, propertySheet, item);
log.info(“********************** ” + item + ” >” + component + ” >” + (component instanceof UISelectOne) + ” ” + isAutoRefresh());
if (component instanceof UISelectOne && isAutoRefresh()) {
component.getAttributes().put(“onchange”, “submit()”);
}
return component;
}
/**
* Retrieves the list of values constraint for the item, if it has one
*
* #param context
* FacesContext
* #param propertySheet
* The property sheet being generated
* #param item
* The item being generated
* #return The constraint if the item has one, null otherwise
*/
protected ListOfValuesConstraint getListOfValuesConstraint(FacesContext context, UIPropertySheet propertySheet, PropertySheetItem item) {
ListOfValuesConstraint lovConstraint = null;
log.info(“propertySheet: ” + propertySheet.getNode() + ” item: ” + item.getName());
// get the property definition for the item
PropertyDefinition propertyDef = getPropertyDefinition(context, propertySheet.getNode(), item.getName());
if (propertyDef != null) {
// go through the constaints and see if it has the
// list of values constraint
List constraints = propertyDef.getConstraints();
for (ConstraintDefinition constraintDef : constraints) {
Constraint constraint = constraintDef.getConstraint();
//log.info(“constraint: ” + constraint);
if (constraint instanceof ListOfValuesQueryConstraint) {
//Node currentNode = (Node) propertySheet.getNode();
// This is a workaround for the fact that constraints do not
// have a reference to Node.
//((ListOfValuesQueryConstraint) constraint).setNode(currentNode);
lovConstraint = (ListOfValuesQueryConstraint) constraint;
break;
}
if (constraint instanceof ListOfValuesConstraint) {
lovConstraint = (ListOfValuesConstraint) constraint;
break;
}
}
}
return lovConstraint;
}
}
custom-model.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Definition of Property Base Model -->
<model name="cdl:customdatalist" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<!-- Optional meta-data about the model -->
<description>Custom Data Model</description>
<author>Lalitha Akella</author>
<version>1.0</version>
<!-- Imports are required to allow references to definitions in other models -->
<imports>
<!-- Import Alfresco Dictionary Definitions -->
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
<!-- Import Alfresco Content Domain Model Definitions -->
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
<import uri="http://www.alfresco.org/model/datalist/1.0" prefix="dl"/>
</imports>
<!-- Introduction of new namespaces defined by this model -->
<namespaces>
<namespace uri="cdl.model" prefix="cdl"/>
</namespaces>
<constraints>
<constraint name="cdl:PropertyRef" type="org.alfresco.ryden.ListOfValuesQueryConstraint" >
<parameter name="allowedValues">
<list>
</list>
</parameter>
<parameter name="caseSensitive"><value>true</value></parameter>
</constraint>
</constraints>
<types>
<type name="cdl:applicationform">
<title>Custom Application Form</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="cdl:applicationpropertyRef">
<title>Property Reference</title>
<type>d:text</type>
<mandatory>true</mandatory>
<constraints>
<constraint ref="cdl:PropertyRef" />
</constraints>
</property>
<property name="cdl:applicationpropAddress">
<title>Property Address</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="cdl:apcreateddate">
<title>Created Date</title>
<type>d:date</type>
<mandatory>false</mandatory>
</property>
<property name="cdl:apcreatedby">
<title>Created By</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="cdl:applicationstatus">
<title>Application Status</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="cdl:applicationlink">
<title>Application Workflow Link</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
</properties>
<associations>
<association name="cdl:applicationassignee">
<title>Assignee</title>
<source>
<mandatory>true</mandatory>
<many>true</many>
</source>
<target>
<class>cm:person</class>
<mandatory>true</mandatory>
<many>false</many>
</target>
</association>
<association name="cdl:applicationattachments">
<title>Attachments</title>
<source>
<mandatory>true</mandatory>
<many>true</many>
</source>
<target>
<class>cm:cmobject</class>
<mandatory>true</mandatory>
<many>true</many>
</target>
</association>
</associations>
</type>
<type name="cdl:terminationform">
<title>Custom Termination Form</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="cdl:terminationpropertyRef">
<title>Property Reference</title>
<type>d:text</type>
<mandatory>true</mandatory>
<constraints>
<constraint ref="cdl:PropertyRef" />
</constraints>
</property>
<property name="cdl:trcreateddate">
<title>Created Date</title>
<type>d:date</type>
<mandatory>false</mandatory>
</property>
<property name="cdl:trcreatedby">
<title>Created By</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="cdl:terminationstatus">
<title>Termination Status</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="cdl:terminationlink">
<title>Termination Workflow Link</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
</properties>
<associations>
<association name="cdl:terminationassignee">
<title>Assignee</title>
<source>
<mandatory>true</mandatory>
<many>true</many>
</source>
<target>
<class>cm:person</class>
<mandatory>true</mandatory>
<many>false</many>
</target>
</association>
<association name="cdl:terminationattachments">
<title>Attachments</title>
<source>
<mandatory>true</mandatory>
<many>true</many>
</source>
<target>
<class>cm:cmobject</class>
<mandatory>true</mandatory>
<many>true</many>
</target>
</association>
</associations>
</type>
</types>
</model>
web-client-config-custom.xml
<config evaluator="node-type" condition="cdl:assignationform">
<property-sheet>
<show-property name="cdl:assignationpropertyRef" component-generator="CustomListComponentGenerator" />
</property-sheet>
</config>
faces-config-beans.xml
<managed-bean>
<description>
Bean that generates a custom generator component
</description>
<managed-bean-name>
CustomListComponentGenerator
</managed-bean-name>
<managed-bean-class>
org.alfresco.ryden.CustomListComponentGenerator
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>autoRefresh</property-name>
<value>true</value>
</managed-property>
</managed-bean>
I don't know whether I should be changing any other files or some thing is wrong in the code above.
I am new To alfresco. Any help is deeply appreciated.
Thanks,
Pavani
Try the following and change to as needed, as it works
ListOfCountriesQueryConstraint.java
package org.spectrum.customConstraints;
import java.util.ArrayList;
import java.util.List;
import java.sql.*;
import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.alfresco.web.bean.generator.BaseComponentGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.Serializable;
import javax.faces.model.SelectItem;
public class ListOfCountriesQueryConstraint extends ListOfValuesConstraint implements Serializable {
private static Log logger = LogFactory.getLog(BaseComponentGenerator.class);
private static final long serialVersionUID = 1;
private List<String> allowedLabels;
#Override
public void setAllowedValues(List allowedValues) {
}
#Override
public void setCaseSensitive(boolean caseSensitive) {
}
#Override
public void initialize() {
super.setCaseSensitive(false);
this.loadDB();
}
#Override
public List getAllowedValues() {
this.loadDB();
return super.getAllowedValues();
}
public List<String> getAllowedLabels() {
return this.allowedLabels;
}
public void setAllowedLabels(List<String> allowedLabels) {
this.allowedLabels = allowedLabels;
}
public List<SelectItem> getSelectItemList() {
List<SelectItem> result = new ArrayList<SelectItem>(this.getAllowedValues().size());
for (int i = 0; i < this.getAllowedValues().size(); i++) {
result.add(new SelectItem((Object) this.getAllowedValues().get(i), this.allowedLabels.get(i)));
}
return result;
}
protected void loadDB() {
String driverName = "org.gjt.mm.mysql.Driver";
String serverName = "alfrescotest";
String mydatabase = "alfresco_custom";
String username = "root";
String password = "support";
List<String> av = new ArrayList<String>();
List<String> al = new ArrayList<String>();
try {
Connection connection = null;
Class.forName(driverName);
String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("select country from countries");
while (rs.next()) {
av.add(rs.getString("country"));
al.add(rs.getString("country"));
}
} catch (Exception e) {
}
super.setAllowedValues(av);
this.setAllowedLabels(al);
}
}
custom-model.xml
<constraint name="sp:country" type="org.spectrum.customConstraints.ListOfCountriesQueryConstraint">
<parameter name="allowedValues">
<list>
</list>
</parameter>
<parameter name="caseSensitive"><value>true</value></parameter>
</constraint>
Make sure to copy the compile java to tomcat/webapps/alfresco/WEB-INF/classes/org/xxx/