Commit ad451c02 by Alex Rhodes

Groupable skeleton component working

parent 4a9d8115
<?xml version="1.0" encoding="UTF-8"?>
<pageflow:Pageflow xmlns:pageflow="http://www.sybase.com/suade/pageflow" id="pf14752596070850" configfile="/PrimeExtensions/WebContent/WEB-INF/faces-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">
<!-- Configuration here handles the dialog framework navigation and error handling framework for primefaces -->
<application>
<action-listener>org.primefaces.application.DialogActionListener</action-listener>
<navigation-handler>org.primefaces.application.DialogNavigationHandler</navigation-handler>
<view-handler>org.primefaces.application.DialogViewHandler</view-handler>
<el-resolver>
org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver
</el-resolver>
</application>
<factory>
<exception-handler-factory>
org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory
</exception-handler-factory>
</factory>
</faces-config>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!-- Google Charts JSF Wrapper Copyright (C) 2016 Alex Rhodes https://www.alexscottrhodes.com
Google Charts JSF Wrapper Information about this project including set-up and configuration information
Copyright (C) 2016 Alex Rhodes can be found here: https://bitbucket.org/alexscottrhodes/googlechartjsf Licensed
https://www.alexscottrhodes.com under the Apache License, Version 2.0 (the "License"); you may not use this
file except in compliance with the License. You may obtain a copy of the
Information about this project including set-up and configuration information can be found here: License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
https://bitbucket.org/alexscottrhodes/googlechartjsf applicable law or agreed to in writing, software distributed under the License
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
Licensed under the Apache License, Version 2.0 (the "License"); KIND, either express or implied. See the License for the specific language
you may not use this file except in compliance with the License. governing permissions and limitations under the License. © 2016 "Google"
You may obtain a copy of the License at and the Google logo are registered trademarks of Google Inc. The Google Charts
API is used under the Apache 2.0 License above. Google software is loaded
http://www.apache.org/licenses/LICENSE-2.0 from Google's servers as required in the Google Terms of Service. -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Unless required by applicable law or agreed to in writing, software xmlns="http://java.sun.com/xml/ns/javaee"
distributed under the License is distributed on an "AS IS" BASIS, xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. id="WebApp_ID" version="3.0">
See the License for the specific language governing permissions and
limitations under the License.
© 2016 "Google" and the Google logo are registered trademarks of Google Inc.
The Google Charts API is used under the Apache 2.0 License above. Google software
is loaded from Google's servers as required in the Google Terms of Service.
-->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>GoogleChartsJSF</display-name> <display-name>GoogleChartsJSF</display-name>
<welcome-file-list> <welcome-file-list>
<welcome-file>index.xhtml</welcome-file> <welcome-file>index.xhtml</welcome-file>
...@@ -37,6 +29,18 @@ is loaded from Google's servers as required in the Google Terms of Service. ...@@ -37,6 +29,18 @@ is loaded from Google's servers as required in the Google Terms of Service.
<servlet-name>Faces Servlet</servlet-name> <servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern> <url-pattern>*.xhtml</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
<context-param> <context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description> <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
...@@ -49,4 +53,8 @@ is loaded from Google's servers as required in the Google Terms of Service. ...@@ -49,4 +53,8 @@ is loaded from Google's servers as required in the Google Terms of Service.
<listener> <listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class> <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener> </listener>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>bootstrap</param-value>
</context-param>
</web-app> </web-app>
\ No newline at end of file
...@@ -10,25 +10,11 @@ ...@@ -10,25 +10,11 @@
<h:outputStylesheet name="style/demo.css" /> <h:outputStylesheet name="style/demo.css" />
</h:head> </h:head>
<h:body> <h:body>
<h:form id="agile"> <ar:groupable var="test" value="#{groupBean.test}" width="1200" height="600">
<p:outputPanel>
<c:forEach var="i" begin="0" end="2"> <h:outputText value="#{test.name}"/>
<p:outputPanel id="drop#{i}" style="margin-top:20px;display:inline-block;margin-left:20px;">
<p:dataTable id="agTable#{i}" styleClass="agileColumn" value="#{testBean.getCardsByList(i)}" var="cname" style="width:300px;" scrollable="true">
<p:ajax event="rowReorder" listener="#{testBean.onReorder}"/>
<p:column>
<p:outputPanel styleClass="card">
<h:outputText value="#{cname}"/>
<p:draggable revert="true" helper="clone"/>
</p:outputPanel> </p:outputPanel>
</p:column> </ar:groupable>
</p:dataTable>
<ar:droppable datasource="#{testBean.dataSourceString}">
<p:ajax listener="#{testBean.wasDrop}"/>
</ar:droppable>
</p:outputPanel>
</c:forEach>
</h:form>
</h:body> </h:body>
</html> </html>
......
<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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<h:outputStylesheet name="style/demo.css" />
</h:head>
<h:body>
<h:form id="temp">
<p:socket onMessage="handleMessage" channel="/push"/>
<script>
function handleMessage(message) {
remHandler([{name:"pushMessage", value:message}]);
console.log(message);
}
</script>
<p:remoteCommand name="remHandler" action="#{testBean.pushHandler()}" />
</h:form>
</h:body>
</html>
...@@ -36,3 +36,10 @@ ...@@ -36,3 +36,10 @@
background:#eaeaea; background:#eaeaea;
} }
.agileColumn > div > table > tbody > tr > td{
border:none !important;
}
.agileColumn > .ui-datatable-scrollable-header{
display:none !important;
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PrimeExtensions</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
...@@ -14,10 +14,25 @@ ...@@ -14,10 +14,25 @@
<version>5.3</version> <version>5.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.8</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId> <artifactId>jstl</artifactId>
<version>1.2</version> <version>1.2</version>
</dependency> </dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>2.4.7</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<sourceDirectory>src</sourceDirectory> <sourceDirectory>src</sourceDirectory>
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
<namespace>http://alexscottrhodes.com/facelets/pfe</namespace> <namespace>http://alexscottrhodes.com/facelets/pfe</namespace>
<tag> <tag>
<tag-name>droppable</tag-name> <tag-name>groupable</tag-name>
<component> <component>
<component-type>com.alexscottrhodes.extDroppable</component-type> <component-type>com.alexscottrhodes.groupable</component-type>
</component> </component>
</tag> </tag>
</facelet-taglib> </facelet-taglib>
\ No newline at end of file
package com.alexscottrhodes.demo;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import org.primefaces.component.dnd.Droppable;
import org.primefaces.context.RequestContext;
import org.primefaces.event.DragDropEvent;
import org.primefaces.event.ReorderEvent;
@ManagedBean
@ViewScoped
public class TestBean {
private HashMap<String,ArrayList<String>> catList = new HashMap<String,ArrayList<String>>();
private ArrayList<String> t1,t2,t3;
private String dataSourceIdString = "";
public TestBean(){
t1 = new ArrayList<String>();
t2 = new ArrayList<String>();
t3 = new ArrayList<String>();
t1.add("field 1");
t1.add("field 2");
t1.add("field 3");
catList.put("list 1",t1);
catList.put("list 2", t2);
catList.put("list 3",t3);
generateDsId();
}
public String getId(int test){
System.out.println(test);
return "lim";
}
public ArrayList<String> getLists(){
return new ArrayList<String>(catList.keySet());
}
public ArrayList<String> getCardsByList(int listPos){
return catList.get(new ArrayList<String>(catList.keySet()).get(listPos));
}
public void wasDrop(DragDropEvent ddEvent) {
//Parsing strings and table identities etc
String dragId = ddEvent.getDragId();
String dropId = ddEvent.getDropId();
String data = (String) ddEvent.getData();
String sourceTable = dragId.substring(dragId.indexOf("agTable"));
sourceTable = sourceTable.substring(0, sourceTable.indexOf(":"));
int sourceIndex = Integer.valueOf(sourceTable.replace("agTable",""));
int destIndex = Integer.valueOf(dropId.replace("agile:drop", ""));
//Remove from origin list
int i = 0;
for(Map.Entry<String, ArrayList<String>> entry : catList.entrySet()){
if(i==sourceIndex){
Iterator<String> lit = entry.getValue().iterator();
while(lit.hasNext()){
if(lit.next().equals(data)){
lit.remove();
break;
}
}
break;
}
i++;
}
//Add to destination list
i = 0;
for(Map.Entry<String, ArrayList<String>> entry : catList.entrySet()){
if(i==destIndex){
entry.getValue().add(0,data);
break;
}
i++;
}
RequestContext.getCurrentInstance().update("agile");
}
public void onReorder(ReorderEvent event){
String temp =(String) event.getSource();
System.out.println(temp);
}
public void generateDsId(){
String ds = "";
for(int i = 0; i < catList.size(); i++){
ds+="agTable" + i +",";
}
ds = ds.substring(0,ds.lastIndexOf(","));
dataSourceIdString = ds;
}
public String getDataSourceString(){
return dataSourceIdString;
}
public ArrayList<String> getT1() {
return t1;
}
public void setT1(ArrayList<String> t1) {
this.t1 = t1;
}
public ArrayList<String> getT2() {
return t2;
}
public void setT2(ArrayList<String> t2) {
this.t2 = t2;
}
public ArrayList<String> getT3() {
return t3;
}
public void setT3(ArrayList<String> t3) {
this.t3 = t3;
}
}
package com.alexscottrhodes.demo.groupable;
import java.util.ArrayList;
import javax.faces.bean.ManagedBean;
@ManagedBean
public class GroupBean {
ArrayList<TClass> test = new ArrayList<TClass>();
public GroupBean(){
for(int i = 0; i < 10; i++){
test.add(new TClass("test " + i));
}
}
public ArrayList<TClass> getTest() {
return test;
}
public void setTest(ArrayList<TClass> test) {
this.test = test;
}
public class TClass{
String name = "";
public TClass(String name){
this.name = name;
}
public String getName(){
return name;
}
}
}
package com.alexscottrhodes.demo.push;
import javax.inject.Singleton;
import org.primefaces.push.EventBus;
import org.primefaces.push.RemoteEndpoint;
import org.primefaces.push.annotation.OnClose;
import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.OnOpen;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.impl.JSONDecoder;
import org.primefaces.push.impl.JSONEncoder;
@PushEndpoint("/push")
@Singleton
public class PushEndpoints {
@OnMessage(encoders = {JSONEncoder.class},decoders={JSONDecoder.class})
public String onMessage(String message) {
return message;
}
@OnOpen
public void onOpen(RemoteEndpoint r, EventBus eventBus) {
}
@OnClose
public void onClose(RemoteEndpoint r, EventBus eventBus) {
}
}
package com.alexscottrhodes.groups;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
import javax.faces.component.FacesComponent;
import javax.faces.component.UIComponent;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
@FacesComponent(tagName = "groupable", createTag = true, namespace = "http://alexscottrhodes.com/facelets/pfe", value = "com.alexscottrhodes.groupable")
public class Groupable extends UIComponentBase {
@Override
public String getFamily() {
return "com.alexscottrhodes.groupable";
}
@Override
public void encodeEnd(FacesContext context) throws IOException {
//ResponseWriter writer = context.getResponseWriter();
@SuppressWarnings("rawtypes")
ArrayList value;
try{
value = (ArrayList<?>) this.getAttributes().get("value");
}catch(Exception e){
throw new RuntimeException("Invalid data.");
}
String var = (String) this.getAttributes().get("var");
Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
Object o = requestMap.get(var);
for(Object obj : value){
obj.getClass();
requestMap.put(var, obj);
for(UIComponent child : this.getChildren()){
child.encodeAll(this.getFacesContext());
}
}
if(o != null){
requestMap.put(var, o);
}else{
requestMap.remove(var);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment