| Author |
Message |
|
|
I have been looking at warp-persist as a way to manage transactions in a Java SE environment. All the examples for it are either stand-alone app (started using main() method) or servlets.
In the servlet examples, one needs to configure an implementation of a ServletContextListener. Is it possible to add a servlet context listener in the web.xml of my ICEFaces portlet and it be used as it would in a regular servlet application?
Thanks again!
|
 |
|
|
Hi,
I'm using JPA (Java SE, so must manage transactions manually) in a portlet and need a place to create and close an EntityManagerFactory and an EntityManager.
There was a post in the General Help forum similar to this one for servlets and the solution was to use ServletContextListener. Howevr, my app is a portlet. Also, I want to make sure that I can close the EntityManager/Factory when the portlet is destroyed.
My only solution so far has been to extend MainPortlet and override the init and destroy methods. However, I'm not sure how I would access the EntityManager from my backing bean.
Any advice?
Thanks in advance!
|
 |
|
|
Apparently I had all but one piece set up for the visual editor. I needed to open the Palette view and the components are now available for drag and drop.
However, it would be really nice to have the auto-complete on the tags. Does anyone know if this is possible in Eclipse?
Thanks again!
|
 |
|
|
Hi,
I posted this question on the Eclipse forums but haven't got any responses. Hoping someone here may have an answer...
I have Eclipse 3.5 with WTP and have installed these additional plugins:
- Portlet Tools
- ICEFaces
- Java EE IDE (part of WTP?)
I am working on a portlet that uses ICEFaces. I have set my project up to use these facets:
- Java v6.0
- Dynamic Web Module v2.5
- Portlet Module (JSR) v2.0
- JavaServer Faces v.12.
- ICEFaces v1.8
What else do I have to do make available/open the Visual JSF editor? I can't find anything under Views or Perspectives.
I can open my web files withthe "Web Page Editor". Is this the same as the Visual JSF editor? It does have visual component but I was under the impression the JSF editor had drag/drop capabilities.
However, even in this view, I do not get any autocomplete functionality when I type in a tag (as one gets in NetBeans and IntelliJ).
For example, this is my file view.xhtml:
Code:
<?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">
<f:view xmlns:f="http://java.sun.com/jsf/core"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ice:portlet>
<ice:form>
<ice:outputStyle href="/xmlhttp/css/xp/xp-portlet.css" />
<ice:outputStyle href="/css/style.css" />
<div id="header">
<h1><ice:outputText value="View Page"/></h1>
<p>This is the view page</p>
</div>
</ice:form>
</ice:portlet>
</f:view>
If I type in "<ice:", I would expect an autocomplete list of ICEFaces component names to choose from to be displayed. Should I not expect this or is there some further configuration that I need to do? Does it have anything to do with my files being .xhtml and not .jsp?
Thanks in advance!
Link to Eclipse forum thread:
http://www.eclipse.org/forums/index.php?t=msg&th=169467&start=0&
|
 |
