Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link

galne vaibhav

Greenhorn
+ Follow
since Nov 30, 2009
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 galne vaibhav

Hi SWAPNIL please try this simple example you need ony one html one jsp and jxl jar









12 years ago

i have code in which i have grid an elements in which element gets deleted on checkbox sharing the same




by using this way you can send the values is id

12 years ago

you are making mistake you mention alloewed type as image/jpeg and trying to upload image/jpg

just open the file in paint save as .jpeg format and try to upload

12 years ago
what you have to do is just get the value data from database put in hashmap or list and show on jsp in list attribute as mention below

JSP code:where objBussCode is my hashmap name

Edited by Dave to be legible.
12 years ago

you can do simple thing write onclick javascript function and assign value to hidden control and in action class write the getter setters for hidden control.

12 years ago

hi you have to follow simple steps





functions gfnDisableKeys() and gfnDisableControls() are optional that is written for not allow any char other than date








action code








reply if your prblem not rsolved


take care of this things:
NOTE-you need to specify head tag like this i gusss your problem resolve when you do this

<head>
<title>l</title>
<s:head/>
<sx:head/>
</head>


and you need to add struts2-dojo-plugin-2.1.6.jar to your application.

12 years ago
you only have to follow struts way of doing it you have call the setter method of the textfield
for example
my field name:
private String txtDescription;

getter and setters
public String getTxtDescription() {
return txtDescription;
}
public void setTxtDescription(String txtDescription) {
this.txtDescription = txtDescription;
}



In targeted method

place one line

setTxtDescription(txtDescription);

reply if you want more detail.
12 years ago

Ben sassi mohammed wrote:hello
i have problem white struts 2 validator

Tags <s:fielderror> you told me works well. Except that
Now I have duplicate messages (I thought the message "by
Default "no longer present).

please looks attchments

thank you in advance




hi Ben sassi mohammed,


can you share your validation xml code and action code then it will be more clear i think you have done both xml action level validation also check for duplication of fielderror tag and actionerror tag.
12 years ago

Hi i have face the same problem and sorted out here is the solution:

Struts2 reads the file prepare tmp file and delete the tmp file after execute method
solution:

jsp code


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<s:head />
</head>
<body>
<s:form action="fileUpload" method="post" enctype="multipart/form-data" >
<s:file name="userImage" label="User Image" />
<s:submit />
</s:form>
</body>
</html>

Action Class

import java.io.File;

import org.apache.commons.io.FileUtils;

import com.opensymphony.xwork2.ActionSupport;

public class FileUploadAction extends ActionSupport{



/**
* Added serial version id
*/
private static final long serialVersionUID = -5138905699893319423L;

private File userImage;

private String userImageContentType;

private String userImageFileName;

private File upload;//The actual file
private String uploadContentType; //The content type of the file
private String uploadFileName; //The uploaded file name
private String fileCaption;//The caption of the file entered by user

public String execute() throws Exception {

try{

String fullFileName = "/opt/glassfish/domains/domain1/logs/myFile.txt;
File theFile = new File(fullFileName);

FileUtils.copyFile(userImage, theFile);

} catch (Exception e) {

addActionError(e.getMessage());

}


return SUCCESS;

}
public String getFileCaption() {
return fileCaption;
}
public void setFileCaption(String fileCaption) {
this.fileCaption = fileCaption;
}
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
public String getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}


public File getUserImage() {
return userImage;
}

public void setUserImage(File userImage) {
this.userImage = userImage;
}

public String getUserImageContentType() {
return userImageContentType;
}

public void setUserImageContentType(String userImageContentType) {
this.userImageContentType = userImageContentType;
}

public String getUserImageFileName() {
return userImageFileName;
}

public void setUserImageFileName(String userImageFileName) {
this.userImageFileName = userImageFileName;
}



}

struts xml

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


<struts>
<package name="fileUploadPackage" extends="struts-default">
<interceptors>
<interceptor-stack name="fileUploadStack">
<interceptor-ref name="exception" />
<interceptor-ref name="alias" />
<interceptor-ref name="servletConfig" />
<interceptor-ref name="prepare" />
<interceptor-ref name="i18n" />
<interceptor-ref name="chain" />
<interceptor-ref name="debugging" />
<interceptor-ref name="profiling" />
<interceptor-ref name="scopedModelDriven" />
<interceptor-ref name="modelDriven" />
<interceptor-ref name="fileUpload">
<param name="maximumSize">10240</param>
<param name="allowedTypes">image/jpeg,image/gif,image/png</param>
</interceptor-ref>
<interceptor-ref name="checkbox" />
<interceptor-ref name="staticParams" />
<interceptor-ref name="actionMappingParams" />
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*</param>
</interceptor-ref>
<interceptor-ref name="conversionError" />
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>

<action name="fileUpload" class="vaannila.FileUploadAction">
<result name="input">/index.jsp</result>
<result name="success">/success.jsp</result>
</action>
</package>
</struts>

best of luck.

12 years ago