JAVAFX Tableview hangs while resizing application with JAVA RESULT 255 - javafx-2

I have simple javafx application that hangs when resizing.
Application was compiled/build with jdk1.7.0_10
OS: Windows 8
IDE: NetBeans 7.2.1
The problem occurs when I populate bottom table and start resizing by shifting the right border of application. Sometimes I need to play with resizing for a while, shifting inner borders of SplitPanes and external application borders till it collapses. When the row is empty, that is nothing is populated in the table, then everything works fine - no hangings, I can resize in every direction whatever I want - and nothing hangs.
Application hangs and ends with Java Result: 255 in Netbeans Output Window.
What could it be? There are no logs, exceptions, nothing...it drives me mad, lost so much time on it :(
Here is my controller:
public class MyFXMLController implements Initializable {
#FXML
TableView<Person> table;
#FXML
TableColumn<Person, String> firstNameCol;
#FXML
TableColumn<Person, String> lastNameCol;
#FXML
TableColumn<Person, String> carCol;
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName"));
lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName"));
carCol.setCellValueFactory(new PropertyValueFactory("car"));
Person p1 = new Person();
p1.setFirstName("A");
p1.setLastName("B");
p1.setCar("ferrari");
ObservableList<Person> teamMembers = FXCollections.observableArrayList(p1);
table.setItems(teamMembers);
}
}
Main class is:
public class TestTableView extends Application {
#Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
AnchorPane page = null;
try {
page = (AnchorPane) FXMLLoader.load(TestTableView.class.getResource("/testtableview/myFXML.fxml"));
} catch (IOException ex) {
Logger.getLogger(TestTableView.class.getName()).log(Level.SEVERE, null, ex);
}
Scene scene = new Scene(page);
primaryStage.setScene(scene);
primaryStage.setTitle("my");
primaryStage.show();
}
/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
and FXML file used:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="715.0000999999975" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml" fx:controller="testtableview.MyFXMLController">
<children>
<SplitPane dividerPositions="0.22720894429047145" focusTraversable="true" prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<TreeView prefHeight="398.0" prefWidth="159.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<SplitPane dividerPositions="0.5" focusTraversable="true" orientation="VERTICAL" prefHeight="398.0" prefWidth="491.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<children>
<TableView id="table" prefHeight="195.0" prefWidth="489.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn prefWidth="75.0" text="Column X" />
<TableColumn prefWidth="75.0" text="Column X">
<columns>
<TableColumn prefWidth="75.0" text="Column X" />
<TableColumn prefWidth="75.0" text="Column X" />
</columns>
</TableColumn>
<TableColumn prefWidth="75.0" text="Column X">
<columns>
<TableColumn prefWidth="75.0" text="Column X" />
<TableColumn prefWidth="75.0" text="Column X" />
</columns>
</TableColumn>
<TableColumn prefWidth="75.0" text="Column X" />
<TableColumn prefWidth="75.0" text="Column X" />
</columns>
</TableView>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<children>
<TableView fx:id="table" prefHeight="195.0" prefWidth="489.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn prefWidth="75.0" text="firstNameCol" fx:id="firstNameCol" />
<TableColumn prefWidth="75.0" text="lastNameCol" fx:id="lastNameCol" />
<TableColumn prefWidth="75.0" text="carCol" fx:id="carCol" />
<TableColumn prefWidth="75.0" text="Column X" />
<TableColumn prefWidth="75.0" text="Column X" />
<TableColumn prefWidth="75.0" text="Column X" />
</columns>
</TableView>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
<stylesheets>
<URL value="#myfxml.css" />
</stylesheets>
</AnchorPane>
And underlying data class is:
package testtableview;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class Person {
private StringProperty firstName;
public void setFirstName(String value) {
firstNameProperty().set(value);
}
public String getFirstName() {
return firstNameProperty().get();
}
public StringProperty firstNameProperty() {
if (firstName == null) {
firstName = new SimpleStringProperty(this, "firstName");
}
return firstName;
}
private StringProperty lastName;
public void setLastName(String value) {
lastNameProperty().set(value);
}
public String getLastName() {
return lastNameProperty().get();
}
public StringProperty lastNameProperty() {
if (lastName == null) {
lastName = new SimpleStringProperty(this, "lastName");
}
return lastName;
}
private StringProperty car;
public void setCar(String value) {
carProperty().set(value);
}
public String getCar() {
return carProperty().get();
}
public StringProperty carProperty() {
if (car == null) {
car = new SimpleStringProperty(this, "car");
}
return car;
}
}