|
|
I have been able to come up with a solution (kludge?). There may be a better, more elegant way to do this, but I couldn't find it online.
It appears that one has to recursively iterate through the component tree to get the dataExporter component. So, I created this method:
Code:
/**
* Recursively iterates through the component tree starting at parent looking
* for a component with a matching id.
*
* @param parent component to start iteration at
* @param id id of component to find
* @return the component if found, null if not
*/
public static UIComponent findComponent(UIComponent parent, String id)
{
UIComponent component = null;
Iterator<UIComponent> components = parent.getFacetsAndChildren();
while (components.hasNext())
{
UIComponent child = components.next();
if (child.getId().equals(id))
{
component = child;
break;
}
else
{
component = findComponent(child, id);
}
}
return component;
}
I make use of this method in my DataBean class when I get teh output handler:
Code:
public OutputTypeHandler getOutputHandler()
{
FacesContext facesContext = FacesContext.getCurrentInstance();
UIViewRoot viewRoot = facesContext.getViewRoot();
UIComponent component = ComponentUtils.findComponent(viewRoot, "dataExporter");
CustomCSVOutputHandler outputHandler = null;
if(component instanceof DataExporter)
{
UIData uiData = ((DataExporter) component).getUIData();
outputHandler = new CustomCSVOutputHandler("MyFile.csv");
outputHandler.setUIData(uiData);
}
return outputHandler;
}
I then re-wrote and re-wrote and re-wrote again my CustomCSVOutputHandler until I got data in file with the headers as the first row:
Code:
package portlet.utils;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.model.ArrayDataModel;
import javax.faces.model.ListDataModel;
import com.icesoft.faces.component.dataexporter.OutputTypeHandler;
import com.icesoft.faces.component.ext.UIColumns;
/**
* This is a custom CSV output handler class because the IceFaces
* CSVOutputHandler and DataExporter classes only deal with DataTables that make
* use of UIColumn (singular) and not UIColumns (plural). Using CSVOutputHandler
* will result in generating an empty file.
* <br/>
* See http://www.icefaces.org/JForum/posts/list/15232.page for more info.
*/
public class CustomCSVOutputHandler extends OutputTypeHandler
{
private StringBuffer buffer;
private int rowIndex = 0;
private UIData uiData;
public CustomCSVOutputHandler(String path)
{
super(path);
this.buffer = new StringBuffer();
this.mimeType = "text/csv";
}
public void flushFile()
{
this.writeColumns();
this.deleteComma();
try
{
BufferedWriter writer = new BufferedWriter(new FileWriter(getFile()));
writer.write(buffer.toString());
writer.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
public void writeCell(Object output, int col, int row)
{
if (row != rowIndex)
{
deleteComma();
buffer.append("\n");
rowIndex++;
}
buffer.append(output.toString() + ",");
}
public void writeHeaderCell(String text, int col)
{
// no special handling for header cells
}
private void deleteComma()
{
int comma = buffer.lastIndexOf(",");
if (comma > 0)
{
buffer.deleteCharAt(comma);
}
}
public void setUIData(UIData data)
{
this.uiData = data;
}
private void writeColumns()
{
Iterator<UIComponent> components = uiData.getFacetsAndChildren();
int row = 0;
// Write header row to file
while (components.hasNext())
{
UIComponent component = (UIComponent) components.next();
if ((component instanceof UIColumns) && (component.isRendered()))
{
UIColumns uiColumns = (UIColumns) component;
ArrayDataModel colDataModel = (ArrayDataModel) uiColumns
.getAttributes().get("value");
for (int i = 0; i < colDataModel.getRowCount(); i++)
{
colDataModel.setRowIndex(i);
// For CSV files, header row treated same as data rows
writeCell(colDataModel.getRowData().toString(), i, row);
}
}
}
row++;
// Write data rows to file
try
{
ListDataModel rowDataModel = (ListDataModel) uiData.getAttributes()
.get("value");
List<Object> data = (List<Object>) rowDataModel.getWrappedData();
for (Iterator<Object> dataIter = data.iterator(); dataIter
.hasNext();)
{
Object dataObject = dataIter.next();
ArrayList<Object> arrayList = (ArrayList) dataObject;
int column = 0;
for (Iterator<Object> listIter = arrayList.iterator(); listIter
.hasNext();)
{
Object listObject = listIter.next();
writeCell(listObject, column, row);
column++;
}
row++;
}
}
catch (Exception e)
{
}
}
}
Finally, this is how I include the tag in my xhtml file:
Code:
<ice:dataExporter id="dataExporter"
for="myData"
label="Download as CSV File"
renderLabelAsButton="true"
type="csv2"
popupBlockerLabel="Popup Blocker detected - click here to resume download..."
outputTypeHandler="#{dataBean.outputHandler}"/>
Note that I set the type to "csv2" so that there wouldn't be anything weird happening in the DataExporter class if it checked the type.
|
 |
|
|
Hi,
I have an issue where the file created by a dataExporter creates an empty file. I found this earlier forum entry and have tried to create a workaround based on the advice in it, but am not succeeding.
http://www.icefaces.org/JForum/posts/list/15232.page
In my .xhtml file I have:
Code:
<ice:dataTable id="myData" value="#{data.rowModel}" var="index" rows="12" >
<ice:columns value="#{data.columnsModel}" var="headings">
<f:facet name="header">
<ice:outputText value="#{headings}" styleClass="dataHeader"/>
</f:facet>
<ice:outputText value="#{data.cellValue}" styleClass="cellValue"/>
</ice:columns>
</ice:dataTable>
<ice:dataExporter id="dataExporter"
for="myData"
label="Download as CSV File"
renderLabelAsButton="true"
type="csv"
popupBlockerLabel="Popup Blocker detected - click here to resume download..."
outputTypeHandler="#{dataBean.outputHandler}"/>
In my backing bean (DataBean), I added this method:
Code:
public OutputTypeHandler getOutputHandler()
{
FacesContext facesContext = FacesContext.getCurrentInstance();
UIComponent component = facesContext.getViewRoot().findComponent("dataExporter");
CustomCSVOutputHandler output = null;
if(component instanceof DataExporter)
{
UIData uiData = ((DataExporter) component).getUIData();
output = new CustomCSVOutputHandler("Data Export");
output.setUIData(uiData);
}
return output;
}
And then I created this class:
Code:
package portlet.utils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.model.ListDataModel;
import org.apache.commons.validator.GenericValidator;
import com.icesoft.faces.component.dataexporter.CSVOutputHandler;
import com.icesoft.faces.component.ext.UIColumns;
public class CustomCSVOutputHandler extends CSVOutputHandler
{
public CustomCSVOutputHandler(String path)
{
super(path);
}
private UIData uiData;
public void setUIData(UIData data)
{
this.uiData = data;
}
public void flushFile()
{
writeColumns();
super.flushFile();
}
private void writeColumns()
{
Iterator<UIComponent> components = uiData.getFacetsAndChildren();
while (components.hasNext())
{
UIComponent component = (UIComponent) components.next();
if ((component instanceof UIColumns) && (component.isRendered()))
{
UIColumns uiColumn = (UIColumns) component;
ListDataModel colDataModel = (ListDataModel) uiColumn
.getAttributes().get("value");
for (int i = 0; i < colDataModel.getRowCount(); i++)
{
colDataModel.setRowIndex(i);
writeHeaderCell(colDataModel.getRowData().toString(), i);
}
}
}
try
{
ListDataModel rowDataModel = (ListDataModel) uiData.getAttributes()
.get("value");
List<Object> data = (List) rowDataModel.getWrappedData();
int count = 0;
for (Iterator<Object> dataIter = data.iterator(); dataIter.hasNext();)
{
Object dataObject = dataIter.next();
ArrayList<Object> arrayList = (ArrayList) dataObject;
int column = 0;
for (Iterator listIter = arrayList.iterator(); listIter.hasNext();)
{
Object listObject = listIter.next();
if (GenericValidator.isDouble(listObject.toString()))
{
writeCell(new Double(listObject.toString()), column, count);
}
else
{
writeCell(listObject, column, count);
}
column++;
}
count++;
}
}
catch (Exception e)
{
}
}
}
My problem is that the getOutputHandler method in the DataBean class doesn't find the dataExporter component. This line:
Code:
UIComponent component = facesContext.getViewRoot().findComponent("dataExporter");
returns null, so my custom output handler is never instantiated so I don't know if it works or not.
I am new to JSF and IceFaces and do not understand the component model. I wrote some code to iterate/display the name of all the facets and children from the UIViewRoot, but there was only one object.
Can somebody point me in the right direction?
|
 |
|
|
Hi Havis,
Setting the project as main is irrelevant to the issue. Mine is not set as main. Here's a snapshot of my project tree...
|
 |
|
|
SOLVED
For future reference, I figured out how to install the component library in my project. Part of my problem is that I'm new to NetBeans. I've been an Eclipse user for a number of years and am using NetBeans because of the Visual Web Pack. The line in the readme.html
Add Component Library to Componet Libraries Folder under Visual Web Project.
threw me off because I was looking for something called "Visual Web Project". I found these instructions (http://www.netbeans.org/kb/55/vwp-ajaximportcomponents.html) which were much more clear to me:
Adding a Component Library to a Project
1. Open the Visual Web Application project in which you want to use the component library's components.
Note: If the components are JavaServer Faces 1.2 components, the project must use a server that supports this level of JavaServer Faces technology. For example, if you use Sun Java System Application Server 9.0 and Java EE 5, both JavaServer Faces 1.2 and JavaServer Faces 1.1 components are supported.
2. In the Projects window, open the main project node and right-click the Component Libraries node.
3. Choose Add Component Library.
....
May I suggest that the readme.html be updated with instructions similar to those quoted? However, I'm just glad to have the solution...
|
 |
|
|
From the readme.html in ICEfaces-v1.5.2-NetBeans-VWP.zip:
Add the ICEfaces Component library to Visual Project
To use the ICEfaces Component Suite in Netbeans VWP in the "Design" editor, you must first Add Component Library to Netbeans VWP Visual web Project.
Once you create a new Visual Web Project, you may:
1. Add Component Library to Componet Libraries Folder under Visual Web Project.
....
How is this to be done? I've tried adding it by looking at the project Properties -> Libraries, but it isn't available in the list of libraries. I think this is because its not active. So I'm back to how do I make the library active?
|
 |
|
|
I have NetBeans 5.5 installed and tried installing the ICEfaces VWP support. I installed both the com-icesoft-faces-vwp-ide.nbm and com-icesoft-faces-icefaces-vwp.nbm modules and then imported the ICEfaces Component Suite (EA) (1.5.2) via the Component Library Manager.
I don't see any new components in the palette when in Design view for a new project (ICEfaces was enabled for the project).
When I view the modules in NetBeans via the Module Manager, under Visual Web, ICfaces Project Integration is listed and is active. However, under Libraries, ICEfaces Complib Library is listed but is inactive. There doesn't seem to be a way to make it active. I've tried "Activate All Modules" and there's no effect.
I've completely uninstalled NetBeans and reinstalled from scratch, but get the same results.
Has anyone successfully implemented the component library?
|
 |
|
|