mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Moving to root below branch label
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
85
source/java/jsftest/DummyBean.java
Normal file
85
source/java/jsftest/DummyBean.java
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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 jsftest;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Object that can be used as a backing bean for components in the zoo
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class DummyBean
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(DummyBean.class);
|
||||
|
||||
private String name;
|
||||
private Properties properties;
|
||||
|
||||
public DummyBean()
|
||||
{
|
||||
this.properties = new Properties();
|
||||
this.properties.put("one", "This is 1");
|
||||
this.properties.put("two", "This is 2");
|
||||
this.properties.put("three", "This is 3");
|
||||
this.properties.put("four", "This is 4");
|
||||
}
|
||||
|
||||
public Properties getProperties()
|
||||
{
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name The name to set.
|
||||
*/
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(super.toString());
|
||||
builder.append(" (name=").append(this.name);
|
||||
builder.append(" properties=").append(this.properties).append(")");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to call on form submit buttons
|
||||
*/
|
||||
public void submit()
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Submit called on DummyBean, state = " + toString());
|
||||
}
|
||||
}
|
100
source/java/jsftest/TestList.java
Normal file
100
source/java/jsftest/TestList.java
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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 jsftest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.event.ActionEvent;
|
||||
|
||||
import org.alfresco.web.ui.common.component.UIActionLink;
|
||||
import org.alfresco.web.ui.common.component.UIBreadcrumb;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* @author kevinr
|
||||
*/
|
||||
public class TestList
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public TestList()
|
||||
{
|
||||
// Create test data rows
|
||||
|
||||
Calendar date = new GregorianCalendar(1999, 1, 5);
|
||||
rows.add(new TestRow("monkey", 5, true, 0.1f, date.getTime()));
|
||||
date = new GregorianCalendar(2000, 12, 5);
|
||||
rows.add(new TestRow("biscuit", 15, true, 0.2f, date.getTime()));
|
||||
date = new GregorianCalendar(1999, 11, 15);
|
||||
rows.add(new TestRow("HORSEY", 23, false, 0.333f, date.getTime()));
|
||||
date = new GregorianCalendar(2003, 11, 11);
|
||||
rows.add(new TestRow("thing go here", 5123, true, 0.999f, date.getTime()));
|
||||
date = new GregorianCalendar(1999, 2, 3);
|
||||
rows.add(new TestRow("I like docs", -5, false, 0.333f, date.getTime()));
|
||||
date = new GregorianCalendar(2005, 1, 1);
|
||||
rows.add(new TestRow("Document", 1235, false, 12.0f, date.getTime()));
|
||||
date = new GregorianCalendar(1998, 8, 8);
|
||||
rows.add(new TestRow("1234567890", 52, false, 5.0f, date.getTime()));
|
||||
date = new GregorianCalendar(1997, 9, 30);
|
||||
rows.add(new TestRow("space", 77, true, 17.5f, date.getTime()));
|
||||
date = new GregorianCalendar(2001, 7, 15);
|
||||
rows.add(new TestRow("House", 12, true, 0.4f, date.getTime()));
|
||||
date = new GregorianCalendar(2002, 5, 28);
|
||||
rows.add(new TestRow("Baboon", 14, true, -0.888f, date.getTime()));
|
||||
date = new GregorianCalendar(2003, 11, 11);
|
||||
rows.add(new TestRow("Woof", 0, true, 0.0f, date.getTime()));
|
||||
}
|
||||
|
||||
public List getRows()
|
||||
{
|
||||
return this.rows;
|
||||
}
|
||||
|
||||
public void clickBreadcrumb(ActionEvent event)
|
||||
{
|
||||
if (event.getComponent() instanceof UIBreadcrumb)
|
||||
{
|
||||
s_logger.debug("clickBreadcrumb action listener called, path now: " + ((UIBreadcrumb)event.getComponent()).getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void clickActionLink(ActionEvent event)
|
||||
{
|
||||
s_logger.debug("clickActionLink");
|
||||
}
|
||||
|
||||
public void clickNameLink(ActionEvent event)
|
||||
{
|
||||
UIActionLink link = (UIActionLink)event.getComponent();
|
||||
Map<String, String> params = link.getParameterMap();
|
||||
String value = params.get("name");
|
||||
if (value != null)
|
||||
{
|
||||
s_logger.debug("clicked item in list: " + value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final static Logger s_logger = Logger.getLogger(TestList.class);
|
||||
|
||||
private List<TestRow> rows = new ArrayList<TestRow>();;
|
||||
}
|
79
source/java/jsftest/TestRow.java
Normal file
79
source/java/jsftest/TestRow.java
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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 jsftest;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author kevinr
|
||||
*/
|
||||
public class TestRow
|
||||
{
|
||||
/**
|
||||
* Test a row bean with various data types
|
||||
*/
|
||||
public TestRow(String name, int count, boolean valid, float relevance, Date created)
|
||||
{
|
||||
this.name = name;
|
||||
this.count = count;
|
||||
this.valid = valid;
|
||||
this.relevance = relevance;
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getCount()
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
public boolean getValid()
|
||||
{
|
||||
return valid;
|
||||
}
|
||||
|
||||
public float getRelevance()
|
||||
{
|
||||
return relevance;
|
||||
}
|
||||
|
||||
public Date getCreated()
|
||||
{
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(Date date)
|
||||
{
|
||||
this.created = date;
|
||||
}
|
||||
|
||||
public TestRow getObject()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
private String name;
|
||||
private int count;
|
||||
private boolean valid;
|
||||
private float relevance;
|
||||
private Date created;
|
||||
}
|
222
source/java/jsftest/User.java
Normal file
222
source/java/jsftest/User.java
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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 jsftest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.model.SelectItem;
|
||||
|
||||
|
||||
/**
|
||||
* Class representing a single User bean instance.
|
||||
*
|
||||
* @author kevinr
|
||||
*/
|
||||
public class User implements Cloneable
|
||||
{
|
||||
public User()
|
||||
{
|
||||
setRoles(new ArrayList<String>(4));
|
||||
}
|
||||
|
||||
public User(String username, String password, String name, String[] roles, Date joined)
|
||||
{
|
||||
setUsername(username);
|
||||
setPassword(password);
|
||||
setName(name);
|
||||
setDateJoined(joined);
|
||||
List<String> rolesList = new ArrayList<String>(roles.length);
|
||||
for (int i=0; i<roles.length; i++)
|
||||
{
|
||||
rolesList.add(roles[i]);
|
||||
}
|
||||
setRoles(rolesList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private copy constructor
|
||||
*
|
||||
* @param u User to clone
|
||||
*/
|
||||
private User(User u)
|
||||
{
|
||||
setUsername(u.getUsername());
|
||||
setPassword(u.getPassword());
|
||||
setName(u.getName());
|
||||
setDateJoined(u.getDateJoined());
|
||||
setRoles(new ArrayList<String>(u.getRoles()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
protected Object clone() throws CloneNotSupportedException
|
||||
{
|
||||
// invoke copy constructor
|
||||
return new User(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the username
|
||||
*
|
||||
* @return the username
|
||||
*/
|
||||
public String getUsername()
|
||||
{
|
||||
return m_username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the username
|
||||
*
|
||||
* @param username the username
|
||||
*/
|
||||
public void setUsername(String username)
|
||||
{
|
||||
m_username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name
|
||||
*
|
||||
* @param name the name
|
||||
*/
|
||||
public void setName(String name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the roles
|
||||
*
|
||||
* @return the roles
|
||||
*/
|
||||
public List<String> getRoles()
|
||||
{
|
||||
return m_roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the roles
|
||||
*
|
||||
* @param roles the roles
|
||||
*/
|
||||
public void setRoles(List<String> roles)
|
||||
{
|
||||
m_roles = roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the password
|
||||
*
|
||||
* @return the password
|
||||
*/
|
||||
public String getPassword()
|
||||
{
|
||||
return m_password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the password
|
||||
*
|
||||
* @param password the password
|
||||
*/
|
||||
public void setPassword(String password)
|
||||
{
|
||||
m_password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the All Roles List
|
||||
*
|
||||
* @return the allRolesList
|
||||
*/
|
||||
public List getAllRolesList()
|
||||
{
|
||||
return m_allRolesList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the allRolesList
|
||||
*
|
||||
* @param allRolesList the allRolesList
|
||||
*/
|
||||
public void setAllRolesList(List<SelectItem> allRolesList)
|
||||
{
|
||||
m_allRolesList = allRolesList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dateJoined
|
||||
*
|
||||
* @return the dateJoined
|
||||
*/
|
||||
public Date getDateJoined()
|
||||
{
|
||||
return m_dateJoined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dateJoined
|
||||
*
|
||||
* @param dateJoined the dateJoined
|
||||
*/
|
||||
public void setDateJoined(Date dateJoined)
|
||||
{
|
||||
m_dateJoined = dateJoined;
|
||||
}
|
||||
|
||||
|
||||
/** the allRolesList enum list */
|
||||
private static List<SelectItem> m_allRolesList = new ArrayList<SelectItem>(8);
|
||||
static
|
||||
{
|
||||
m_allRolesList.add(new SelectItem("admin", "Administrator"));
|
||||
m_allRolesList.add(new SelectItem("superuser", "Super User"));
|
||||
m_allRolesList.add(new SelectItem("dev", "Developer"));
|
||||
m_allRolesList.add(new SelectItem("qa", "QA"));
|
||||
m_allRolesList.add(new SelectItem("standard", "Basic User"));
|
||||
}
|
||||
|
||||
|
||||
/** the password */
|
||||
private String m_password;
|
||||
|
||||
/** the username */
|
||||
private String m_username;
|
||||
|
||||
/** the name */
|
||||
private String m_name;
|
||||
|
||||
/** the roles */
|
||||
private List<String> m_roles;
|
||||
|
||||
/** the date joined */
|
||||
private Date m_dateJoined;
|
||||
}
|
302
source/java/jsftest/UserListBean.java
Normal file
302
source/java/jsftest/UserListBean.java
Normal file
@@ -0,0 +1,302 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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 jsftest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.component.UIComponent;
|
||||
import javax.faces.component.UIParameter;
|
||||
import javax.faces.component.html.HtmlOutputText;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.ActionEvent;
|
||||
import javax.faces.event.ValueChangeEvent;
|
||||
import javax.faces.model.DataModel;
|
||||
import javax.faces.model.ListDataModel;
|
||||
import javax.faces.validator.ValidatorException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* JSF Managed Bean. Provides the backing for the userlist.jsp view. The view uses
|
||||
* the datatable control to bind to the List of User bean objects. Implements the
|
||||
* action events called by the view when the user clicks the Edit link or Add button.
|
||||
*
|
||||
* @author kevinr
|
||||
*/
|
||||
public class UserListBean
|
||||
{
|
||||
// ===========================================================================
|
||||
// Construction
|
||||
|
||||
public UserListBean()
|
||||
{
|
||||
Calendar date = new GregorianCalendar(2002, 5, 10);
|
||||
m_users.add(new User("admin", "admin", "Administrator", new String[] {"admin","superuser"}, date.getTime()));
|
||||
date = new GregorianCalendar(2001, 7, 10);
|
||||
m_users.add(new User("kevinr", "kevinr", "Kevin Roast", new String[] {"admin","superuser","dev"}, date.getTime()));
|
||||
date = new GregorianCalendar(2003, 8, 15);
|
||||
m_users.add(new User("gavinc", "gavinc", "Gavin Cornwell", new String[] {"superuser","dev"}, date.getTime()));
|
||||
date = new GregorianCalendar(2003, 1, 1);
|
||||
m_users.add(new User("stever", "stever", "Steve Rigby", new String[] {"superuser","qa"}, date.getTime()));
|
||||
}
|
||||
|
||||
|
||||
// ===========================================================================
|
||||
// Bean methods
|
||||
|
||||
public List getUsers()
|
||||
{
|
||||
return m_users;
|
||||
}
|
||||
|
||||
public void setUsers(List<User> users)
|
||||
{
|
||||
m_users = users;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the users list as a wrapped DataModel object
|
||||
*
|
||||
* @return DataModel for use by the data-table components
|
||||
*/
|
||||
public DataModel getUsersModel()
|
||||
{
|
||||
if (m_usersModel == null)
|
||||
{
|
||||
m_usersModel = new ListDataModel();
|
||||
m_usersModel.setWrappedData(m_users);
|
||||
}
|
||||
|
||||
return m_usersModel;
|
||||
}
|
||||
|
||||
public User getUser()
|
||||
{
|
||||
return m_currentUser;
|
||||
}
|
||||
|
||||
public void setUser(User user)
|
||||
{
|
||||
m_currentUser = user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the isNewUser
|
||||
*
|
||||
* @return the isNewUser
|
||||
*/
|
||||
public boolean getIsNewUser()
|
||||
{
|
||||
return m_isNewUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the isNewUser
|
||||
*
|
||||
* @param isNewUser the isNewUser
|
||||
*/
|
||||
public void setIsNewUser(boolean isNewUser)
|
||||
{
|
||||
m_isNewUser = isNewUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rolesOutputText
|
||||
*
|
||||
* @return the rolesOutputText
|
||||
*/
|
||||
public HtmlOutputText getRolesOutputText()
|
||||
{
|
||||
return m_rolesOutputText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rolesOutputText
|
||||
*
|
||||
* @param rolesOutputText the rolesOutputText component
|
||||
*/
|
||||
public void setRolesOutputText(HtmlOutputText rolesOutputText)
|
||||
{
|
||||
m_rolesOutputText = rolesOutputText;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ===========================================================================
|
||||
// Action event methods
|
||||
|
||||
/**
|
||||
* Edit user action event listener
|
||||
*
|
||||
* Specified directly on the appropriate tag such as commandLink or commandButton
|
||||
* e.g. actionListener="#{UserListBean.editUser}"
|
||||
*
|
||||
* This listener cannot directly affect the navigation of the page - the command
|
||||
* tag has an "action" attribute of which the default handler will use the outcome
|
||||
* from the faces-config.xml by default or call a specifid controller method
|
||||
* returning the String outcome as usual.
|
||||
*/
|
||||
public void editUser(ActionEvent event)
|
||||
{
|
||||
s_logger.debug("*****USERLIST: " + ((UIParameter)event.getComponent().findComponent("userId")).getValue().toString());
|
||||
|
||||
// Get the username from the "param" tag component we added as a nested tag
|
||||
// to the command tag that fired this event.
|
||||
// So we can have a key to work out which item was clicked in the data table
|
||||
String usernameId = ((UIParameter)event.getComponent().findComponent("userId")).getValue().toString();
|
||||
|
||||
// It is also possible to get the relevent row from the DataModel we created
|
||||
// wrapping our users list. But this is a weak solution as models which then
|
||||
// potentially sort or page data may not provide the correct row index.
|
||||
// e.g.
|
||||
// m_usersModel.getWrappedData().get(m_usersModel.getRowIndex());
|
||||
|
||||
for (Iterator i=m_users.iterator(); i.hasNext(); /**/)
|
||||
{
|
||||
User user = (User)i.next();
|
||||
if (user.getUsername().equals(usernameId))
|
||||
{
|
||||
// set the user as current so we know which one to edit etc.
|
||||
try
|
||||
{
|
||||
setUser((User)user.clone());
|
||||
setIsNewUser(false);
|
||||
}
|
||||
catch (CloneNotSupportedException e)
|
||||
{
|
||||
// will not happen - clone is supported for our own types
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* OK button action handler
|
||||
*
|
||||
* @return outcome view name
|
||||
*/
|
||||
public void editUserOK(ActionEvent event)
|
||||
{
|
||||
s_logger.debug("*****USERLIST: persisting user: " + getUser().getUsername());
|
||||
for (int i=0; i<m_users.size(); i++)
|
||||
{
|
||||
User user = (User)m_users.get(i);
|
||||
if (user.getUsername().equals(getUser().getUsername()))
|
||||
{
|
||||
// found modified user - persist changes
|
||||
m_users.set(i, getUser());
|
||||
m_usersModel = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add user action event listener
|
||||
*/
|
||||
public void addUser(ActionEvent event)
|
||||
{
|
||||
// create a blank user template
|
||||
setUser(new User());
|
||||
setIsNewUser(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* OK button action handler
|
||||
*
|
||||
* @return outcome view name
|
||||
*/
|
||||
public void addUserOK(ActionEvent event)
|
||||
{
|
||||
// persist new user details
|
||||
s_logger.debug("*****USERLIST: creating user: " + getUser().getUsername());
|
||||
m_users.add(getUser());
|
||||
m_usersModel = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Example of a value changed event handler
|
||||
* NOTE: Value changed events do not submit the form directly, either a command
|
||||
* button or link submits the form or can be done manually with Javascript
|
||||
*/
|
||||
public void roleValueChanged(ValueChangeEvent event)
|
||||
{
|
||||
s_logger.debug("*****USERLIST: Value change from: " + event.getOldValue() + " to: " + event.getNewValue());
|
||||
|
||||
// example of the use of a direct component binding
|
||||
// in the JSP page, a outputText tag has used binding='beanmethod' so we
|
||||
// can now programatically modify the component as required
|
||||
if (m_rolesOutputText != null)
|
||||
{
|
||||
m_rolesOutputText.setValue(getUser().getRoles().toString());
|
||||
}
|
||||
|
||||
// An alternative to using the component binding would be to lookup the
|
||||
// component via it's component Id:
|
||||
// HtmlOutputText comp = (HtmlOutputText)event.getComponent().findComponent("roles-text");
|
||||
// comp.setValue(...);
|
||||
|
||||
// The attributes of a component are all stored in a Map, the Map features
|
||||
// attribute-property transparency which means typed attributes can be get/set
|
||||
// directly without using casts as the appropriate getters/setters will be
|
||||
// called for you by the framework.
|
||||
// comp.getAttributes().put("style", "color:red");
|
||||
}
|
||||
|
||||
|
||||
// ===========================================================================
|
||||
// Validator methods
|
||||
|
||||
/**
|
||||
* Example of a specific validation method. Required as the basic validator
|
||||
* child tags are not sufficient for anything beyond very simple length checks etc.
|
||||
*/
|
||||
public void validateUsername(FacesContext context, UIComponent component, Object value)
|
||||
throws ValidatorException
|
||||
{
|
||||
String username = (String)value;
|
||||
if (username.length() < 5 || username.length() > 12)
|
||||
{
|
||||
String err = "Username must be between 5 and 12 characters in length.";
|
||||
throw new ValidatorException(new FacesMessage(err));
|
||||
}
|
||||
else if (username.indexOf(' ') != -1 || username.indexOf('\t') != -1)
|
||||
{
|
||||
String err = "Username cannot contain space or whitespace characters.";
|
||||
throw new ValidatorException(new FacesMessage(err));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ===========================================================================
|
||||
// Private data
|
||||
|
||||
private List<User> m_users = new ArrayList<User>();
|
||||
private DataModel m_usersModel = null;
|
||||
private User m_currentUser = null;
|
||||
private boolean m_isNewUser = false;
|
||||
|
||||
/** the HTMLOutputText component */
|
||||
private HtmlOutputText m_rolesOutputText = null;
|
||||
|
||||
protected final static Logger s_logger = Logger.getLogger(UserListBean.class);
|
||||
}
|
35
source/java/jsftest/ZooService.java
Normal file
35
source/java/jsftest/ZooService.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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 jsftest;
|
||||
|
||||
/**
|
||||
* Managed bean that provides action handlers to navigate around the component zoo
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class ZooService
|
||||
{
|
||||
public String showPropertyZoo()
|
||||
{
|
||||
return "showPropertyZoo";
|
||||
}
|
||||
|
||||
public String showPropertyZoo2()
|
||||
{
|
||||
return "showPropertyZoo2";
|
||||
}
|
||||
}
|
256
source/java/jsftest/repository/DataDictionary.java
Normal file
256
source/java/jsftest/repository/DataDictionary.java
Normal file
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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 jsftest.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Class to represent a basic data dictionary service
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class DataDictionary
|
||||
{
|
||||
private Map types;
|
||||
|
||||
public DataDictionary()
|
||||
{
|
||||
this.types = new HashMap();
|
||||
|
||||
// setup the dictionary
|
||||
Property name = new Property("name", "string", "Name", false);
|
||||
Property desc = new Property("description", "string", "Description" , false);
|
||||
Property created = new Property("created", "datetime", "Created Date", true);
|
||||
Property modified = new Property("modified", "datetime", "Modified Date", false);
|
||||
Property keywords = new Property("keywords", "string[]", "Keywords", false);
|
||||
|
||||
MetaData base = new MetaData("base");
|
||||
base.addProperty(name);
|
||||
base.addProperty(desc);
|
||||
base.addProperty(created);
|
||||
base.addProperty(modified);
|
||||
base.addProperty(keywords);
|
||||
|
||||
Property sopid = new Property("sopId", "string", "SOP ID", true);
|
||||
Property effective = new Property("effective", "datetime", "Effective Date", false);
|
||||
Property approved = new Property("approved", "boolean", "Approved", false);
|
||||
Property latestVersion = new Property("latestversion", "string", "Latest Version", true);
|
||||
|
||||
MetaData sop = new MetaData("SOP");
|
||||
sop.setProperties(base.getProperties());
|
||||
sop.addProperty(sopid);
|
||||
sop.addProperty(effective);
|
||||
sop.addProperty(approved);
|
||||
// add an aspect and the associated property
|
||||
sop.addAspect("versionable");
|
||||
sop.addProperty(latestVersion);
|
||||
|
||||
this.types.put(base.getTypeName(), base);
|
||||
this.types.put(sop.getTypeName(), sop);
|
||||
}
|
||||
|
||||
public MetaData getMetaData(String type)
|
||||
{
|
||||
return (MetaData)this.types.get(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the types.
|
||||
*/
|
||||
public Map getTypes()
|
||||
{
|
||||
return this.types;
|
||||
}
|
||||
|
||||
|
||||
// *********************
|
||||
// *** Inner classes ***
|
||||
// *********************
|
||||
|
||||
/**
|
||||
* Represents the meta data of an object
|
||||
* @author gavinc
|
||||
*/
|
||||
public class MetaData
|
||||
{
|
||||
private Map propertiesMap;
|
||||
private List properties;
|
||||
private String typeName;
|
||||
private List aspects;
|
||||
|
||||
public MetaData(String typeName)
|
||||
{
|
||||
this.properties = new ArrayList();
|
||||
this.propertiesMap = new HashMap();
|
||||
this.aspects = new ArrayList();
|
||||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a property to the meta data object
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public void addProperty(Property property)
|
||||
{
|
||||
this.properties.add(property);
|
||||
this.propertiesMap.put(property.getName(), property);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the properties.
|
||||
*/
|
||||
public List getProperties()
|
||||
{
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param properties The properties to set.
|
||||
*/
|
||||
public void setProperties(List properties)
|
||||
{
|
||||
this.properties.clear();
|
||||
this.propertiesMap.clear();
|
||||
|
||||
Iterator iter = properties.iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
Property prop = (Property)iter.next();
|
||||
this.properties.add(prop);
|
||||
this.propertiesMap.put(prop.getName(), prop);
|
||||
}
|
||||
}
|
||||
|
||||
public Map getPropertiesMap()
|
||||
{
|
||||
return this.propertiesMap;
|
||||
}
|
||||
|
||||
public List getAspects()
|
||||
{
|
||||
return this.aspects;
|
||||
}
|
||||
|
||||
public void addAspect(String aspect)
|
||||
{
|
||||
this.aspects.add(aspect);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the typeName.
|
||||
*/
|
||||
public String getTypeName()
|
||||
{
|
||||
return this.typeName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a property on an object
|
||||
* @author gavinc
|
||||
*/
|
||||
public class Property
|
||||
{
|
||||
private String name;
|
||||
private String type;
|
||||
private String displayName;
|
||||
private boolean readOnly;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param type
|
||||
* @param readOnly
|
||||
*/
|
||||
public Property(String name, String type, String displayName, boolean readOnly)
|
||||
{
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.displayName = displayName;
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the name.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name The name to set.
|
||||
*/
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the type.
|
||||
*/
|
||||
public String getType()
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type The type to set.
|
||||
*/
|
||||
public void setType(String type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the displayName.
|
||||
*/
|
||||
public String getDisplayName()
|
||||
{
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param displayName The displayName to set.
|
||||
*/
|
||||
public void setDisplayName(String displayName)
|
||||
{
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the readOnly.
|
||||
*/
|
||||
public boolean isReadOnly()
|
||||
{
|
||||
return this.readOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param readOnly The readOnly to set.
|
||||
*/
|
||||
public void setReadOnly(boolean readOnly)
|
||||
{
|
||||
this.readOnly = readOnly;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
44
source/java/jsftest/repository/NodeRef.java
Normal file
44
source/java/jsftest/repository/NodeRef.java
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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 jsftest.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Mock NodeRef object that comes from the Mock NodeService API.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class NodeRef implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 3833183614468175153L;
|
||||
|
||||
private String id;
|
||||
|
||||
public NodeRef(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the id.
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
}
|
104
source/java/jsftest/repository/NodeService.java
Normal file
104
source/java/jsftest/repository/NodeService.java
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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 jsftest.repository;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Mock NodeService API
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class NodeService
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(NodeService.class);
|
||||
|
||||
public static NodeRef getNodeRef(String path)
|
||||
{
|
||||
return new NodeRef(path);
|
||||
}
|
||||
|
||||
public static String getType(NodeRef nodeRef)
|
||||
{
|
||||
String id = nodeRef.getId();
|
||||
String type = null;
|
||||
|
||||
if (id.equalsIgnoreCase("/gav.doc") ||
|
||||
id.equalsIgnoreCase("/kev.txt"))
|
||||
{
|
||||
type = "base";
|
||||
}
|
||||
else if (id.equalsIgnoreCase("/sop.txt"))
|
||||
{
|
||||
type = "SOP";
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
public static Map getProperties(NodeRef nodeRef)
|
||||
{
|
||||
String id = nodeRef.getId();
|
||||
Map properties = null;
|
||||
|
||||
if (id.equalsIgnoreCase("/gav.doc"))
|
||||
{
|
||||
properties = createProperties("Gav", "Gavs Object",
|
||||
new String[] {"gav", "gadget", "gibbon"}, null);
|
||||
}
|
||||
else if (id.equalsIgnoreCase("/kev.txt"))
|
||||
{
|
||||
properties = createProperties("Kev", "Kevs Object",
|
||||
new String[] {"kev", "monkey"}, null);
|
||||
}
|
||||
else if (id.equalsIgnoreCase("/sop.txt"))
|
||||
{
|
||||
properties = createProperties("SOP", "A manufacturing SOP",
|
||||
new String[] {"sop", "manufacturing"}, "sop1");
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
private static Map createProperties(String name, String desc,
|
||||
String[] keywords, String sop)
|
||||
{
|
||||
HashMap props = new HashMap();
|
||||
|
||||
Date date = new Date();
|
||||
props.put("name", name);
|
||||
props.put("description", desc);
|
||||
props.put("keywords", keywords);
|
||||
props.put("created", date);
|
||||
props.put("modified", date);
|
||||
|
||||
if (sop != null)
|
||||
{
|
||||
props.put("sopId", sop);
|
||||
props.put("effective", date);
|
||||
props.put("approved", new Boolean(true));
|
||||
props.put("latestversion", "1.6");
|
||||
}
|
||||
|
||||
return props;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user