However I am not able to see any specific problem here. but it might be problem with your memory management. try to make data class static as a subclass in controller class.

Related

Primefaces pick list target is always empty

I have a pick list component and I have 2 lists, the first has data from my database and the second is a DualListModel and I have a button to transfer between the pick lists, when I transfer data nothing happenes the source in the DualListModel stays empty.
Here is my JSF code:
<p:pickList id="a" value="#{mbInstructor.model}" var="pickQ"
itemLabel="#{pickQ}" itemValue="#{pickQ}">
<o:converter converterId="omnifaces.ListConverter" list="#{mbInstructor.fullList}" />
<p:ajax event="transfer" listener="#{mbInstructor.onTransfer}" update="msg" />
<p:ajax event="select" listener="#{mbInstructor.onSelect}" update="msg" />
<p:ajax event="unselect" listener="#{mbInstructor.onUnselect}" update="msg" />
<p:ajax event="reorder" listener="#{mbInstructor.onReorder}" update="msg" />
</p:pickList>
And here is my methods in the managed bean:
private List<Question> fullList;
private DualListModel<Question> model;
public List<SemesterExamQuestionForm> getAllQuestionForms() {
GeneralFacade facade = new GeneralFacade();
return facade.lstSemesterExamQuestionForm(getCurrentStudySemesterExam());
}
public void onTransfer(TransferEvent event) {
StringBuilder builder = new StringBuilder();
for (Object item : event.getItems()) {
((Question) item).getQuestionTxt();
}
FacesMessage msg = new FacesMessage();
msg.setSeverity(FacesMessage.SEVERITY_INFO);
msg.setSummary("Items Transferred");
msg.setDetail(builder.toString());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public List<Question> getFullList() {
return fullList;
}
public DualListModel<Question> getModel() {
if(model == null){
model = new DualListModel<>();
}
fullList = getAllCourseQuestions();
model = new DualListModel<>(new ArrayList<>(fullList),new ArrayList<Question>());
return model;
}
public void setModel(DualListModel<Question> model) {
this.model = model;
}

java.lang.NullPointerException at org.primefaces.util.ResourceUtils.getComponentResources

I'm using PF6.0 and Wildfly 10 and my web app in some point needs to build some quite big grid of p:inplace objects on single page. Sounds easy.
The problem: when my grid is too big any ajax request ends with error.
To reproduce this problem I have working example:
The page test.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Test</title>
</h:head>
<h:body>
<h:form>
<!--it's a part of something bigger so this part is in outputPanel-->
<p:outputPanel id="details">
<h:outputText value="Size: #{backBean.size}" />
<p:panelGrid>
<!--btw. why it forces me to set all of this variables at p.repeat?-->
<p:repeat value="#{backBean.content}"
var="_row"
offset="0"
step="1"
size="#{backBean.content.size()}"
varStatus="_rowStatus" >
<p:row>
<p:repeat value="#{_row}"
var="_cell"
offset="0"
step="1"
size="#{_row.size()}"
varStatus="_rowStatus" >
<p:column>
<p:inplace editor="true">
<f:facet name="output">
<h:outputText value="#{_cell.output}" />
</f:facet>
<f:facet name="input">
<!--in real example it will be more complex with checkboxes, selectonemenu etc-->
<h:outputText value="First:" />
<p:inputText value="#{_cell.something}" />
<br />
<h:outputText value="Second:" />
<p:inputText value="#{_cell.another}" />
</f:facet>
</p:inplace>
</p:column>
</p:repeat>
</p:row>
</p:repeat>
</p:panelGrid>
</p:outputPanel>
<p:commandButton value="more" update="details" actionListener="#{backBean.weNeedMore}" />
</h:form>
</h:body>
</html>
Backing bean:
package com.test;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
#Named(value = "backBean")
#SessionScoped
public class BackBean implements Serializable {
private List<List<CellContent>> content;
private int size;
/**
* Creates a new instance of BackBean
*/
public BackBean() {
}
private void build() {
content = new ArrayList<>();
for(int i=0;i<size;i++) {
List<CellContent> row = new ArrayList<>();
for(int j=0;j<size;j++) {
CellContent cell = new CellContent();
row.add(cell);
}
content.add(row);
}
}
#PostConstruct
public void init() {
size = 10;
//create first content
build();
}
public void weNeedMore() {
//increase until we get error after click.
size = size + 10;
build();
}
//plain getters & setters
public List<List<CellContent>> getContent() {
return content;
}
public void setContent(List<List<CellContent>> content) {
this.content = content;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
}
and one class that holds my objects:
package com.test;
public class CellContent {
private String something = "";
private String another = "";
private String output = "click_me";
public CellContent() {
}
//some dummy update based on inputs
private void update() {
if(!something.equals(""))
output = something;
if(!another.equals(""))
output = "another: " + another;
}
//those two setters update the object
public void setSomething(String something) {
this.something = something;
update();
}
public void setAnother(String another) {
this.another = another;
update();
}
//rest are plain get&seters
public String getSomething() {
return something;
}
public String getAnother() {
return another;
}
public String getOutput() {
return output;
}
public void setOutput(String output) {
this.output = output;
}
}
When grid of my objects are "small" like 10x10 or 20x20 it works - I can click and update any cell.
But increasing size up to 30 (by hitting more button) leads to this error when I click anything:
09:47:13,602 ERROR [io.undertow.request] (default task-89) UT005023: Exception handling request to /myapp/test.xhtml: javax.servlet.ServletException
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:100)
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at org.primefaces.util.ResourceUtils.getComponentResources(ResourceUtils.java:66)
at org.primefaces.context.PrimePartialResponseWriter.startMetadataIfNecessary(PrimePartialResponseWriter.java:280)
at org.primefaces.context.PrimePartialResponseWriter.startError(PrimePartialResponseWriter.java:107)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:203)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:127)
at javax.faces.context.ExceptionHandlerWrapper.handle(ExceptionHandlerWrapper.java:100)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:123)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
... 34 more
Any idea what's happen? Is there any parameter I could adjust to avoid this error? Or any other solution (my current workaround is using datagrid with pagination).
FOUND IT ;)
I switched back to PF 5.3 to check if it's PrimeFaces issue.
There is no p:repeat # PF5.3 so I switched to ui:repeat.
Same was here but error message finally tells what's going on:
10:37:58,508 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default task-44) java.lang.IllegalStateException: UT000047: The number of parameters exceeded the maximum of 1000
at io.undertow.server.handlers.form.FormData.add(FormData.java:78)
at io.undertow.server.handlers.form.FormData.add(FormData.java:68)
All what I need to do is update max-parameters value at http-listener in standalone configuration:
<subsystem xmlns="urn:jboss:domain:undertow:3.0">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="default" max-parameters="10000" socket-binding="http" redirect-socket="https"/>
(found it at https://developer.jboss.org/thread/241526)

p:media problems with stream and autoplay

I got a datatable with a list of files, some of them are sound files. If I use a stream Firebug say a Network error 404. I made it work by writing the files (but param autoplay=false don't work), but its an ugly workaround, I'm probably missing something to make stream work.
Firebug says :
"NetworkError: 404 not found - http://localhost:8080/Projet/javax.faces.resource/dynamiccontent.properties.xhtml?ln=primefaces&v=5.3&pfdrid=1G8w72KY96Ob6Ye0QRtzBg%3D%3D&pfdrt=sc&pfdrid_c=true"
<p:dataTable var="doc" value="#{besoin.document}" id="besoinTableDocument"
draggableColumns="true" resizableColumns="true"
scrollable="true" scrollHeight="150"
selectionMode="single" rowKey="#{doc.id}">
<f:facet name="header">
<p:commandButton value="Upload" icon="ui-icon-extlink" onclick="PF('dlgupload').show();">
<f:attribute name="filId" value="0" />
</p:commandButton>
</f:facet>
<br/>
<p:column sortBy="nom" headerText="Nom">
<h:outputText value="#{doc.nom}" />
</p:column>
<p:column>
<p:commandButton icon="ui-icon-search" title="Télécharger" ajax="false" actionListener="#{documentBacking.makeFile}">
<f:attribute name="doc" value="#{doc}"/>
<p:fileDownload value="#{documentBacking.file}" />
</p:commandButton>
<p:commandButton icon="ui-icon-trash" title="Supprimer" ajax="true" actionListener="#{besoinView.deleteDocument}" update="besoinTableDocument">
<p:confirm header="Confirmation" message="Valider la suppression" icon="ui-icon-alert" />
<f:attribute name="doc" value="#{doc}"/>
</p:commandButton>
</p:column>
<p:column>
<<p:media value="/resources/sound/#{doc.nom}" player="quicktime" rendered="#{doc.sound}" width="200" height="30" >
<f:param name="autoPlay" value="false"/>
</p:media>
<p:media value="#{doc.stream}" player="quicktime" width="180" height="30" rendered="#{doc.sound}"/>
<f:param name="autoPlay" value="false"/>
</p:media>
</p:column>
</p:dataTable>
ManagedBean
#ManagedBean
#RequestScoped
public class Document implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int id;
private Besoin besoin;
private String nom;
private Blob blob;
private boolean sound;
private StreamedContent stream;
public Document(ResultSet rs, Besoin bean) throws SQLException {
this.id = rs.getInt("DOC_ID");
this.nom = rs.getString("DOC_NOM");
this.blob = rs.getBlob("DOC_BLOB");
this.besoin = bean;
this.sound = FilenameUtils.getExtension(nom).matches("^(ogg|mp3|mp4)$");
InputStream in = blob.getBinaryStream();
String mime = FacesContext.getCurrentInstance().getExternalContext().getMimeType(nom);
this.stream = (sound?new DefaultStreamedContent(in, mime):null);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Besoin getBesoin() {
return besoin;
}
public void setBesoin(Besoin besoin) {
this.besoin = besoin;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public Blob getBlob() {
return blob;
}
public void setBlob(Blob blob) {
this.blob = blob;
}
public boolean isSound() {
return sound;
}
public void setSound(boolean sound) {
this.sound = sound;
}
public StreamedContent getStream() {
return stream;
}
public void setStream(StreamedContent stream) {
this.stream = stream;
}
}

JSF Validator Problems

I'm doing the following:
I want do the validation implements interface validator of JSF. I have the following code:
index.xhtml:
<h:form id="inicio">
<p:panel id="panel" header="Digite sus Credenciales">
<p:focus context="panel"/>
<h:panelGrid id="gridInicio" columns="3" cellpadding="5" >
<p:outputLabel for="identificacion" value="Identificacion:"/>
<p:inputText id="identificacion" onfocus="true" value="#
{ingresoMB.usuario.identificacionUsuario}"
required="true"
label="Identificacion">
<f:validator validatorId="numericoValidator"/>
<f:validateLength minimum="2" />
</p:inputText>
</h:panelGrid>
<p:commandButton value="Ingresar" update="panel"
actionListener="#{ingresoMB.verificarInicio()}"
icon="ui-icon-check" />
</p:panel>
face-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<validator>
<validator-id>numericoValidator</validator-id>
<validator-class>co.com.patios.mb.util.validacioncomponentes.numericoValidator</validator-class>
</validator>
</faces-config>
numericoValidator.java:
import javax.faces.validator.ValidatorException;
public class numericoValidator implements Validator {
public numericoValidator() {
// TODO Auto-generated constructor stub
}
#Override
public void validate(FacesContext context, UIComponent component,
Object value) throws ValidatorException {
String identificacion = (String) value;
if(!validarNumerico(identificacion)){
FacesMessage message = new FacesMessage();
message.setSeverity(FacesMessage.SEVERITY_ERROR);
message.setDetail("Campo debe ser Numerico, Verifique !!!");
message.setSummary("Campo debe ser Numerico, Verifique !!!");
context.addMessage("inicio", message);
throw new ValidatorException(message);
}
}
private boolean validarNumerico(String value){
try{
Long.parseLong(value);
}catch (NumberFormatException e){
return false;
}
return true;
}
}
Now, in my index.xhtml I reference
<f:validator validatorId="numericoValidator"/>
validatorId="numericoValidator" is the Id in my face-config.xml:
<validator>
<validator-id>numericoValidator</validator-id>
<validator-class>co.com.patios.mb.util.validacioncomponentes.numericoValidator</validator-class>
</validator>
And co.com.patios.mb.util.validacioncomponentes.numericoValidator is my class java where I perform the validation.
But, I don't understand. Why do it not run ? It isn't showed message.
could you help me ?

How can I get popup window using commandButton in Trinidad?

How can I get popup window using commandButton in Trinidad?
My problem is that by clicking on Add button from dialogdemo.jspx, not any popup window or dialog box is opened.
This is dialogdemo.jspx file:
<jsp:root
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:tr="http://myfaces.apache.org/trinidad"
version="1.2">
<jsp:directive.page contentType="text/html;charset=utf-8" />
<f:view>
<tr:document title="Dialog Demo">
<tr:form>
<!--
The field for the value; we point partialTriggers at the
button to ensure it gets redrawn when we return
-->
<tr:inputText label="Pick a number:" partialTriggers="buttonId"
value="#{launchDialog.input}" />
<!--
The button for launching the dialog: we've also configured
the width and height of that window
-->
<tr:commandButton text="Add" action="dialog:chooseInteger"
id="buttonId" windowWidth="300" windowHeight="200"
partialSubmit="true" useWindow="true"
returnListener="#{launchDialog.returned}" />
</tr:form>
</tr:document>
</f:view>
</jsp:root>
Here is the associated managed bean LaunchDialogBean.java:
package jsfpkg;
import org.apache.myfaces.trinidad.component.UIXInput;
import org.apache.myfaces.trinidad.event.ReturnEvent;
public class LaunchDialogBean {
private UIXInput _input;
public UIXInput getInput() {
return _input;
}
public void setInput(UIXInput input) {
_input = input;
}
public void returned(ReturnEvent event) {
if (event.getReturnValue() != null) {
getInput().setSubmittedValue(null);
getInput().setValue(event.getReturnValue());
}
}
}
Here is the popup file Popup.jspx:
<jsp:root
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:trh="http://myfaces.apache.org/trinidad/html"
xmlns:tr="http://myfaces.apache.org/trinidad"
version="2.0">
<jsp:directive.page contentType="text/html;charset=utf-8" />
<f:view>
<tr:document title="Add dialog">
<tr:form>
<!-- Two input fields -->
<tr:panelForm>
<tr:inputText label="Number 1:" value="#{chooseInteger.value1}"
required="true" />
<tr:inputText label="Number 2:" value="#{chooseInteger.value2}"
required="true" />
</tr:panelForm>
<!-- Two buttons -->
<tr:panelGroup layout="horizontal">
<tr:commandButton text="Submit" action="#{chooseInteger.select}" />
<tr:commandButton text="Cancel" immediate="true"
action="#{chooseInteger.cancel}" />
</tr:panelGroup>
</tr:form>
</tr:document>
</f:view>
</jsp:root>
For that I have written the bean ChooseIntegerBean.java
package jsfpkg;
import org.apache.myfaces.trinidad.context.RequestContext;
public class ChooseIntegerBean {
private Integer _value1;
private Integer _value2;
public Integer getValue1() {
return _value1;
}
public void setValue1(Integer value1) {
_value1 = value1;
}
public Integer getValue2() {
return _value2;
}
public void setValue2(Integer value2) {
_value2 = value2;
}
public String cancel() {
RequestContext.getCurrentInstance().returnFromDialog(null, null);
return null;
}
public String select() {
Integer value = new Integer(getValue1().intValue() + getValue2().intValue());
RequestContext.getCurrentInstance().returnFromDialog(value, null);
return null;
}
}
Here is my faces-config.xml:
<managed-bean>
<managed-bean-name>chooseInteger</managed-bean-name>
<managed-bean-class>jsfpkg.ChooseIntegerBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>launchDialog</managed-bean-name>
<managed-bean-class>jsfpkg.LaunchDialogBean</managed-bean-class>
<managed-bean-scope>
request
</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/dialogdemo.jspx</from-view-id>
<navigation-case>
<from-outcome>dialog:chooseInteger</from-outcome>
<to-view-id>/dialogbox.jspx</to-view-id>
</navigation-case>
</navigation-rule>
I think action of your commandButton is wrong:
<tr:commandButton text="Submit" action="#{chooseIntegerBean.select}" windowWidth="300" windowHeight="200"
partialSubmit="true" useWindow="true" />
and in your ChooseIntegerBean:
public String select()
{
//other things
return "dialog:chooseInteger";
}
and in web.xml:
<context-param><param-name>org.apache.myfaces.trinidad.ENABLE_LIGHTWEIGHT_DIALOGS</param-name><param-value>true</param-value></context-param>
try removing /dialogdemo.jspx from you config file first. second time just remove the / in above tag in front of the file name.

Resources