- added a simple conversion example into showcase

- it is basically just populating a List in SAF2 Action with Person.java
  Object. Using *-conversion.properties as well
- since this is asked constantly in the forum, we should just put a
  simple example in showcase.



git-svn-id: https://svn.apache.org/repos/asf/struts/action2/trunk@410132 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Toby Jee
2006-05-29 17:51:39 +00:00
parent f2f5cce876
commit 0aaf550ab8
10 changed files with 240 additions and 2 deletions
@@ -0,0 +1,34 @@
/*
* $Id: AbstractDao.java 394498 2006-04-16 15:28:06Z tmjee $
*
* Copyright 2006 The Apache Software Foundation.
*
* Licensed 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.struts.action2.showcase.conversion;
import java.io.Serializable;
/**
*
*/
public class Person implements Serializable {
private String name;
private Integer age;
public void setName(String name) { this.name = name; }
public String getName() { return this.name; }
public void setAge(Integer age) { this.age = age; }
public Integer getAge() { return this.age; }
}
@@ -0,0 +1 @@
Element_persons=org.apache.struts.action2.showcase.conversion.Person
@@ -0,0 +1,43 @@
/*
* $Id: AbstractDao.java 394498 2006-04-16 15:28:06Z tmjee $
*
* Copyright 2006 The Apache Software Foundation.
*
* Licensed 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.struts.action2.showcase.conversion;
import java.util.List;
import com.opensymphony.xwork.ActionSupport;
/**
*
*/
public class PersonAction extends ActionSupport {
private List persons;
public List getPersons() { return persons; }
public void setPersons(List persons) { this.persons = persons; }
public String input() throws Exception {
return SUCCESS;
}
public String submit() throws Exception {
return SUCCESS;
}
}
@@ -1,4 +1,8 @@
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN" "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xwork PUBLIC
"-//OpenSymphony Group//XWork 1.1.1//EN"
"http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">
<!-- START SNIPPET: xworkSample -->
@@ -7,7 +11,7 @@
<include file="struts-default.xml"/>
<include file="config-browser.xml"/>
<include file="xwork-continuations.xml"/>
<include file="xwork-tags.xml"/>
@@ -31,6 +35,8 @@
<include file="xwork-model-driven.xml" />
<include file="xwork-filedownload.xml" />
<include file="xwork-conversion.xml" />
<package name="default" extends="struts-default">
<interceptors>
@@ -75,6 +75,7 @@
<li><a href="<saf:url value="/wait/index.jsp"/>">Execute & Wait</a></li>
<li><a href="<saf:url value="/token/index.jsp"/>">Token</a></li>
<li><a href="<saf:url value="/filedownload/index.jsp"/>">File Download</a></li>
<li><a href="<saf:url value="/conversion/index.jsp"/>"/>Conversion</a></li>
<li><a href="<saf:url action="index" namespace="/jsf"/>">JSF</a></li>
<li class="last"><a href="<saf:url value="/help.jsp"/>">Help</a></li>
</ul>
@@ -0,0 +1,34 @@
/*
* $Id: AbstractDao.java 394498 2006-04-16 15:28:06Z tmjee $
*
* Copyright 2006 The Apache Software Foundation.
*
* Licensed 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.struts.action2.showcase.conversion;
import java.io.Serializable;
/**
*
*/
public class Person implements Serializable {
private String name;
private Integer age;
public void setName(String name) { this.name = name; }
public String getName() { return this.name; }
public void setAge(Integer age) { this.age = age; }
public Integer getAge() { return this.age; }
}
@@ -0,0 +1,43 @@
/*
* $Id: AbstractDao.java 394498 2006-04-16 15:28:06Z tmjee $
*
* Copyright 2006 The Apache Software Foundation.
*
* Licensed 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.struts.action2.showcase.conversion;
import java.util.List;
import com.opensymphony.xwork.ActionSupport;
/**
*
*/
public class PersonAction extends ActionSupport {
private List persons;
public List getPersons() { return persons; }
public void setPersons(List persons) { this.persons = persons; }
public String input() throws Exception {
return SUCCESS;
}
public String submit() throws Exception {
return SUCCESS;
}
}
@@ -0,0 +1,44 @@
<%@taglib prefix="saf" uri="/struts-action" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Showcase - Conversion - Populate Object into SAF Action List</title>
</head>
<body>
<p/>
An example populating a list of object (Person.java) into SAF's action (PersonAction.java)
<p/>
See the jsp code <saf:url id="url" action="showJspCode" namespace="/conversion" /><saf:a href="%{#url}">here.</saf:a><br/>
See the code for PersonAction.java <saf:url id="url" action="showPersonActionJavaCode" namespace="/conversion" /><saf:a href="%{#url}">here.</saf:a><br/>
See the code for Person.java <saf:url id="url" action="showPersonJavaCode" namespace="/conversion" /><saf:a href="%{#url}">here.</saf:a><br/>
<p/>
<saf:actionerror />
<saf:fielderror />
<saf:form action="submitPersonInfo" namespace="/conversion" method="post">
<saf:textfield label="Person 1 Name"
name="persons[0].name" />
<saf:textfield label="Person 1 Age"
name="persons[0].age" />
<saf:textfield label="Person 2 Name"
name="persons[1].name" />
<saf:textfield label="Person 2 Age"
name="persons[1].age" />
<saf:textfield label="Person 3 Name"
name="persons[2].name" />
<saf:textfield label="Person 3 Age"
name="persons[2].age" />
<saf:submit />
</saf:form>
</body>
</html>
@@ -0,0 +1,15 @@
<%@taglib prefix="saf" uri="/struts-action" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Showcase - Conversion</title>
</head>
<body>
<ul>
<li><saf:url id="url" action="enterPersonsInfo" namespace="/conversion" /><saf:a href="%{#url}">Populate into SAF action class a List of Person.java Object</saf:a></li>
</ul>
</body>
</html>
@@ -0,0 +1,17 @@
<%@taglib prefix="saf" uri="/struts-action" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Showcase - Conversion - Populate Object into SAF Action List</title>
</head>
<body>
<saf:iterator value="persons" status="status">
<saf:label label="%{#status.index+' Name'}" value="%{name}" /><br/>
<saf:label label="%{#status.index+' Age'}" value="%{age}" /><br/>
</saf:iterator>
</body>
</html>