mary malven

Greenhorn
+ Follow
since Feb 09, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by mary malven

hi all,
I try a sample with struts1.3.10+EJB3+Glassfish3+Netbeans6.8 which can insert user in database,
show all users,delete and edit user correctly but when I add validation to userForm,
validation works correctly but link of edit user makes an error :

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "allUsersForm" in any scope
root cause

javax.servlet.jsp.JspException: Cannot find bean: "allUsersForm" in any scope
note The full stack traces of the exception and its root causes are available in the GlassFish v3 logs.

--------------------------------------------------------------------------------

GlassFish v3

___________________________________________________

in which "allUsersForm" is a form used in showAllUsers.jsp, showAllUsers(in action) and userForm has used in showOneUser in action to load in edit.jsp for edditing .
I changed scope="request" to scope="session" in struts-config.xml but when cliking on edit link
it makes no change and return to the same page(showAllUsers.jsp).

please send if anybody has any iead.
thank in advance.
___________________________________________________
----------------------struts-config.xml-----------------------
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>
<form-beans>
<form-bean name="userForm" type="form.UserForm"/>
<form-bean name="allUsersForm" type="form.AllUsersForm"/>

</form-beans>

<global-exceptions>

</global-exceptions>

<global-forwards>
<forward name="welcome" path="/Welcome.do"/>
</global-forwards>

<action-mappings>
<action path="/Welcome" forward="/welcomeStruts.jsp"/>

<action path="/changeLang" type="action.ChangeLocaleAction">
<forward name="home" path="/index.jsp"/>
</action>

<action path="/performRegister" type="action.UserRegisterAction" parameter="saveUser" name="userForm" scope="request" input="/pages/addUser.jsp" cancellable="true">
<forward name="home" path="/index.jsp"/>
<forward name="saveSuccess" path="/pages/saveSuccess.jsp"/>
</action>

<action path="/showAllUsers" type="action.UserRegisterAction" parameter="loadAllUsers" name="allUsersForm" scope="request" input="/index.jsp" >
<forward name="allUsersSuccess" path="/pages/showAllUsers.jsp" />
</action>

<action path="/loadOneUser" type="action.UserRegisterAction" parameter="showOneUser" name="userForm" scope="request" input="/pages/showAllUsers.jsp" >
<forward name="loadOneUserSuccess" path="/pages/edit.jsp"/>
</action>

<action path="/edit" type="action.UserRegisterAction" parameter="editUser" name="userForm" scope="request" input="/pages/edit.jsp" cancellable="true" >
<forward name="home" path="/index.jsp"/>
<forward name="editSuccess" path="/pages/editSuccess.jsp"/>
</action>

<action path="/deleteUser" type="action.UserRegisterAction" parameter="deleteUser" scope="request" input="/pages/showAllUsers.jsp" >
<forward name="deleteSuccess" path="/showAllUsers.do"/>

</action>

</action-mappings>

<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

<message-resources parameter="com/myapp/struts/ApplicationResource"/>

<!-- ========================= Tiles plugin ===============================-->

<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
</plug-in>

<!-- ========================= Validator plugin ================================= -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>

</struts-config>
-----------------UserRegisterAction.java----------------
public ActionForward loadAllUsers(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{

try
{
Context ctx = new InitialContext();

iuser = (IUser) ctx.lookup("ebadiUserBizImpl");

} catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException(e);
}

List<UserEntity> allUsers=iuser.loadAllUsers();

List<UserForm> usersListForm=new ArrayList<UserForm>();

for(UserEntity userEntity:allUsers){
System.out.println("in foreach 1");
UserForm userForm=new UserForm();
BeanUtils.copyProperties(userForm,userEntity );
usersListForm.add(userForm);

System.out.println("in foreach 2");
}

AllUsersForm allUsersForm =new AllUsersForm();
// AllUsersForm allUsersForm =(AllUsersForm)form;
allUsersForm.setAllUsers(usersListForm);

BeanUtils.copyProperties(form,allUsersForm );


return mapping.findForward("allUsersSuccess");
}

//************showOneUser************************

public ActionForward showOneUser(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{

try
{
Context ctx = new InitialContext();

iuser = (IUser) ctx.lookup("ebadiUserBizImpl");

} catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException(e);
}


UserEntity userEntity=iuser.loadOneUser(Integer.parseInt(request.getParameter("id")));
UserForm userForm=(UserForm) form;
// UserForm userForm=new UserForm();
BeanUtils.copyProperties(userForm, userEntity );

return mapping.findForward("loadOneUserSuccess");

}


------------------showAllUsers.jsp---------------

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>


<html dir='<bean:message key="dir"/>'>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><bean:message key="AllUsers.head"/></title>

<script type="text/javascript" language="JavaScript">
function deleteConfirm(){
var msg="<bean:message key="are.you.sure.to.delete.user"/>";
if(confirm(msg)==false){
return false;
}

}
</script>

</head>
<body>

<h2><bean:message key="AllUsers.head"/></h2><br/><hr/>

<html:link page="/pages/addUser.jsp"><bean:message key="add.user"/></html:link>
<br>
<html:link page="/index.jsp"><bean:message key="return.home"/></html:link>
<br>

<bean:message key="AllUsers.head"/>:<br/>

<table border="1">
<tr><td><bean:message key="id"/></td>
<td><bean:message key="first.name"/></td>
<td><bean:message key="last.name"/></td>
<td><bean:message key="gender"/></td>
<td><bean:message key="city"/></td>
<td><bean:message key="edit"/></td>
<td><bean:message key="delete"/></td>
</tr>
<logic:iterate id="list" name="allUsersForm" property="allUsers" >
<tr><td><bean:write name="list" property="id"/></td>
<td><bean:write name="list" property="firstName"/></td>
<td><bean:write name="list" property="lastName"/></td>
<td><logic:equal name="list" value="true" property="gender"><bean:message key="male"/></logic:equal>
<logic:equal name="list" value="false" property="gender"><bean:message key="female"/></logic:equal><br/></td>
<td><bean:write name="list" property="city"/></td>
<%-- <td><a href="loadOneUser.do?id=<bean:write name="list" property="id"/>"><bean:message key="edit"/></a></td>
<td><a href="deleteUser.do?id=<bean:write name="list" property="id"/>" onclick="return deleteConfirm()" ><bean:message key="delete"/></a></td>
--%>
<td><html:link action="loadOneUser.do" paramId="id" paramName="list" paramProperty="id"><bean:message key="edit"/></html:link></td>
<td><html:link action="deleteUser.do" paramId="id" paramName="list" paramProperty="id" onclick="return deleteConfirm()" ><bean:message key="delete"/></html:link></td>

</tr>

</logic:iterate>

</table>

</body>
</html>

-----------------------validation.xml-----------------------
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.3.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd">

<form-validation>


<global>

<!-- An example global constant
<constant>
<constant-name>postalCode</constant-name>
<constant-value>^\d{5}\d*$</constant-value>
</constant>
end example-->

</global>

<formset>

<!-- An example form -->
<form name="logonForm">
<field
property="username"
depends="required">
<arg key="logonForm.username"/>
</field>
<field
property="password"
depends="required,mask">
<arg key="logonForm.password"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9a-zA-Z]*$</var-value>
</var>
</field>
</form>

</formset>

<!-- An example formset for another locale -->
<formset language="fr">

<constant>
<constant-name>postalCode</constant-name>
<constant-value>^[0-9a-zA-Z]*$</constant-value>
</constant>

<!-- An example form -->
<form name="logonForm">
<field
property="username"
depends="required">
<arg key="logonForm.username"/>
</field>
<field
property="password"
depends="required,mask">
<arg key="logonForm.password"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9a-zA-Z]*$</var-value>
</var>
</field>
</form>

</formset>

<!---************* userForm **************************************************** -->
<formset>
<form name="userForm">
<field
property="firstName"
depends="required">
<arg key="first.name"/>
</field>
<field
property="lastName"
depends="required">
<arg key="last.name"/>

</field>

<field
property="userName"
depends="required">
<arg key="user.name"/>

</field>

<field property="password" depends="required, minlength, validwhen">
<msg key="password.and.confirm.are.not.equal" name="validwhen"/>
<arg position="0" key="password"/>
<arg position="1" name="minlength" key="${var:minlength}" resource="false"/>
<var>
<var-name>test</var-name>
<var-value>(*this* == confirmPassword)</var-value>
</var>
<var>
<var-name>minlength</var-name>
<var-value>6</var-value>
</var>
</field>

<field
property="confirmPassword"
depends="required">
<arg key="confirmPassword"/>

</field>

</form>
</formset>

</form-validation>
13 years ago

hi all,
I try a sample with struts1.3.10+EJB3+Glassfish3+Netbeans6.8 which can insert user in database,
show all users,delete and edit user correctly but when I add validation to userForm,
validation works correctly but link of edit user makes an error :

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "allUsersForm" in any scope
root cause

javax.servlet.jsp.JspException: Cannot find bean: "allUsersForm" in any scope
note The full stack traces of the exception and its root causes are available in the GlassFish v3 logs.

--------------------------------------------------------------------------------

GlassFish v3

___________________________________________________

in which "allUsersForm" is a form used in showAllUsers.jsp, showAllUsers(in action) and userForm has used in showOneUser in action to load in edit.jsp for edditing .
I changed scope="request" to scope="session" in struts-config.xml but when cliking on edit link
it makes no change and return to the same page(showAllUsers.jsp).

please send if anybody has any iead.
thank in advance.
___________________________________________________
----------------------struts-config.xml-----------------------
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>
<form-beans>
<form-bean name="userForm" type="form.UserForm"/>
<form-bean name="allUsersForm" type="form.AllUsersForm"/>

</form-beans>

<global-exceptions>

</global-exceptions>

<global-forwards>
<forward name="welcome" path="/Welcome.do"/>
</global-forwards>

<action-mappings>
<action path="/Welcome" forward="/welcomeStruts.jsp"/>

<action path="/changeLang" type="action.ChangeLocaleAction">
<forward name="home" path="/index.jsp"/>
</action>

<action path="/performRegister" type="action.UserRegisterAction" parameter="saveUser" name="userForm" scope="request" input="/pages/addUser.jsp" cancellable="true">
<forward name="home" path="/index.jsp"/>
<forward name="saveSuccess" path="/pages/saveSuccess.jsp"/>
</action>

<action path="/showAllUsers" type="action.UserRegisterAction" parameter="loadAllUsers" name="allUsersForm" scope="request" input="/index.jsp" >
<forward name="allUsersSuccess" path="/pages/showAllUsers.jsp" />
</action>

<action path="/loadOneUser" type="action.UserRegisterAction" parameter="showOneUser" name="userForm" scope="request" input="/pages/showAllUsers.jsp" >
<forward name="loadOneUserSuccess" path="/pages/edit.jsp"/>
</action>

<action path="/edit" type="action.UserRegisterAction" parameter="editUser" name="userForm" scope="request" input="/pages/edit.jsp" cancellable="true" >
<forward name="home" path="/index.jsp"/>
<forward name="editSuccess" path="/pages/editSuccess.jsp"/>
</action>

<action path="/deleteUser" type="action.UserRegisterAction" parameter="deleteUser" scope="request" input="/pages/showAllUsers.jsp" >
<forward name="deleteSuccess" path="/showAllUsers.do"/>

</action>

</action-mappings>

<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

<message-resources parameter="com/myapp/struts/ApplicationResource"/>

<!-- ========================= Tiles plugin ===============================-->

<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
</plug-in>

<!-- ========================= Validator plugin ================================= -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>

</struts-config>
-----------------UserRegisterAction.java----------------
public ActionForward loadAllUsers(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{

try
{
Context ctx = new InitialContext();

iuser = (IUser) ctx.lookup("ebadiUserBizImpl");

} catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException(e);
}

List<UserEntity> allUsers=iuser.loadAllUsers();

List<UserForm> usersListForm=new ArrayList<UserForm>();

for(UserEntity userEntity:allUsers){
System.out.println("in foreach 1");
UserForm userForm=new UserForm();
BeanUtils.copyProperties(userForm,userEntity );
usersListForm.add(userForm);

System.out.println("in foreach 2");
}

AllUsersForm allUsersForm =new AllUsersForm();
// AllUsersForm allUsersForm =(AllUsersForm)form;
allUsersForm.setAllUsers(usersListForm);

BeanUtils.copyProperties(form,allUsersForm );


return mapping.findForward("allUsersSuccess");
}

//************showOneUser************************

public ActionForward showOneUser(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{

try
{
Context ctx = new InitialContext();

iuser = (IUser) ctx.lookup("ebadiUserBizImpl");

} catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException(e);
}


UserEntity userEntity=iuser.loadOneUser(Integer.parseInt(request.getParameter("id")));
UserForm userForm=(UserForm) form;
// UserForm userForm=new UserForm();
BeanUtils.copyProperties(userForm, userEntity );

return mapping.findForward("loadOneUserSuccess");

}


------------------showAllUsers.jsp---------------

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>


<html dir='<bean:message key="dir"/>'>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><bean:message key="AllUsers.head"/></title>

<script type="text/javascript" language="JavaScript">
function deleteConfirm(){
var msg="<bean:message key="are.you.sure.to.delete.user"/>";
if(confirm(msg)==false){
return false;
}

}
</script>

</head>
<body>

<h2><bean:message key="AllUsers.head"/></h2><br/><hr/>

<html:link page="/pages/addUser.jsp"><bean:message key="add.user"/></html:link>
<br>
<html:link page="/index.jsp"><bean:message key="return.home"/></html:link>
<br>

<bean:message key="AllUsers.head"/>:<br/>

<table border="1">
<tr><td><bean:message key="id"/></td>
<td><bean:message key="first.name"/></td>
<td><bean:message key="last.name"/></td>
<td><bean:message key="gender"/></td>
<td><bean:message key="city"/></td>
<td><bean:message key="edit"/></td>
<td><bean:message key="delete"/></td>
</tr>
<logic:iterate id="list" name="allUsersForm" property="allUsers" >
<tr><td><bean:write name="list" property="id"/></td>
<td><bean:write name="list" property="firstName"/></td>
<td><bean:write name="list" property="lastName"/></td>
<td><logic:equal name="list" value="true" property="gender"><bean:message key="male"/></logic:equal>
<logic:equal name="list" value="false" property="gender"><bean:message key="female"/></logic:equal><br/></td>
<td><bean:write name="list" property="city"/></td>
<%-- <td><a href="loadOneUser.do?id=<bean:write name="list" property="id"/>"><bean:message key="edit"/></a></td>
<td><a href="deleteUser.do?id=<bean:write name="list" property="id"/>" onclick="return deleteConfirm()" ><bean:message key="delete"/></a></td>
--%>
<td><html:link action="loadOneUser.do" paramId="id" paramName="list" paramProperty="id"><bean:message key="edit"/></html:link></td>
<td><html:link action="deleteUser.do" paramId="id" paramName="list" paramProperty="id" onclick="return deleteConfirm()" ><bean:message key="delete"/></html:link></td>

</tr>

</logic:iterate>

</table>

</body>
</html>

-----------------------validation.xml-----------------------
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.3.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_3_0.dtd">

<form-validation>


<global>

<!-- An example global constant
<constant>
<constant-name>postalCode</constant-name>
<constant-value>^\d{5}\d*$</constant-value>
</constant>
end example-->

</global>

<formset>

<!-- An example form -->
<form name="logonForm">
<field
property="username"
depends="required">
<arg key="logonForm.username"/>
</field>
<field
property="password"
depends="required,mask">
<arg key="logonForm.password"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9a-zA-Z]*$</var-value>
</var>
</field>
</form>

</formset>

<!-- An example formset for another locale -->
<formset language="fr">

<constant>
<constant-name>postalCode</constant-name>
<constant-value>^[0-9a-zA-Z]*$</constant-value>
</constant>

<!-- An example form -->
<form name="logonForm">
<field
property="username"
depends="required">
<arg key="logonForm.username"/>
</field>
<field
property="password"
depends="required,mask">
<arg key="logonForm.password"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9a-zA-Z]*$</var-value>
</var>
</field>
</form>

</formset>

<!---************* userForm **************************************************** -->
<formset>
<form name="userForm">
<field
property="firstName"
depends="required">
<arg key="first.name"/>
</field>
<field
property="lastName"
depends="required">
<arg key="last.name"/>

</field>

<field
property="userName"
depends="required">
<arg key="user.name"/>

</field>

<field property="password" depends="required, minlength, validwhen">
<msg key="password.and.confirm.are.not.equal" name="validwhen"/>
<arg position="0" key="password"/>
<arg position="1" name="minlength" key="${var:minlength}" resource="false"/>
<var>
<var-name>test</var-name>
<var-value>(*this* == confirmPassword)</var-value>
</var>
<var>
<var-name>minlength</var-name>
<var-value>6</var-value>
</var>
</field>

<field
property="confirmPassword"
depends="required">
<arg key="confirmPassword"/>

</field>

</form>
</formset>

</form-validation>