You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by ma...@apache.org on 2007/03/29 07:51:08 UTC
svn commit: r523607 [6/14] - in /incubator/adffaces/trunk/trinidad:
trinidad-assembly/ trinidad-assembly/src/ trinidad-assembly/src/main/
trinidad-assembly/src/main/assembly/ trinidad-assembly/src/main/resources/
trinidad-examples/ trinidad-examples/bl...
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/RelativeDateConverter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/RelativeDateConverter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ReplyToMessageBackingBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ReplyToMessageBackingBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ReplyToMessageBackingBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ReplyToMessageBackingBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.email;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.mail.Address;
+import javax.mail.Folder;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.internet.InternetAddress;
+
+import org.apache.myfaces.trinidad.context.RequestContext;
+
+/**
+ * Backing bean for the "reply-to message" page.
+ * @todo For now, the original contents are not included in the reply
+ * We could add a preference so the user can choose to include
+ * the original contents in replies
+ */
+public class ReplyToMessageBackingBean extends NewMessageBackingBean
+{
+ public ReplyToMessageBackingBean()
+ {
+ // if the user pressed the Reply button, then the pageFlowScope's
+ // replyToAll value will be false. If the user pressed the
+ // Reply to All button, then the pageFlowScope's replyToAll value
+ // will be true. We set this in the showMessage.jspx page.
+ RequestContext afContext = RequestContext.getCurrentInstance();
+
+ Object replyToAll = afContext.getPageFlowScope().get("replyToAll");
+
+ _setUpReplyToMessage("true".equals(replyToAll));
+ }
+
+ private void _setUpReplyToMessage(boolean replyToAll)
+ {
+ RequestContext afContext = RequestContext.getCurrentInstance();
+
+ MessageData message =
+ (MessageData) afContext.getPageFlowScope().get("message");
+
+ if (message == null) return;
+ Message msg = message.getMessage();
+
+ try
+ {
+ msg.getFolder().open(Folder.READ_ONLY);
+ Message replyMessage = msg.reply(replyToAll);
+
+ setSubject(replyMessage.getSubject());
+ Address[] replyToAddresses = replyMessage.getAllRecipients();
+ setTo(_getAddressString(replyToAddresses));
+
+ }
+ catch (MessagingException e)
+ {
+ _LOG.log(Level.WARNING, "Couldn't create reply-to message", e);
+ }
+ finally
+ {
+
+ try
+ {
+ msg.getFolder().close(false);
+ }
+ catch (Exception e)
+ {
+
+ }
+
+ }
+ }
+
+ /**
+ * Given Address[], return a comma-separated string of the email addresses.
+ * @param replyToAddresses
+ * @return return a comma-separated string of the email addresses.
+ */
+ private String _getAddressString(Address[] replyToAddresses)
+ {
+
+ StringBuffer to = new StringBuffer(100);
+
+ for (int i = 0; i < replyToAddresses.length; i++)
+ {
+ if (i > 0)
+ to.append(",");
+ to.append(((InternetAddress)replyToAddresses[i]).getAddress());
+ }
+
+ return to.toString();
+
+ }
+
+ static private final Logger _LOG =
+ Logger.getLogger(ReplyToMessageBackingBean.class.getName());
+
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ReplyToMessageBackingBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ReplyToMessageBackingBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ShowMessageBackingBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ShowMessageBackingBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ShowMessageBackingBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ShowMessageBackingBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.email;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.mail.Folder;
+import javax.mail.MessagingException;
+import javax.mail.Part;
+
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.trinidad.context.RequestContext;
+
+/**
+ * Backing bean for the "show message" page. Provides support
+ * for downloading attachments, and hides the fact that the "message"
+ * comes in pageFlowScope from the actual page content.
+ */
+public class ShowMessageBackingBean
+{
+ public ShowMessageBackingBean()
+ {
+ // Code necessary because of:
+ // https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=22
+ RequestContext afContext = RequestContext.getCurrentInstance();
+ setMessage((MessageData) afContext.getPageFlowScope().get("message"));
+ }
+
+ public MessageData getMessage()
+ {
+ return _message;
+ }
+
+ public void setAttachmentToDownload(Part attachment)
+ {
+ _attachmentToDownload = attachment;
+ }
+
+
+ public Part getAttachmentToDownload()
+ {
+ return _attachmentToDownload;
+ }
+
+
+ public void setMessage(MessageData message)
+ {
+ try
+ {
+ _LOG.log(Level.INFO, "Displaying message {0}", message.getSubject());
+ }
+ catch (MessagingException me)
+ {
+ _LOG.log(Level.SEVERE, "Can't get the subject", me);
+ }
+
+ _message = message;
+ }
+
+ public String downloadAttachment() throws IOException, MessagingException
+ {
+ if (_attachmentToDownload == null)
+ {
+ _LOG.severe("No attachment available");
+ return null;
+ }
+
+ _message.getMessage().getFolder().open(Folder.READ_ONLY);
+
+ InputStream in = _attachmentToDownload.getInputStream();
+
+ FacesContext context = FacesContext.getCurrentInstance();
+ // Get the ServletResponse; nothing on ExternalContext is sufficient
+ ServletResponse response = (ServletResponse)
+ context.getExternalContext().getResponse();
+ response.setContentType(_attachmentToDownload.getContentType());
+
+ // If the size of the attachment is known, pass that on.
+ int size = _attachmentToDownload.getSize();
+ if (size >= 0)
+ {
+ response.setContentLength(size);
+ }
+
+ if (_LOG.isLoggable(Level.INFO))
+ _LOG.info("Downloading content+ [size=" + size +",contentType=" +
+ _attachmentToDownload.getContentType() + "]");
+
+ if (response instanceof HttpServletResponse)
+ {
+ String filename = _attachmentToDownload.getFileName();
+ if (filename != null)
+ {
+ ((HttpServletResponse) response).setHeader(
+ "Content-disposition",
+ "attachment; filename=\"" + filename + "\"");
+ }
+ }
+
+ // Pass the text along, 128K at a time.
+ try
+ {
+ OutputStream out = response.getOutputStream();
+ try
+ {
+ byte[] buffer = new byte[131072];
+ while (true)
+ {
+ int count = in.read(buffer);
+ if (count < 0)
+ break;
+
+ out.write(buffer, 0, count);
+ }
+ }
+ // Close up the response
+ finally
+ {
+ // And tell JSF that we handled everything
+ context.responseComplete();
+ out.close();
+ }
+ }
+ // And make sure the folder got closed
+ finally
+ {
+ _message.getMessage().getFolder().close(false);
+ }
+
+ return null;
+ }
+
+ private MessageData _message;
+ private Part _attachmentToDownload;
+
+ static private final Logger _LOG =
+ Logger.getLogger(ShowMessageBackingBean.class.getName());
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ShowMessageBackingBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/ShowMessageBackingBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/resource/EmailDemoBundle.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/resource/EmailDemoBundle.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/resource/EmailDemoBundle.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/resource/EmailDemoBundle.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.email.resource;
+
+import java.util.ListResourceBundle;
+
+public class EmailDemoBundle extends ListResourceBundle
+{
+ @Override
+ public Object[][] getContents()
+ {
+ return _CONTENTS;
+ }
+
+ static private final Object[][] _CONTENTS =
+ {
+ {"TODAY_MASK", "Today, {0}"},
+ {"EMAIL_LIST_ERROR", "Illegal email address."},
+ {"EMAIL_LIST_ERROR_detail", "{0} is not a legal email address."},
+ {"MESSAGE_SENT", "The message was sent successfully."},
+ {"COULD_NOT_DELETE", "Deletion failed."},
+ {"COULD_NOT_DELETE_detail", "The server returned an error: {0}."},
+ {"EMAIL_DEMO_TITLE", "Trinidad Email Demo"},
+
+
+ };
+}
+
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/resource/EmailDemoBundle.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/email/resource/EmailDemoBundle.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/DemoNavigationItem.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/DemoNavigationItem.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/DemoNavigationItem.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/DemoNavigationItem.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.nav;
+
+import java.io.Serializable;
+import java.util.List;
+
+
+public class DemoNavigationItem implements Serializable
+{
+ public DemoNavigationItem()
+ {}
+
+
+ public void setLabel(String label)
+ {
+ _label = label;
+ }
+
+ public String getLabel()
+ {
+ return _label;
+ }
+
+ public void setOutcome(String outcome)
+ {
+ _outcome = outcome;
+ }
+
+ public String getOutcome()
+ {
+ return _outcome;
+ }
+
+ public void setViewId(String viewId)
+ {
+ _viewId = viewId;
+ }
+
+ public String getViewId()
+ {
+ return _viewId;
+ }
+
+ // calling this 'ico' instead of 'icon' due to tree bug
+ public void setIco(String icon)
+ {
+ _icon = icon;
+ }
+
+ // calling this 'ico' instead of 'icon' due to tree bug
+ public String getIco()
+ {
+ return _icon;
+ }
+
+
+ public void setDestination(String destination)
+ {
+ _destination = destination;
+ }
+
+ public String getDestination()
+ {
+ return _destination;
+ }
+
+ public List<?> getChildren()
+ {
+ return _children;
+ }
+
+ public void setChildren(List<?> children)
+ {
+ _children = children;
+ }
+
+
+
+
+ private String _label = null;
+ private String _outcome = null;
+ private String _viewId = null;
+ private String _destination = null;
+ private String _icon = null;
+ private List<?> _children = null;
+
+
+
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/DemoNavigationItem.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/DemoNavigationItem.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/MenuModelAdapter.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/MenuModelAdapter.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/MenuModelAdapter.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/MenuModelAdapter.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.nav;
+
+import java.util.List;
+
+import org.apache.myfaces.trinidad.model.ViewIdPropertyMenuModel;
+
+/**
+ * This class facilitates calling ViewIdPropertyMenuModel.addViewId via
+ * an "aliasList".
+ */
+public class MenuModelAdapter implements java.io.Serializable
+{
+ public MenuModelAdapter()
+ {
+ }
+
+ private ViewIdPropertyMenuModel _model = null;
+ private List<Object> _aliasList = null;
+ private boolean _aliasListAdded = false;
+
+ /**
+ *
+ * @param model an instance of ViewIdPropertyMenuModel
+ */
+ public void setModel(ViewIdPropertyMenuModel model)
+ {
+ _model = model;
+ _aliasListAdded = false;
+
+ }
+
+ public ViewIdPropertyMenuModel getModel()
+ {
+ if (_model != null && !_aliasListAdded)
+ {
+ _aliasListAdded = true;
+ if(_aliasList != null && !_aliasList.isEmpty())
+ {
+ int size = _aliasList.size();
+ if (size % 2 == 1)
+ size = size - 1;
+
+ for ( int i = 0; i < size; i=i+2)
+ {
+ _model.addViewId(_aliasList.get(i).toString(),
+ _aliasList.get(i+1).toString());
+ }
+ }
+ }
+ return _model;
+ }
+
+ public List<Object> getAliasList()
+ {
+ return _aliasList;
+ }
+
+ /**
+ * aliasList is just a list of viewId strings grouped into pairs.
+ * We iterate over the list like so:
+ * ViewIdPropertyMenuModel.addViewId(aliasList.get(i), aliasList.get(i+1))
+ */
+ public void setAliasList(List<Object> aliasList)
+ {
+ _aliasList = aliasList;
+ }
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/MenuModelAdapter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/nav/MenuModelAdapter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/resource/SkinBundle.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/resource/SkinBundle.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/resource/SkinBundle.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/resource/SkinBundle.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.resource;
+
+import java.util.ListResourceBundle;
+
+public class SkinBundle extends ListResourceBundle
+{
+ @Override
+ public Object[][] getContents()
+ {
+ return _CONTENTS;
+ }
+
+ static private final Object[][] _CONTENTS =
+ {
+ {"af_tableSelectMany.SELECT_COLUMN_HEADER", "Select A Lot"},
+ {"af_tableSelectOne.SELECT_COLUMN_HEADER", "Select Just One"},
+ };
+}
+
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/resource/SkinBundle.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/resource/SkinBundle.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidator.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidator.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidator.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.survey;
+
+import javax.faces.component.StateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.application.FacesMessage;
+import javax.faces.validator.Validator;
+
+public class AnswerValidator implements Validator, StateHolder
+{
+
+ public void setQuestionIndex(String index)
+ {
+ _questionIndex = index;
+ }
+
+ public String getQuestionIndex()
+ {
+ return _questionIndex;
+ }
+
+ public void validate(FacesContext context, UIComponent component, Object value) {
+
+ String userResponse = (String.valueOf(value)).toUpperCase();
+ String correctResponse = lookupAnswer().toUpperCase();
+
+ if(!userResponse.equals(correctResponse))
+ {
+ FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ "Incorrect Response",
+ lookupCorrectAnswerMsg());
+
+ context.addMessage(component.getClientId(context), msg);
+ }
+ else
+ {
+ FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,
+ "Correct Response",
+ "CORRECT!");
+ context.addMessage(component.getClientId(context), msg);
+ }
+ } // end validate()
+
+ // -------------------------------------------------------- Private Methods
+ private String lookupCorrectAnswerMsg()
+ {
+ // based on the current question index
+ // get the answer message from the appropriate question bean
+
+ if (_questionIndex.equals("0"))
+ {
+ return _surveyBean.getQ0().getCorrectAnswerMessage();
+ }
+ else if (_questionIndex.equals("1"))
+ {
+ return _surveyBean.getQ1().getCorrectAnswerMessage();
+ }
+ else if (_questionIndex.equals("2"))
+ {
+ return _surveyBean.getQ2().getCorrectAnswerMessage();
+ }
+ else if (_questionIndex.equals("3A"))
+ {
+ return String.valueOf(_surveyBean.getQ3().getCorrectAnswerMessage(0));
+ }
+ else if (_questionIndex.equals("3B"))
+ {
+ return String.valueOf(_surveyBean.getQ3().getCorrectAnswerMessage(1));
+ }
+ else if (_questionIndex.equals("3C"))
+ {
+ return String.valueOf(_surveyBean.getQ3().getCorrectAnswerMessage(2));
+ }
+ else if (_questionIndex.equals("3D"))
+ {
+ return String.valueOf(_surveyBean.getQ3().getCorrectAnswerMessage(3));
+ }
+ else if (_questionIndex.equals("4"))
+ {
+ return _surveyBean.getQ4().getCorrectAnswerMessage();
+ }
+ else
+ {
+ return ""; // error: passed in incorrect questionindex
+ }
+ } // end getCorrectAnswerMsg()
+
+ private String lookupAnswer()
+ {
+
+ // based on the current question index
+ // get the answer string from the appropriate question bean
+
+ if (_questionIndex.equals("0"))
+ {
+ return String.valueOf(_surveyBean.getQ0().getCorrectIndex());
+ }
+ else if (_questionIndex.equals("1"))
+ {
+ return _surveyBean.getQ1().getCorrectAnswer();
+ }
+ else if (_questionIndex.equals("2"))
+ {
+ return String.valueOf(_surveyBean.getQ2().getCorrectIndex());
+ }
+ else if (_questionIndex.equals("3A"))
+ {
+ return String.valueOf(_surveyBean.getQ3().getCheckbox0());
+ }
+ else if (_questionIndex.equals("3B"))
+ {
+ return String.valueOf(_surveyBean.getQ3().getCheckbox1());
+ }
+ else if (_questionIndex.equals("3C"))
+ {
+ return String.valueOf(_surveyBean.getQ3().getCheckbox2());
+ }
+ else if (_questionIndex.equals("3D"))
+ {
+ return String.valueOf(_surveyBean.getQ3().getCheckbox3());
+ }
+ else if (_questionIndex.equals("4"))
+ {
+ return String.valueOf(_surveyBean.getQ4().getCorrectIndex());
+ }
+ else
+ {
+ return ""; // error: passed in incorrect questionindex
+ }
+ } // end loookupAnswer()
+
+
+ //------------------------------------------------- StateHolder Methods
+
+ public Object saveState(FacesContext context)
+ {
+ Object values[] = new Object[1];
+ values[0] = _questionIndex;
+ return (values);
+ }
+
+
+ public void restoreState(FacesContext context, Object state)
+ {
+ Object values[] = (Object[]) state;
+ _questionIndex = (String) values[0];
+ }
+
+ public boolean isTransient()
+ {
+ return (_transientValue);
+ }
+
+ public void setTransient(boolean transientValue)
+ {
+ _transientValue = transientValue;
+ }
+
+
+
+ private String _questionIndex = "";
+ private SurveyBean _surveyBean = new SurveyBean();
+ private boolean _transientValue = false;
+
+} // end class AnswerValidator
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidator.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidatorTag.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidatorTag.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidatorTag.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidatorTag.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.survey;
+
+import javax.faces.webapp.ValidatorTag;
+import javax.faces.validator.Validator;
+import javax.servlet.jsp.JspException;
+
+public class AnswerValidatorTag extends ValidatorTag
+{
+
+ private String _questionIndex = "";
+ private final String ID = "survey answer validator";
+
+ public AnswerValidatorTag()
+ {
+ super();
+ super.setValidatorId(ID);
+ }
+
+ public void setQuestionIndex(String index)
+ {
+ _questionIndex = index;
+ }
+
+ public String getQuestionIndex()
+ {
+ return _questionIndex;
+ }
+
+ @Override
+ protected Validator createValidator() throws JspException {
+
+ AnswerValidator validator = (AnswerValidator)super.createValidator();
+ validator.setQuestionIndex(_questionIndex);
+
+ //System.out.println("just instantiated " + validator + " with: " + validator.getQuestionIndex());
+ return validator;
+
+ }
+
+
+} // end AnswerValidatorTag
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidatorTag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/AnswerValidatorTag.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/CheckboxQuestionBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/CheckboxQuestionBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/CheckboxQuestionBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/CheckboxQuestionBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,253 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.survey;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+/***
+ * class CheckboxQuestionBean
+ *
+ * This bean represents a single multiple-answer checkbox style question.
+ * It has fields for the question prompt, a list of choices, and all the
+ * correct checkboxes in the answer.
+ *
+ * [Note: Due to a lack of support for dynamically iterating through data in
+ * early releases of Trinidad, this bean contains special get methods that help
+ * iterate through the list of choices for printing out on the screen.]
+ *
+ * ***/
+
+public class CheckboxQuestionBean implements QuestionBean, Serializable
+{
+
+ /** The question prompt as a String object */
+ private String _prompt;
+
+ /** arbitrary number of possible answer choices (Strings) */
+ private ArrayList<String> _choices;
+
+
+ /** An integer that represents the correct checkbox choices */
+ private int _correctAnswer;
+
+ /** the booleans to represent the correct choices */
+ private boolean _checkbox0;
+ private boolean _checkbox1;
+ private boolean _checkbox2;
+ private boolean _checkbox3;
+
+ // a debug flag
+ private boolean debug = false;
+
+
+
+ /**
+ * Class constructor (no arguments).
+ */
+ public CheckboxQuestionBean()
+ {
+ }
+
+ /**
+ * Class constructor.
+ */
+ public CheckboxQuestionBean(
+ String prompt,
+ ArrayList<String> choices,
+ int correctAnswer,
+ boolean checkbox0,
+ boolean checkbox1,
+ boolean checkbox2,
+ boolean checkbox3)
+ {
+ _prompt = prompt;
+ _choices = choices;
+ _correctAnswer = correctAnswer;
+
+ _checkbox0 = checkbox0;
+ _checkbox1 = checkbox1;
+ _checkbox2 = checkbox2;
+ _checkbox3 = checkbox3;
+ }
+
+
+ /*** Accessors ***/
+
+ /**
+ * returns the question prompt.
+ *
+ * @return the question prompt
+ */
+ public String getPrompt()
+ {
+ // after getting the prompt, we want to initialize the iterator index
+ // for the answers
+ return _prompt;
+ }
+
+
+ public String getText1()
+ {
+ return _choices.get(0);
+ }
+
+ public String getText2()
+ {
+ return _choices.get(1);
+ }
+
+ public String getText3()
+ {
+ return _choices.get(2);
+ }
+
+ public String getText4()
+ {
+ return _choices.get(3);
+ }
+
+ /*** util functions ***/
+
+
+ /**
+ * typical toString method
+ *
+ * @return a String representation of a QuestionBean
+ */
+ @Override
+ public String toString()
+ {
+ String str = _prompt + "; " + _choices.toString();
+ return str;
+ }
+
+
+ /**
+ * returns a message describing the correct answer choices.
+ *
+ * @return a message describing the correct answer choices
+ */
+ public String getCorrectAnswerMessage()
+ {
+ String message = "The correct answer is: ";
+ String bitMap = Integer.toBinaryString(_correctAnswer);
+ int i,j;
+ boolean atLeastOneSelected = false;
+
+ // since toBinaryString() library method does not put in leading zeros,
+ // we need to make sure bitMap is as long as NUMBER_OF_ANSWER_CHOICES
+ while (bitMap.length() < SurveyBean.NUMBER_OF_ANSWER_CHOICES)
+ {
+ // prepend leading zeros
+ bitMap = '0' + bitMap;
+ }
+
+ // beginning with the NUMBER_OF_ANSWER_CHOICES-th bit from the right
+ // check until the end of the string
+ for (i=bitMap.length()-SurveyBean.NUMBER_OF_ANSWER_CHOICES, j=0;
+ i<bitMap.length() && j<_choices.size();
+ i++, j++)
+ {
+ // if the considered bit is 1
+ if (debug)
+ {
+ System.out.println("in cbqb, bitMap is: " + bitMap + ", getting " + i + "th char, which is: " + bitMap.charAt(i));
+ }
+ if( bitMap.charAt(i) == '1')
+ {
+ // it's a correct solution
+ message = message + _choices.get(j) + " & ";
+ atLeastOneSelected = true;
+ }
+ } //end for loop
+
+ if (atLeastOneSelected)
+ {
+ // remove extra " & " from end of message
+ message = message.substring(0, message.length()-3);
+ }
+
+ return message;
+ }
+
+
+ /**
+ * Returns a message describing the correct answer for a particular checkbox.
+ *
+ * @param checkboxNum the index of the checkbox
+ *
+ * @return a message describing the correct answer choices
+ */
+ public String getCorrectAnswerMessage(int checkboxNum)
+ {
+ String message = "INCORRECT";
+// String message = "The correct answer is: ";
+//
+// switch (checkboxNum)
+// {
+// case(0):
+// message = message + getCheckbox0();
+// break;
+// case(1):
+// message = message + getCheckbox1();
+// break;
+// case(2):
+// message = message + getCheckbox2();
+// break;
+// case(3):
+// message = message + getCheckbox3();
+// break;
+// }
+
+ return message;
+ }
+
+/*** IDE generated accessors ***/
+
+ public boolean getCheckbox0()
+ {
+ return _checkbox0;
+ }
+
+
+ public boolean getCheckbox1()
+ {
+ return _checkbox1;
+ }
+
+
+ public boolean getCheckbox2()
+ {
+ return _checkbox2;
+ }
+
+
+ public boolean getCheckbox3()
+ {
+ return _checkbox3;
+ }
+
+
+ public int getCorrectAnswer()
+ {
+ return _correctAnswer;
+ }
+
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/CheckboxQuestionBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/CheckboxQuestionBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/MultChoiceQuestionBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/MultChoiceQuestionBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/MultChoiceQuestionBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/MultChoiceQuestionBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.survey;
+
+import java.io.Serializable;
+import java.util.List;
+
+/***
+ * class MultChoiceQuestionBean
+ *
+ * This bean represents a single multiple choice questions. It has fields for
+ * the question prompt, a list of choices, and the correct answer.
+ *
+ ***/
+
+
+public class MultChoiceQuestionBean implements QuestionBean, Serializable
+{
+
+ /** Constructors **/
+
+ /**
+ * Class constructor (no arguments).
+ */
+ public MultChoiceQuestionBean()
+ {
+ }
+
+ /**
+ * Class constructor.
+ */
+ public MultChoiceQuestionBean(String prompt,
+ List<String> choices,
+ int correctIndex)
+ {
+ _prompt = prompt;
+ _choices = choices;
+ _correctIndex = correctIndex;
+ }
+
+
+ /*** Accessors ***/
+ /**
+ * returns the question prompt.
+ *
+ * @return the question prompt
+ */
+ public String getPrompt()
+ {
+ return _prompt;
+ }
+
+
+ /**
+ * returns the list of answer strings.
+ */
+ public List<String> getAnswerStrings()
+ {
+ return _choices;
+ }
+
+
+ /**
+ * typical toString method
+ *
+ * @return a String representation of a MultChoiceQuestionBean
+ */
+ @Override
+ public String toString()
+ {
+ String str = "[" + _prompt + "; " + _choices.toString() + "]";
+ return str;
+ }
+
+
+
+ /**
+ * returns a message describing the correct answer choices.
+ *
+ * @return a message describing the correct answer choices
+ */
+ public String getCorrectAnswerMessage()
+ {
+ return "The correct answer is: " + _choices.get(_correctIndex);
+ }
+
+ /**
+ * returns the index of the correct answer
+ *
+ * @return the index of the correct answer
+ */
+ public int getCorrectIndex()
+ {
+ return _correctIndex;
+ }
+
+ /* The question as a String object */
+ private String _prompt;
+
+ /* arbitrary number of possible answer choices (Strings) */
+ private List<String> _choices;
+
+ /* The index of the correct answer */
+ private int _correctIndex;
+
+
+} //end QuestionBean
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/MultChoiceQuestionBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/MultChoiceQuestionBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/QuestionBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/QuestionBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/QuestionBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/QuestionBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.survey;
+
+/**
+ * @author Simon Lessard, Fujitsu Consulting
+ */
+public interface QuestionBean
+{
+ /**
+ * returns a message describing the correct answer choices.
+ *
+ * @return a message describing the correct answer choices
+ */
+ public String getCorrectAnswerMessage();
+
+ /**
+ * returns the question prompt.
+ *
+ * @return the question prompt
+ */
+ public String getPrompt();
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/QuestionBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/QuestionBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,582 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.survey;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/***
+ * class SurveyBean
+ *
+ * This is the main backing bean for the Survey Demo project.
+ * It represents a multiple-choice survey. It contains state about
+ * the list of questions to ask in the survey and the user's responses to
+ * these questions. It also has methods that help with application
+ * navigation.
+ *
+ * ***/
+
+public class SurveyBean extends Object implements Serializable
+{
+
+ /** A List of QuestionBean objects */
+ private ArrayList<QuestionBean> _questions = new ArrayList<QuestionBean>();
+
+ /** The index of the (current) question displayed */
+ private int _currentIndex;
+
+ /** A List of QuestionBean objects */
+ private ArrayList<String> _userAnswers = new ArrayList<String>();
+
+ /** number of choices */
+ static final int NUMBER_OF_ANSWER_CHOICES = 4;
+
+ /** debug flag */
+ private boolean debug = false;
+
+ /** beans for each question in the survey */
+ MultChoiceQuestionBean _q0;
+
+ TextQuestionBean _q1; // insert a text field question here
+
+ MultChoiceQuestionBean _q2;
+
+ CheckboxQuestionBean _q3; // this is a checkbox question
+
+ MultChoiceQuestionBean _q4;
+
+ /** a String for each user response in the survey */
+ String _a0; //response for a multiple choice (normal) question
+ String _a1; //response for TextQuestion
+ String _a2; //response for a multiple choice (normal) question
+
+ String _a3; //special case: responses for CheckboxQuestion
+ boolean _a30; // these booleans represent the user's choices for the
+ boolean _a31; // checkbox question
+ boolean _a32;
+ boolean _a33;
+
+ String _a4; //response for a multiple choice (normal) question
+
+ /** A List of SurveyPage objects for use with the processTrain component */
+ private List<SurveyPage> _pages;
+ /**
+ * Class constructor (no arguments).
+ */
+ public SurveyBean()
+ {
+ init("survey.bundles.california");
+ }
+
+ /**
+ * Class constructor.
+ *
+ * @param bundleName the path of a bundle file
+ */
+ public SurveyBean(String bundleName)
+ {
+ init(bundleName);
+ }
+
+ /**
+ * Initializes survey application.
+ *
+ * @param bundleName the path of a bundle file
+ */
+ private void init(String bundleName)
+ {
+ //TODO
+ /*FacesContext context = FacesContext.getCurrentInstance();
+ * ResourceBundle data = null;
+ *data = ResourceBundle.getBundle(bundleName);
+ */
+
+ // load in the questions
+ loadQuestions();
+
+ // initialize other state for each survey session
+ initSurveyState();
+ }
+
+ /**
+ * Loads the questions into survey application.
+ */
+ private void loadQuestions()
+ {
+ // notice there are redundant data structures
+ // the QuestionBeans are both stored in instance fields, which are linked
+ // together in an Array List
+
+ // question 0, for surveyPage1
+ ArrayList<String> choices = new ArrayList<String>();
+ choices.add("A. Loading zone for freight or passengers.");
+ choices.add("B. Loading zone for passengers or mail only.");
+ choices.add("C. Loading zone for freight only.");
+ choices.add("D. They ran out of red paint.");
+ _q0 = new MultChoiceQuestionBean("A white painted curb means ", choices, 1);
+ _questions.add(_q0);
+
+ // question 1, for surveyPage2
+ _q1 = new TextQuestionBean("The color of a typical stop sign is ", "RED");
+ _questions.add(_q1);
+
+ // question 2, for surveyPage3
+ ArrayList<String> choices2 = new ArrayList<String>();
+ choices2.add("A. If the shoulder is wide enough to accommodate your vehicle.");
+ choices2.add("B. If the vehicle ahead of you is turning left.");
+ choices2.add("C. Under no circumstances.");
+ choices2.add("D. If you are driving a Hummer.");
+ _q2 = new MultChoiceQuestionBean("You may drive off of the paved roadway to pass another vehicle ", choices2, 2);
+ _questions.add(_q2);
+
+ // question 3, for surveyPage4
+ ArrayList<String> choices3 = new ArrayList<String>();
+ choices3.add("A. In a crosswalk.");
+ choices3.add("B. Within 10 feet of a fire hydrant.");
+ choices3.add("C. Next to a red painted curb.");
+ choices3.add("D. If you are driving a Hummer.");
+ _q3 = new CheckboxQuestionBean("It is illegal to park your vehicle (check all that apply) ", choices3, 14, true, true, true, false);
+ _questions.add(_q3);
+
+ // question 4, for surveyPage5
+ ArrayList<String> choices4 = new ArrayList<String>();
+ choices4.add("A. Stop, then proceed when you think all of the children have exited the bus.");
+ choices4.add("B. Slow to 25 MPH and pass cautiously.");
+ choices4.add("C. Stop as long as the red lights are flashing. ");
+ choices4.add("D. Grab your sack lunch and jump onboard so you're not late for homeroom like yesterday.");
+ _q4 = new MultChoiceQuestionBean("A school bus ahead of you in your lane is stopped with red lights flashing. You should ", choices4, 2);
+ _questions.add(_q4);
+
+ if (debug)
+ {
+ System.out.println("init() printing out the list of questions:\n" + _questions);
+ System.out.println("length of list of questions: " + _questions.size());
+ }
+
+ } //end loadQuestions()
+
+ /**
+ * Initializes various survey state. Should be called for each new sesion
+ * through the survey.
+ */
+ public void initSurveyState()
+ {
+ /* start with the first(0th) question */
+ _currentIndex = 0;
+
+ /* holders for user responses are initialized to "no selection" */
+ _a0 = null;
+ _a1 = ""; //response for a TextQuestion
+ _a2 = null;
+
+ _a3 = "0"; //response for a CheckboxQuestion
+ _a30 = false;
+ _a31 = false;
+ _a32 = false;
+ _a33 = false;
+
+ _a4 = null;
+
+ /* add initialized responses into array */
+ _userAnswers.add(_a0);
+ _userAnswers.add(_a1);
+ _userAnswers.add(_a2);
+ _userAnswers.add(_a3);
+ _userAnswers.add(_a4);
+
+ } //end initSurveyState()
+
+
+
+ /*** navigation methods ***/
+
+ /**
+ * advances the survey to the next question.
+ *
+ * @return a String object, "next"
+ */
+ public String next()
+ {
+ advanceToNextQuestion();
+ if (debug)
+ {
+ System.out.println("the currentIndex is:" + _currentIndex);
+ System.out.println("next() is finished");
+ }
+
+ return "next";
+ }
+ /**
+ * moves the survey to the previous question.
+ *
+ * @return a String object, "back"
+ */
+ public String back()
+ {
+ goToPreviousQuestion();
+ if (debug)
+ {
+ System.out.println("the currentIndex is:" + _currentIndex);
+ System.out.println("next() is finished");
+ }
+ return "back";
+ }
+
+ /**
+ * called when the first run through the survey is completed.
+ *
+ * @return a String object, "finish"
+ */
+ public String finish()
+ {
+ return "finish";
+ }
+
+ /**
+ * called to advance to the results page.
+ *
+ * @return a String object, "check"
+ */
+ public String check()
+ {
+ return "check";
+ }
+
+ /**
+ * called to go back to beginning of survey and clears all previous responses.
+ *
+ * @return a String object, "start"
+ */
+ public String start()
+ {
+ initSurveyState();
+ return "start";
+ }
+
+
+ /*** Accessors ***/
+
+ /**
+ * advances the survey to the next question.
+ *
+ * @return a String object representing the number of questions in the survey
+ */
+ public String getNumQuestions()
+ {
+ return ( String.valueOf(_questions.size()) );
+ }
+
+ /**
+ * determines whether we have reached the end of the survey
+ *
+ * @return a boolean that is true if we have reached the end of the survey
+ */
+ public boolean getDone()
+ {
+ // when we've reached the last question in the list
+ return ( _currentIndex == _questions.size()-1 );
+ }
+
+ /**
+ * determines the number of the current question in the survey.
+ *
+ * @return a String that represents the number of the current question
+ */
+ public String getCurrentQuestionNumber()
+ {
+ // the question number is index+1 since the index starts at 0
+ int i = _currentIndex + 1 ;
+ return String.valueOf(i);
+ }
+
+ /*** Utils ***/
+
+
+ /**
+ * increments question index to next question.
+ */
+ public void advanceToNextQuestion()
+ {
+ _currentIndex++;
+ }
+
+ /**
+ * decrements question index to previous question.
+ */
+ public void goToPreviousQuestion()
+ {
+ _currentIndex--;
+ }
+
+ /**
+ * a hack to return the String "error" inside a binding using EL
+ *
+ * @return the literal String, "error"
+ */
+ public String getError()
+ {
+ return "error";
+ }
+
+ /**
+ * a hack to return the String "none" inside a binding using EL
+ *
+ * @return the literal String, "none"
+ */
+ public String getNone()
+ // a hack to return a String inside a binding using EL
+ {
+ return "none";
+ }
+
+ /**
+ * a hack to return the empty String "" inside a binding using EL
+ *
+ * @return the empty String, ""
+ */
+ public String getEmptyString()
+ // a hack to return a String inside a binding using EL
+ {
+ return "";
+ }
+
+ /**
+ * a hack to return the String "correct" inside a binding using EL
+ *
+ * @return the literal String, "correct"
+ */
+ public String getCorrect()
+ // a hack to return a String inside a binding using EL
+ {
+ return "correct";
+ }
+
+
+ /**
+ * a hack to return the String "incorrect" inside a binding using EL
+ *
+ * @return the literal String, "incorrect"
+ */
+ public String getIncorrect()
+ // a hack to return a String inside a binding using EL
+ {
+ return "incorrect";
+ }
+
+
+ /**
+ * stores whether a checkbox is checked. This app uses a simple bit mapping
+ * to represent the "checked" state of the checkboxes. For example, assume the
+ * number of checkboxes is 4. If all four checkboxes were checked, then
+ * the representation is "1111", which is equivalent to the number 15 in
+ * base 10. Likewise, if only the first and third checkboxes are selected,
+ * then the representation is "1010", which is the number 10 in base 10.
+ * This method turns the bits on/off according to whether the "index"-th
+ * checkbox is "checked".
+ *
+ * @param checked whether this checkbox is checked
+ * @param index the index of the checkbox
+ * @param storageDestination the String of the integer representation of the selection state
+ *
+ * @return a String that represents the current selections (an integer)
+ */
+ private String storeCheckSelection (boolean checked, int index,
+ String storageDestination)
+ {
+ // extract an integer from the string
+ int storageInt = Integer.parseInt(storageDestination);
+ if (checked)
+ {
+ // if checked, then turn on index-th bit
+ storageInt = storageInt | 1<<(NUMBER_OF_ANSWER_CHOICES-index-1);
+ }
+ else
+ {
+ // if not checked, then turn off index-th bit
+ storageInt = storageInt & ~(1<<(NUMBER_OF_ANSWER_CHOICES-index-1));
+ }
+
+ if (debug)
+ {
+ System.out.println("checked is: " + checked + ", index is: " + index + ", storageInt is:" + storageInt);
+ }
+
+ // store the integer as a string
+ return String.valueOf(storageInt);
+
+ } // end storeCheckSelection
+
+
+ /*** IDE generated accessors ***/
+
+ public MultChoiceQuestionBean getQ0()
+ {
+ return _q0;
+ }
+
+ public TextQuestionBean getQ1()
+ {
+ return _q1;
+ }
+
+ public MultChoiceQuestionBean getQ2()
+ {
+ return _q2;
+ }
+
+ public CheckboxQuestionBean getQ3()
+ {
+ return _q3;
+ }
+
+ public MultChoiceQuestionBean getQ4()
+ {
+ return _q4;
+ }
+
+
+ public void setA0(String a0)
+ {
+ _a0 = a0;
+ }
+
+
+ public String getA0()
+ {
+ return _a0;
+ }
+
+
+ public void setA1(String a1)
+ {
+ // special set method to trim and convert response from text input
+ _a1 = a1.trim().toUpperCase();
+ }
+
+
+ public String getA1()
+ {
+ return _a1;
+ }
+
+
+ public void setA2(String a2)
+ {
+ _a2 = a2;
+ }
+
+
+ public String getA2()
+ {
+ return _a2;
+ }
+
+
+ public void setA3(String a3)
+ {
+ _a3 = a3;
+ }
+
+
+ public String getA3()
+ {
+ return _a3;
+ }
+
+
+ public void setA4(String a4)
+ {
+ _a4 = a4;
+ }
+
+
+ public String getA4()
+ {
+ return _a4;
+ }
+
+
+ public void setA30(boolean a30)
+ {
+ _a30 = a30;
+ _a3 = storeCheckSelection(a30, 0, _a3);
+
+ }
+
+
+ public boolean getA30()
+ {
+ return _a30;
+ }
+
+
+ public void setA31(boolean a31)
+ {
+ _a31 = a31;
+ _a3 = storeCheckSelection(a31, 1, _a3);
+ }
+
+
+ public boolean getA31()
+ {
+ return _a31;
+ }
+
+
+ public void setA32(boolean a32)
+ {
+ _a32 = a32;
+ _a3 = storeCheckSelection(a32, 2, _a3);
+ }
+
+
+ public boolean getA32()
+ {
+ return _a32;
+ }
+
+
+ public void setA33(boolean a33)
+ {
+ _a33 = a33;
+ _a3 = storeCheckSelection(a33, 3, _a3);
+ }
+
+
+ public boolean getA33()
+ {
+ return _a33;
+ }
+
+ public List<SurveyPage> getPages()
+ {
+ if (_pages == null)
+ {
+ _pages = new ArrayList<SurveyPage>();
+ _pages.add(new SurveyPage("/surveydemo/surveyPage1.jspx", "Step1"));
+ _pages.add(new SurveyPage("/surveydemo/surveyPage2.jspx", "Step2"));
+ _pages.add(new SurveyPage("/surveydemo/surveyPage3.jspx", "Step3"));
+ _pages.add(new SurveyPage("/surveydemo/surveyPage4.jspx", "Step4"));
+ _pages.add(new SurveyPage("/surveydemo/surveyPage5.jspx", "Step5"));
+ }
+ return _pages;
+ }
+
+} //end SurveyBean class
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyPage.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyPage.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyPage.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyPage.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.survey;
+
+public class SurveyPage implements java.io.Serializable
+{
+ public SurveyPage()
+ {
+ }
+
+ public SurveyPage(String viewId, String label)
+ {
+ setViewId(viewId);
+ setLabel(label);
+ setDisabled(false);
+ }
+
+ public void setViewId(String viewId)
+ {
+ _viewId = viewId;
+ }
+
+
+ public String getViewId()
+ {
+ return _viewId;
+ }
+
+ public void setOutcome(String outcome)
+ {
+ _outcome = outcome;
+ }
+
+
+ public String getOutcome()
+ {
+ return _outcome;
+ }
+
+ public void setLabel(String label)
+ {
+ _label = label;
+ }
+
+
+ public String getLabel()
+ {
+ return _label;
+ }
+
+
+ public void setDisabled(boolean disabled)
+ {
+ _disabled = disabled;
+ }
+
+
+ public boolean isDisabled()
+ {
+ return _disabled;
+ }
+
+ private String _viewId;
+ private String _outcome;
+ private String _label;
+ private boolean _disabled;
+
+
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyPage.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/SurveyPage.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/TextQuestionBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/TextQuestionBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/TextQuestionBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/TextQuestionBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.survey;
+
+import java.io.Serializable;
+
+/***
+ * class TextQuestionBean
+ *
+ * This bean represents a single question with a text field as its answer form.
+ * It has fields for the question prompt and the correct answer.
+ *
+ * ***/
+
+
+public class TextQuestionBean implements QuestionBean, Serializable
+{
+ /** The question as a String object. */
+ private String _prompt;
+
+ /** The correct answer. */
+ private String _correctAnswer;
+
+ /**
+ * Class constructor (no arguments).
+ */
+ public TextQuestionBean()
+ {
+ _prompt = "";
+ _correctAnswer = "";
+ }
+
+ /**
+ * Class constructor.
+ */
+ public TextQuestionBean(String prompt, String correctAnswer)
+ {
+ _prompt = prompt;
+ _correctAnswer = correctAnswer;
+ }
+
+
+ /*** JDev generated accessors ***/
+
+ public void setPrompt(String prompt)
+ {
+ _prompt = prompt;
+ }
+
+ public String getPrompt()
+ {
+ return _prompt;
+ }
+
+ public String getCorrectAnswer()
+ {
+ return _correctAnswer;
+ }
+
+ public String getCorrectAnswerMessage()
+ {
+ return "The correct answer is: " + _correctAnswer;
+ }
+
+
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/TextQuestionBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/survey/TextQuestionBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/table/DynamicModel.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/table/DynamicModel.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/table/DynamicModel.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/table/DynamicModel.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.table;
+
+import java.io.Serializable;
+import javax.faces.model.DataModel;
+
+public class DynamicModel extends DataModel implements Serializable
+{
+ public DynamicModel()
+ {
+ }
+
+ @Override
+ public int getRowCount()
+ {
+ return _rowCount;
+ }
+
+ public void setRowCount(int count)
+ {
+ if ((count >= -1) && (count <= 400))
+ _rowCount = count;
+ }
+
+ public int getActualRowCount()
+ {
+ return _length;
+ }
+
+ public void setActualRowCount(int count)
+ {
+ if ((count >= 0) && (count <= 400))
+ _length = count;
+ }
+
+ public int getBlockSize()
+ {
+ return _blockSize;
+ }
+
+ public void setBlockSize(int blockSize)
+ {
+ if (blockSize >= 0)
+ {
+ _blockSize = blockSize;
+ }
+ }
+
+ @Override
+ public boolean isRowAvailable()
+ {
+ return (_index >= 0) && (_index < _length);
+ }
+
+ @Override
+ public Object getRowData()
+ {
+ return isRowAvailable() ? new Integer(_index) : null;
+ }
+
+ @Override
+ public int getRowIndex()
+ {
+ return _index;
+ }
+
+ @Override
+ public void setRowIndex(int index)
+ {
+ _index = index;
+ }
+
+ @Override
+ public Object getWrappedData()
+ {
+ return this;
+ }
+
+ @Override
+ public void setWrappedData(Object obj)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ private int _rowCount = -1;
+ private int _length = 25;
+ private int _index = -1;
+ private int _blockSize = 10;
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/table/DynamicModel.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/table/DynamicModel.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/table/TableBuilder.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/table/TableBuilder.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/table/TableBuilder.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/table/TableBuilder.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.table;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+public class TableBuilder implements java.io.Serializable
+{
+ @SuppressWarnings("unchecked")
+ public TableBuilder()
+ {
+ // no arg contructor needed for usage as managed-bean
+ _beanProps = Collections.EMPTY_LIST;
+ _data = Collections.EMPTY_LIST;
+ _result = null;
+ }
+
+ public void setBeanClass(String klass)
+ {
+ _beanClass = klass;
+ }
+
+ public void setBeanProperties(List<Object> props)
+ {
+ if (props == null)
+ throw new NullPointerException("beanProperties");
+ _beanProps = props;
+ }
+
+ public void setBeanData(List<?> data)
+ {
+ if (data == null)
+ throw new NullPointerException("beanData");
+ _data = data;
+ }
+
+ public List<?> getTableData()
+ throws ClassNotFoundException, IntrospectionException, InstantiationException,
+ IllegalAccessException, InvocationTargetException
+ {
+ if (_result == null)
+ {
+ _result = _getAsList();
+ }
+ return _result;
+ }
+
+ private List<Object> _getAsList()
+ throws ClassNotFoundException, IntrospectionException, InstantiationException,
+ IllegalAccessException, InvocationTargetException
+ {
+ if (_beanClass == null)
+ throw new NullPointerException("beanClass");
+
+ Class<?> beanClass = Class.forName(_beanClass);
+ _setPropertySetters(beanClass, _beanProps);
+ int sz = _beanProps.size();
+ List<Object> result = new ArrayList<Object>(sz);
+
+ Iterator<?> cells = _data.iterator();
+ while(cells.hasNext())
+ {
+ Object beanInstance = beanClass.newInstance();
+ for(int i=0; i<sz; i++)
+ {
+ Object value = cells.next();
+ Method setter = (Method) _beanProps.get(i);
+ Class<?> expectedType = setter.getParameterTypes()[0];
+ if (!expectedType.isAssignableFrom(value.getClass()))
+ {
+ value = _convert(value, expectedType);
+ }
+
+ setter.invoke(beanInstance, new Object[] {value});
+ }
+ result.add(beanInstance);
+ }
+ return result;
+ }
+
+ private Object _convert(Object instance, Class<?> expectedType)
+ {
+ if (Integer.TYPE == expectedType)
+ {
+ return new Integer(instance.toString());
+ }
+ throw new IllegalArgumentException("Could not convert instance:"+instance+
+ " of class:"+instance.getClass()+" into "+expectedType);
+ }
+
+ private void _setPropertySetters(Class<?> klass, List<Object> props)
+ throws IntrospectionException
+ {
+ BeanInfo beanInfo = Introspector.getBeanInfo(klass);
+ PropertyDescriptor[] descs = beanInfo.getPropertyDescriptors();
+ for(int i=0, sz=props.size(); i<sz; i++)
+ {
+ String name = (String)props.get(i);
+ PropertyDescriptor desc = _getDescriptor(descs, name);
+ if (desc == null)
+ {
+ throw new IllegalArgumentException("property:"+name+" not found on:"
+ +klass);
+ }
+ Method setter = desc.getWriteMethod();
+ if (setter == null)
+ {
+ throw new IllegalArgumentException("No way to set property:"+name+" on:"
+ +klass);
+ }
+ props.set(i, setter);
+ }
+ }
+
+ private PropertyDescriptor _getDescriptor(
+ PropertyDescriptor[] descs,
+ String name)
+ {
+ for(int i=0; i<descs.length; i++)
+ {
+ PropertyDescriptor desc = descs[i];
+ if (name.equals(desc.getName()))
+ return desc;
+ }
+ return null;
+ }
+
+ private String _beanClass = null;
+ // Transient as it contains java.lang.reflect.Method objects
+ private transient List<Object> _beanProps;
+ private List<?> _data;
+ private List<?> _result;
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/table/TableBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/table/TableBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tableDemos/EmployeeBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tableDemos/EmployeeBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tableDemos/EmployeeBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tableDemos/EmployeeBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.tableDemos;
+
+import java.io.Serializable;
+
+/**
+ * @author asghosh
+ */
+public class EmployeeBean implements Serializable
+{
+ private String data1;
+
+ private String data2;
+
+ private boolean _readOnly;
+
+ public EmployeeBean()
+ {
+ _readOnly = true;
+ }
+
+ public EmployeeBean(String data1, String data2)
+ {
+ setData1(data1);
+ setData2(data2);
+ _readOnly = true;
+ }
+
+ public EmployeeBean(String data1, String data2, boolean readOnly)
+ {
+ setData1(data1);
+ setData2(data2);
+ setReadOnly(readOnly);
+ }
+
+ /**
+ * @param _readOnly
+ * The _readOnly to set.
+ */
+ public void setReadOnly(boolean _readOnly)
+ {
+ this._readOnly = _readOnly;
+ }
+
+ /**
+ * @return Returns the _readOnly.
+ */
+ public boolean getReadOnly()
+ {
+ return _readOnly;
+ }
+
+ /**
+ * @param data1
+ * The data1 to set.
+ */
+ public void setData1(String data1)
+ {
+ this.data1 = data1;
+ }
+
+ /**
+ * @return Returns the data1.
+ */
+ public String getData1()
+ {
+ return data1;
+ }
+
+ /**
+ * @param data2
+ * The data2 to set.
+ */
+ public void setData2(String data2)
+ {
+ this.data2 = data2;
+ }
+
+ /**
+ * @return Returns the data2.
+ */
+ public String getData2()
+ {
+ return data2;
+ }
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tableDemos/EmployeeBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tableDemos/EmployeeBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tableDemos/EmployeeTableBean.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tableDemos/EmployeeTableBean.java?view=auto&rev=523607
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tableDemos/EmployeeTableBean.java (added)
+++ incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tableDemos/EmployeeTableBean.java Thu Mar 29 00:50:53 2007
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.trinidaddemo.tableDemos;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.faces.event.ActionEvent;
+
+/**
+ * @author asghosh
+ */
+public class EmployeeTableBean implements Serializable
+{
+ public EmployeeTableBean()
+ {
+ _populate();
+ }
+
+ private List<EmployeeBean> _list;
+
+ private int _total;
+
+ /**
+ * @param _list
+ * The _list to set.
+ */
+ public void setList(List<EmployeeBean> list)
+ {
+ this._list = list;
+ }
+
+ /**
+ * @return Returns the _list.
+ */
+ public List<EmployeeBean> getList()
+ {
+ return _list;
+ }
+
+ /**
+ * @param _total
+ * The _total to set.
+ */
+ public void setTotal(int total)
+ {
+ this._total = total;
+ }
+
+ /**
+ * @return Returns the _total.
+ */
+ public int getTotal()
+ {
+ return _total;
+ }
+
+ public void addRow(ActionEvent event)
+ {
+ EmployeeBean dataHolder = _list.get(_list.size() - 1);
+ dataHolder.setReadOnly(true);
+ dataHolder = new EmployeeBean("", "");
+ dataHolder.setReadOnly(false);
+ _list.add(dataHolder);
+ }
+
+ public void totalRow(ActionEvent event)
+ {
+ _total = 0;
+ for(EmployeeBean dataHolder : _list)
+ {
+ if (!dataHolder.getData2().equalsIgnoreCase(""))
+ {
+ _total = _total + Integer.parseInt(dataHolder.getData2());
+ }
+ }
+ }
+
+ private void _populate()
+ {
+ _list = new ArrayList<EmployeeBean>();
+ _list.add(new EmployeeBean("22", "22"));
+ _list.add(new EmployeeBean("44", "44"));
+ _list.add(new EmployeeBean("44", "44"));
+ _list.add(new EmployeeBean("44", "44"));
+ _list.add(new EmployeeBean("44", "44"));
+
+ }
+}
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tableDemos/EmployeeTableBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/adffaces/trunk/trinidad/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/tableDemos/EmployeeTableBean.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL