Author: Alex.Kolonitsky
Date: 2009-03-02 09:52:46 -0500 (Mon, 02 Mar 2009)
New Revision: 12787
Added:
trunk/samples/panelmenu-sample/src/main/webapp/pages/rf5671.jsp
Modified:
trunk/framework/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java
trunk/framework/api/src/test/java/org/ajax4jsf/framework/util/javascript/ScriptUtilsTest.java
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/InternetResourceBase.java
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ServletResourceContext.java
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/UserResource.java
trunk/samples/panelmenu-sample/src/main/java/org/richfaces/Bean.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TabPanelTest.java
trunk/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java
Log:
ScriptUtils: toScript() fails with java.sql.* types
https://jira.jboss.org/jira/browse/RF-6278
Modified: trunk/framework/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java
===================================================================
--- trunk/framework/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java 2009-03-02
14:41:00 UTC (rev 12786)
+++ trunk/framework/api/src/main/java/org/ajax4jsf/javascript/ScriptUtils.java 2009-03-02
14:52:46 UTC (rev 12787)
@@ -71,11 +71,9 @@
} else if (obj instanceof Collection) {
// Collections put as JavaScript array.
-
@SuppressWarnings("unchecked")
Collection<Object> collection = (Collection<Object>) obj;
-
StringBuilder ret = new StringBuilder("[");
boolean first = true;
for (Iterator<Object> iter = collection.iterator(); iter.hasNext();) {
@@ -95,8 +93,7 @@
StringBuilder ret = new StringBuilder("{");
boolean first = true;
- for (Iterator<Map.Entry<Object, Object>> iter = map.entrySet().iterator();
iter.hasNext();) {
- Map.Entry<Object, Object> entry = iter.next();
+ for (Map.Entry<Object, Object> entry : map.entrySet()) {
if (!first) {
ret.append(',');
}
@@ -116,36 +113,63 @@
addEncodedString(ret, obj);
return ret.toString();
} else if (obj instanceof Enum) {
- // all other put as encoded strings.
- StringBuilder ret = new StringBuilder();
- addEncodedString(ret, obj);
- return ret.toString();
+ // all other put as encoded strings.
+ StringBuilder ret = new StringBuilder();
+ addEncodedString(ret, obj);
+ return ret.toString();
+ } else if (obj.getClass().getName().startsWith("java.sql.")) {
+ StringBuilder ret = new StringBuilder("{");
+ boolean first = true;
+ for (PropertyDescriptor propertyDescriptor :
+ PropertyUtils.getPropertyDescriptors(obj)) {
+ String key = propertyDescriptor.getName();
+ if ("class".equals(key)) {
+ continue;
+ }
+ Object value = null;
+ try {
+ value = PropertyUtils.getProperty(obj, key);
+ } catch (Exception e) {
+ continue;
+ }
+
+ if (!first) {
+ ret.append(',');
+ }
+
+ addEncodedString(ret, key);
+ ret.append(":");
+ ret.append(toScript(value));
+
+ first = false;
+ }
+ return ret.append("} ").toString();
}
+
// All other objects threaded as Java Beans.
- try {
- StringBuilder ret = new StringBuilder("{");
- PropertyDescriptor[] propertyDescriptors = PropertyUtils
- .getPropertyDescriptors(obj);
- boolean first = true;
- for (int i = 0; i < propertyDescriptors.length; i++) {
- PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
- String key = propertyDescriptor.getName();
- if ("class".equals(key)) {
- continue;
- }
- if (!first) {
- ret.append(',');
- }
- addEncodedString(ret, key);
- ret.append(":");
- ret.append(toScript(PropertyUtils.getProperty(obj, key)));
- first = false;
- }
- return ret.append("} ").toString();
- } catch (Exception e) {
- throw new FacesException(
- "Error in conversion Java Object to JavaScript", e);
- }
+ try {
+ StringBuilder ret = new StringBuilder("{");
+ PropertyDescriptor[] propertyDescriptors = PropertyUtils
+ .getPropertyDescriptors(obj);
+ boolean first = true;
+ for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
+ String key = propertyDescriptor.getName();
+ if ("class".equals(key)) {
+ continue;
+ }
+ if (!first) {
+ ret.append(',');
+ }
+ addEncodedString(ret, key);
+ ret.append(":");
+ ret.append(toScript(PropertyUtils.getProperty(obj, key)));
+ first = false;
+ }
+ return ret.append("} ").toString();
+ } catch (Exception e) {
+ throw new FacesException(
+ "Error in conversion Java Object to JavaScript", e);
+ }
}
public static void addEncodedString(StringBuilder buff, Object obj) {
Modified:
trunk/framework/api/src/test/java/org/ajax4jsf/framework/util/javascript/ScriptUtilsTest.java
===================================================================
---
trunk/framework/api/src/test/java/org/ajax4jsf/framework/util/javascript/ScriptUtilsTest.java 2009-03-02
14:41:00 UTC (rev 12786)
+++
trunk/framework/api/src/test/java/org/ajax4jsf/framework/util/javascript/ScriptUtilsTest.java 2009-03-02
14:52:46 UTC (rev 12787)
@@ -49,9 +49,6 @@
boolean _bool;
Object _foo;
- /**
- *
- */
public Bean() {
}
/**
@@ -100,7 +97,6 @@
public void setFoo(Object foo) {
this._foo = foo;
}
-
}
/**
@@ -125,6 +121,15 @@
int[] obj = {1,2,3,4,5};
assertEquals("[1,2,3,4,5] ", ScriptUtils.toScript(obj));
}
+
+ public void testSqlDate() {
+ java.sql.Time obj = new java.sql.Time(1);
+ assertNotNull(ScriptUtils.toScript(obj));
+
+ java.sql.Date obj1 = new java.sql.Date(1);
+ assertNotNull(ScriptUtils.toScript(obj1));
+ }
+
/**
* Test method for {@link
org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
*/
@@ -139,7 +144,7 @@
public void testTwoDimentionalStringArrayToScript() {
String[][] obj =
{{"one","two"},{"three","four"}};
assertEquals("[['one','two'] ,['three','four'] ]
", ScriptUtils.toScript(obj));
- Map map = new TreeMap();
+ Map<String, Object> map = new TreeMap<String, Object>();
map.put("a", obj);
map.put("b", "c");
assertEquals("{'a':[['one','two']
,['three','four'] ] ,'b':'c'} ",
ScriptUtils.toScript(map));
@@ -148,7 +153,7 @@
* Test method for {@link
org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
*/
public void testListToScript() {
- List obj = new ArrayList();
+ List<Integer> obj = new ArrayList<Integer>();
obj.add(new Integer(1));
obj.add(new Integer(2));
obj.add(new Integer(3));
@@ -161,7 +166,7 @@
* Test method for {@link
org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
*/
public void testSetToScript() {
- Set obj = new TreeSet();
+ Set<Integer> obj = new TreeSet<Integer>();
obj.add(new Integer(1));
obj.add(new Integer(2));
obj.add(new Integer(3));
@@ -182,7 +187,7 @@
*/
public void testObjectListToScript() {
Bean[] array = {new Bean(1,true,"foo"),new Bean(2,false,"bar")};
- List obj = Arrays.asList(array);
+ List<Bean> obj = Arrays.asList(array);
assertEquals("[{'bool':true,'foo':'foo',\'integer\':1}
,{'bool':false,'foo':'bar','integer':2} ] ",
ScriptUtils.toScript(obj));
}
@@ -190,7 +195,7 @@
* Test method for {@link
org.ajax4jsf.javascript.ScriptUtils#toScript(java.lang.Object)}.
*/
public void testMapToScript() {
- TreeMap obj = new TreeMap();
+ TreeMap<String, String> obj = new TreeMap<String, String>();
obj.put("a", "foo");
obj.put("b", "bar");
obj.put("c", "baz");
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/InternetResourceBase.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/InternetResourceBase.java 2009-03-02
14:41:00 UTC (rev 12786)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/InternetResourceBase.java 2009-03-02
14:52:46 UTC (rev 12787)
@@ -369,9 +369,7 @@
*/
public void send(ResourceContext context) throws IOException {
if (log.isDebugEnabled()) {
- log
- .debug(Messages.getMessage(Messages.SEND_CONTENT_INFO,
- getKey()));
+ log.debug(Messages.getMessage(Messages.SEND_CONTENT_INFO,getKey()));
}
int total = getRenderer(context).send(this, context);
// For cacheable resources, store size.
@@ -391,41 +389,39 @@
* @see
org.ajax4jsf.chameleon.resource.InternetResource#sendHeaders(javax.servlet.http.HttpServletResponse)
*/
public void sendHeaders(ResourceContext context) {
- boolean cached = context.isCacheEnabled() && isCacheable(context);
- if (log.isDebugEnabled()) {
- log.debug(Messages.getMessage(Messages.SET_RESPONSE_HEADERS_INFO,
- getKey()));
- }
- // context.setHeader("Content-Type",getContentType());
- context.setContentType(getContentType(context));
- Date lastModified = getLastModified(context);
- if (lastModified != null) {
- context.setDateHeader("Last-Modified", lastModified.getTime());
- }
- int contentLength = getContentLength(context);
- if (cached) {
- if (contentLength > 0) {
- context.setContentLength(contentLength);
- }
- long expired = getExpired(context);
- if (expired < 0 ) {
- expired = DEFAULT_EXPIRE;
- }
- context.setDateHeader("Expires", System.currentTimeMillis()
- + expired);
- context.setHeader("Cache-control", "max-age="
- + (expired / 1000L));
- } else {
- if (contentLength > 0) {
- context.setContentLength(contentLength);
-// } else {
-// context.setHeader("Transfer-Encoding", "chunked");
- }
- context.setHeader("Cache-control", "max-age=0, no-store,
no-cache");
- context.setHeader("Pragma", "no-cache");
- context.setIntHeader("Expires", 0);
- }
- }
+ boolean cached = context.isCacheEnabled() && isCacheable(context);
+ if (log.isDebugEnabled()) {
+ log.debug(Messages.getMessage(Messages.SET_RESPONSE_HEADERS_INFO,
+ getKey()));
+ }
+ // context.setHeader("Content-Type",getContentType());
+ context.setContentType(getContentType(context));
+ Date lastModified = getLastModified(context);
+ if (lastModified != null) {
+ context.setDateHeader("Last-Modified", lastModified.getTime());
+ }
+ int contentLength = getContentLength(context);
+ if (cached) {
+ if (contentLength > 0) {
+ context.setContentLength(contentLength);
+ }
+ long expired = getExpired(context);
+ if (expired < 0) {
+ expired = DEFAULT_EXPIRE;
+ }
+ context.setDateHeader("Expires", System.currentTimeMillis() +
expired);
+ context.setHeader("Cache-control", "max-age=" + (expired
/ 1000L));
+ } else {
+ if (contentLength > 0) {
+ context.setContentLength(contentLength);
+ // } else {
+ // context.setHeader("Transfer-Encoding",
"chunked");
+ }
+ context.setHeader("Cache-control", "max-age=0, no-store,
no-cache");
+ context.setHeader("Pragma", "no-cache");
+ context.setIntHeader("Expires", 0);
+ }
+ }
/*
* (non-Javadoc)
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java 2009-03-02
14:41:00 UTC (rev 12786)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ResourceLifecycle.java 2009-03-02
14:52:46 UTC (rev 12787)
@@ -109,27 +109,25 @@
public void send(ResourceContext resourceContext, InternetResource resource)
throws IOException {
FacesContext facesContext = FacesContext.getCurrentInstance();
- PhaseListener[] phaseListeners = null;
- PhaseEvent renderViewEvent = null;
if (null != facesContext) {
Lifecycle facesLifecycle = getFacesLifecycle();
- phaseListeners = facesLifecycle.getPhaseListeners();
+ PhaseListener[] phaseListeners = facesLifecycle.getPhaseListeners();
PhaseEvent restoreViewEvent = new PhaseEvent(facesContext,
PhaseId.RESTORE_VIEW, this);
processPhaseListeners(phaseListeners, restoreViewEvent, true);
// Fix for a
http://jira.jboss.org/jira/browse/RF-1056
- if (facesContext.getResponseComplete())
+ if (facesContext.getResponseComplete()) {
return;
+ }
// fix for a
http://jira.jboss.com/jira/browse/RF-1064 .
// viewRoot can be created outside.
UIViewRoot savedViewRoot = facesContext.getViewRoot();
try {
- // create "dummy" viewRoot, to avoid problems in phase
- // listeners.
+ // create "dummy" viewRoot, to avoid problems in phase listeners.
UIViewRoot root = new UIViewRoot();
String key = resource.getKey();
- if(null != key && !key.startsWith("/")){
- key="/"+key;
+ if (null != key && !key.startsWith("/")) {
+ key = "/" + key;
}
root.setViewId(key);
root.setLocale(Locale.getDefault());
@@ -140,12 +138,11 @@
// Fix for a
http://jira.jboss.org/jira/browse/RF-1056
if (!facesContext.getResponseComplete()) {
// Invoke before render view phase listeners
- renderViewEvent = new PhaseEvent(facesContext,
+ PhaseEvent renderViewEvent = new PhaseEvent(facesContext,
PhaseId.RENDER_RESPONSE, this);
processPhaseListeners(phaseListeners, renderViewEvent, true);
sendResource(resourceContext, resource);
- processPhaseListeners(phaseListeners, renderViewEvent,
- false);
+ processPhaseListeners(phaseListeners, renderViewEvent, false);
}
} finally {
@@ -201,11 +198,8 @@
phaseListener.afterPhase(phaseEvent);
}
} catch (Exception e) {
- _log
- .debug("Exception in PhaseListener, phase :"
- + phaseEvent.getPhaseId().toString()
- + (beforePhase ? " : beforePhase"
- : " : afterPhase"), e);
+ _log.debug("Exception in PhaseListener, phase :" +
phaseEvent.getPhaseId().toString()
+ + (beforePhase ? " : beforePhase" : " : afterPhase"), e);
}
}
}
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ServletResourceContext.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ServletResourceContext.java 2009-03-02
14:41:00 UTC (rev 12786)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/ServletResourceContext.java 2009-03-02
14:52:46 UTC (rev 12787)
@@ -135,7 +135,8 @@
* @return
* @see javax.servlet.ServletContext#getResourcePaths(java.lang.String)
*/
- public Set getResourcePaths(String path) {
+ @SuppressWarnings("unchecked")
+ public Set getResourcePaths(String path) {
return context.getResourcePaths(path);
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/resource/UserResource.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/resource/UserResource.java 2009-03-02
14:41:00 UTC (rev 12786)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/resource/UserResource.java 2009-03-02
14:52:46 UTC (rev 12787)
@@ -32,12 +32,7 @@
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
-import javax.faces.el.ValueBinding;
-import org.ajax4jsf.resource.ResourceComponent;
-import org.ajax4jsf.resource.ResourceContext;
-
/**
* @author shura
*
Modified: trunk/samples/panelmenu-sample/src/main/java/org/richfaces/Bean.java
===================================================================
--- trunk/samples/panelmenu-sample/src/main/java/org/richfaces/Bean.java 2009-03-02
14:41:00 UTC (rev 12786)
+++ trunk/samples/panelmenu-sample/src/main/java/org/richfaces/Bean.java 2009-03-02
14:52:46 UTC (rev 12787)
@@ -25,7 +25,13 @@
*
*/
public class Bean {
+
+ private String name = "two";
+ public void action() {
+ System.out.println(">> Bean.action");
+ }
+
public String executeServer(){
System.out.println("executed server");
return null;
@@ -36,18 +42,14 @@
return null;
}
-
-
public String executeItem1(){
System.out.println("item1 executed ");
return null;
-
}
public String executeItem2(){
System.out.println("item2 executed ");
return null;
-
}
public String executeItem3(){
@@ -55,5 +57,13 @@
return null;
}
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
}
\ No newline at end of file
Added: trunk/samples/panelmenu-sample/src/main/webapp/pages/rf5671.jsp
===================================================================
--- trunk/samples/panelmenu-sample/src/main/webapp/pages/rf5671.jsp
(rev 0)
+++ trunk/samples/panelmenu-sample/src/main/webapp/pages/rf5671.jsp 2009-03-02 14:52:46
UTC (rev 12787)
@@ -0,0 +1,27 @@
+<%@ taglib
uri="http://java.sun.com/jsf/html" prefix="h" %>
+<%@ taglib
uri="http://java.sun.com/jsf/core" prefix="f"%>
+<%@ taglib
uri="http://richfaces.org/a4j" prefix="a4j"%>
+<%@ taglib
uri="http://labs.jboss.com/jbossrichfaces/ui/panelmenu"
prefix="pm"%>
+
+<html>
+ <head>
+ <style type="text/css">
+ </style>
+ </head>
+ <body>
+ <f:view>
+ <h:form>
+ <h2>3</h2>
+ <pm:panelMenu selectedChild="one" id="pb3"
mode="ajax">
+ <pm:panelMenuGroup expanded="true">
+ <pm:panelMenuItem id="one"
label="one"/>
+ <pm:panelMenuItem id="two"
label="two"/>
+ </pm:panelMenuGroup>
+ </pm:panelMenu>
+ <div>
+ In this case if the User.name="one" by default - no
selection will happens at all from the beggining because item in collapsed group.
+ </div>
+ </h:form>
+ </f:view>
+ </body>
+</html>
\ No newline at end of file
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TabPanelTest.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TabPanelTest.java 2009-03-02
14:41:00 UTC (rev 12786)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/TabPanelTest.java 2009-03-02
14:52:46 UTC (rev 12787)
@@ -254,9 +254,7 @@
Assert.fail("https://jira.jboss.org/jira/browse/RF-5759");
String tabId1 = parentId + FORM_ID + "tab1";
String tabId2 = parentId + FORM_ID + "tab2";
- String tabId3 = parentId + FORM_ID + "tab3";
String tabId4 = parentId + FORM_ID + "tab4";
- String messages = parentId + FORM_ID + "messages";
setValueById(tabId1 + "_input", "text");
setValueById(tabId4 + "_input", "text");
@@ -276,9 +274,6 @@
Assert.fail("https://jira.jboss.org/jira/browse/RF-5759");
String tabId1 = parentId + FORM_ID + "tab1";
String tabId2 = parentId + FORM_ID + "tab2";
- String tabId3 = parentId + FORM_ID + "tab3";
- String tabId4 = parentId + FORM_ID + "tab4";
- String messages = parentId + FORM_ID + "messages";
setValueById(tabId1 + "_input", "text");
Modified:
trunk/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java
===================================================================
---
trunk/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java 2009-03-02
14:41:00 UTC (rev 12786)
+++
trunk/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java 2009-03-02
14:52:46 UTC (rev 12787)
@@ -42,7 +42,7 @@
}
protected void doDecode(FacesContext context, UIComponent component) {
- if(isSubmitted(context, component)) {
+ if (isSubmitted(context, component)) {
new ActionEvent(component).queue();
if ("ajax".equals(getItemMode(component))) {
new AjaxEvent(component).queue();