Re: update a complex object through struts2
2011/3/20 Martin Gainty > Another common approach is to postfix the method name and set it off with > an exclamation point (aka "bang"), underscore, or other special character. > >- "action=TaskAction_add" >- "action=TaskAction_update" > > To use a postfix wildcard, just move the asterisk and add an underscore. > > > > From the framework's perspective, a wildcard mapping creates a new > "virtual" mapping with all the same attributes as a conventional, static > mapping. As a result, you can use the expanded wildcard name as the name of > validation, type conversion, and message resource files, just as if it were > an Action name (which it is!). > >- TaskAction_add-validation.xml >- TaskAction_update-conversion.xml > > > here is an example of TaskAction_add-validation.xml: > > "-//OpenSymphony Group//XWork Validator 1.0.2//EN" > "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd";> > > > > > > > > > http://struts.apache.org/2.0.14/docs/action-configuration.html > > you should use discrete atomic names for field name attribute so change > I am not exactly sure why I have to use this vilidator in my case? > > > to > "#NameOfActionClass.NameOfMapinActionClassToPopulateFrom"/> > > http://struts.apache.org/2.0.14/docs/radio.html > I know the common usage,but I am not sure how to set it with the Enum type. Just for my case,it seems that the "" does not work. > > use of iterators: > > > ">oddeven"> > > > > > > > test="!#customerStatus.last">, > > > > > > > This is the usage of s:iterator. I know it yet. Now my biggest problem is how to collect information from the form and create the nested object-- Task (including it TaskSteps,Operators,name setted) by struts. -- Also,suppose all of these question are solved which I mean the value can be sent to the server side,so a new object of "Task" will be created by struts,since I am update this task,so this task must own a id in the db,I have the following things to do: 1)get the being updated Task from the db from the id. 2)copy all the field attributes of the Task object created by struts to the Task object in the db,this is crazy,since there are so many fields in the task,and even is field "List" also own in in the db,I may make a duplicate object and save it to db. Any good ideas about this? > Martin Gainty > __ > Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité > > Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene > Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte > Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht > dient lediglich dem Austausch von Informationen und entfaltet keine > rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von > E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen. > > Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le > destinataire prévu, nous te demandons avec bonté que pour satisfaire informez > l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci > est interdite. Ce message sert à l'information seulement et n'aura pas > n'importe quel effet légalement obligatoire. Étant donné que les email > peuvent facilement être sujets à la manipulation, nous ne pouvons accepter > aucune responsabilité pour le contenu fourni. > > > > > > > > From: apachemav...@gmail.com > > Date: Sun, 20 Mar 2011 19:20:54 +0800 > > Subject: Fwd: update a complex object through struts2 > > To: user@struts.apache.org > > > > > -This post is orignal sent to Martin Gainty. > > > > It seems he maybe busy now,so I post it to the list and wonder if any > other > > guys can do me a favor. > > > > --- > > -- Forwarded message -- > > From: maven apache > > Date: 2011/3/19 > > Subject: Re: update a complex object through struts2 > > To: Martin Gainty > > > > > > Thank you very much for your attention and patience. > > > > The following is my codes,after trying the whole afternoon,I just can > make > > the adding task page,thougth there is also some problem: > > > > > > I have a class named Task. > > > > class
Fwd: update a complex object through struts2
-This post is orignal sent to Martin Gainty. It seems he maybe busy now,so I post it to the list and wonder if any other guys can do me a favor. --- -- Forwarded message -- From: maven apache Date: 2011/3/19 Subject: Re: update a complex object through struts2 To: Martin Gainty Thank you very much for your attention and patience. The following is my codes,after trying the whole afternoon,I just can make the adding task page,thougth there is also some problem: I have a class named Task. class Task{ private int id; private String name; private List managers; //the operator who will be responsible for this task private List steps; //the required steps to complete this task //getter and setter } class TaskStep{ private int id; private String name; private List operators; //the operator who will directly do this job private Status status; // the status of this step(complted or not) } enum Status{ ongoing,done; } My Action TaskAction(used to update and add task) class TaskAction extends ActionSupport{ private int taskid; private List allOpInDb; private Task task; public String updatePage(){ //retrive the Task of id "takid", task=new TaskDaoImpl().queryById(taskid); // put it in the valuestack,so it can be referd in thejsp page //initization the allOpInDb allOpInDb=new OperatorDaoImpl().list(); return "updatePage"; } public String update(){ // } public String addPage(){ //initization the allOpInDb allOpInDb=new OperatorDaoImpl().list(); } public String add(){ // } } The struts.xml(core part) /jsp/updatePage.jsp /jsp/addPage.jsp Now I have pages which are used to add/update a task(including its steps): By entering : http:///task_addPage; I get the addpage: Steps: Step Name Step Operators Step Status Question: 1)when to add the "[index]" syntax? For example: "task.steps[0].id" use this syntax,but "task.managers.id" does not. Both the steps and the managers are all java.uitl.List. I wonder why? 2)how to list the value of the enum type,in my case how to list "ongoing","done" as two radio button in the page? The above is the adding task page,and I have to build another page,updating task. By entering :http://xxx/task_updatePage?taskid=1<http://xxx/task_updatePage> I get the update page,It seems that it is more complex than the adding page: Step Name Step Operators Step Status Make this step up Make this step down As you can see,in the form I can just read the value form the stack,but I do not know how to set the "name" attribute of each input. Also,suppose all of these question are solved which I mean the value can be sent to the server side,so a new object of "Task" will be created by struts,since I am update this task,so this task must own a id in the db,I have the following things to do: 1)get the being updated Task from the db from the id. 2)copy all the field attributes of the Task object created by struts to the Task object in the db,this is crazy,since there are so many fields in the task,and even is field "List" also own in in the db,I may make a duplicate object and save it to db. Any secury problem? BTW,the tag "s:select" with property of "multiple='true'" will take too much space in the page if the "list" own a large size,any way to slove this?
Re: update a complex object through struts2
Hi: I update my question and make a simple example, Please take a look this example:http://jsfiddle.net/mbwwg/ Suppose the name of the task is "Task1",it belog to Department2,and it own two tasksteps(step01 and step02). And the operators of step1 contain "jhon" and "bill",while the step02 contain "bill" and "susan".Also there are other attributes. The user can modfiy the project name,group of the project,and the name,status of its tasks. Also he can add or remove the operator of one task. So, I can just read the attribute to page,but I do not know how to submit the updated information to the server side when a user make some modifination.
update a complex object through struts2
Hi: I meet some problem when I use struts as the mvc framework in my app, They are the core classes: *Task{ private int id; private String name; private List steps; } TaskStep{ public int id; private String name; private Date startDate; private TaskStatus status; private List operators; } Operator{ private int id; private String name; } Enum TaskStatus{ start,doing,completed }* So,a task objec has relationship with so many other objects, now I have a page to update(modify) a speified task: I can read each attribute of the task and display it in the page,but I do not know when user modify something(for example,modify the name of or add/remove some operators of one its step. At this time,how to transfer these information to the server side and update it in the db? BTW,I use the hiberante as the dao.
iterate the list values defined inthe tile
iterate the list values defined inthe tile
Re: Why do we need the set/push tag?
2011/1/6 Aaron Brown > Generally speaking, when you use a struts tag and you do NOT specify > an object, the tag will default to using the object at the top of the > stack. > The push tag lets you force a specific object to be at the top > of the stack, Well,is it the action's **responsibility to prepare the data which to be used in the view/page? so you can write generic, reusable jsp code (like > fragments, etc.) that doesn't reference the object name directly and > instead operates only on its generic properties. > > - Aaron > > On Thu, Jan 6, 2011 at 5:54 AM, maven apache > wrote: > > Hi > > I am learning the struts tag,however I can't understand why we need the > > set/push/bean tag? > > In my opinion,the views like jsp just need to pull data from the > > Actioncontext and render them. What's the advantage of pushing new data > to > > context? > > I am using my phone to ask this question,so I can't express more,hope you > > guys know what I am talking about.^_^ > > > > > > -- > Aaron Brown : aa...@thebrownproject.com > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >
Why do we need the set/push tag?
Hi I am learning the struts tag,however I can't understand why we need the set/push/bean tag? In my opinion,the views like jsp just need to pull data from the Actioncontext and render them. What's the advantage of pushing new data to context? I am using my phone to ask this question,so I can't express more,hope you guys know what I am talking about.^_^
How to save the valuestack when using the redirectaction result type
Hi: In my application I first use the chain result type for one action:"loginSub". If login success,user should be taken to the manager page. This is the core content in struts.xml: . manager /secure /jsp/login.jsp /jsp/login.jsp /jsp/secure/manager.jsp loginPage / It works,when user login,the page will show the content in the /jsp/secure/manager.jsp. However the value in the browser address bar is also something like: http://localhost:8080/Test/loginSub.action. So once user refresh this page,it will result in a relogin. After read the struts2 tutorial,I found the result type of "redirectAction",it will change the value of the Browser address bar. I change the "loginSub" action: <. the authentication interceptor>... manager /secure /jsp/login.jsp /jsp/login.jsp Now after login,the browser address bar will change to : *http://localhost:8080/Test/secure/manager.action* Now no matter how frequently user refresh the page,it will not cause a relogin. However I found that I can not get some properties in the LoginAction. I have a struts tag in the manager.jsp: ** Now using the redirectAction result type,I have no idea to get this value. Any ideas? BWT: 1)what's the difference between "Dispatcher Result","Redirect Result","Redirect Action Result" and "Chain Result"? I read the contents at "struts.apache.org/2.2.1/docs/result-types.html",but I am not exactly sure its meaning. 2)My action "manager" is a authentication required action,so I add a authentication interceptor for them. But how about user enter the url directly like this: * http://localhost:8080/Test/jsp/secure/manager.jsp?* If so ,I do not think the interceptor will work. How do you guys slove this problem?
Re: change the filename to be downloaded
2010/12/29 Dave Newton > I didn't misunderstand you at all; now you're asking a different question. > > Have you checked that the content type is correct in the headers? > :) Thanks, I will have a try. > > Dave > On Dec 28, 2010 7:18 PM, "maven apache" wrote: > > I am afraid you misundersatnd me. > > > > *I mean jus the "contentType"* > > > > Nomatter I set it to text/plain or application/vnd/ms-word,I can not see > the > > difference. So I wonder if there is relly no difference. > > > > 2010/12/29 Dave Newton > > > >> http://struts.apache.org/2.x/docs/stream-result.html > >> > >> On Tue, Dec 28, 2010 at 7:35 PM, maven apache >> >wrote: > >> > >> > Hi jlmagc: > >> > > >> > How do you set the contenttype in the result of the action? > >> > > >> > 2010/12/27 maven apache > >> > > >> > > > >> > > > >> > > 2010/12/27 > >> > > > >> > >> That's right. I don't have access to the code now, but I will try > to > >> > send > >> > >> it later. Check the syntax, I'm sure you will find some > >> > > > >> > > > >> > > No hurry. :) Thanks. > >> > > > >> > > > >> > >> examples > >> > >> Sent via BlackBerry from T-Mobile > >> > >> > >> > >> -Original Message- > >> > >> From: maven apache > >> > >> Date: Mon, 27 Dec 2010 20:42:15 > >> > >> To: Struts Users Mailing List > >> > >> Reply-To: "Struts Users Mailing List" > >> > >> Subject: Re: change the filename to be downloaded > >> > >> > >> > >> 2010/12/27 > >> > >> > >> > >> > I do the same, but with an excel, and I'm able to write the excel > >> > >> direclty > >> > >> > to an input stream. I don't know about word, but I suppouse it > would > >> > be > >> > >> the > >> > >> > same. Also, I think you can set a getFileName method in the > action, > >> > and > >> > >> it > >> > >> > can be used as follows > >> > >> > > >> > >> > > >> > >> write the excel direclty to an input stream > >> > >> > >> > >> ? How,the wirte method write(OutputStream out),isn't it? > >> > >> > >> > >> > >> > >> > >> > >> name="contentDisposition">attachment;filename="{fileName}" > >> > >> > > >> > >> * >> > >> name="contentDisposition">attachment;filename="{fileName}"* > >> > >> > >> > >> My god. It can be used in this way? I do not know before. Thanks.:) > >> > >> > >> > >> > Sent via BlackBerry from T-Mobile > >> > >> > > >> > >> > -Original Message- > >> > >> > From: maven apache > >> > >> > Date: Mon, 27 Dec 2010 19:26:16 > >> > >> > To: Struts Users Mailing List > >> > >> > Reply-To: "Struts Users Mailing List" > >> > >> > Subject: change the filename to be downloaded > >> > >> > > >> > >> > Hi: > >> > >> > In myapplication,I have to generate a ms-word file(I use the > apache > >> > >> poi). > >> > >> > 1)first I save the generated file to disk. > >> > >> > 2)set the inputstream according to the file.Of course,the action > >> > result > >> > >> > type > >> > >> > is already set to stream. > >> > >> > > >> > >> > here is a exmapleI found about file downing: > >> > >> > http://www.mkyong.com/struts2/struts-2-download-file-example/ > >> > >> > > >> > >> > Now,my problem is how to set the filename? Since the filename is > set > >> > in > >> > >> the > >> > >> > action in the struts.xml. > >> > >> > > >> > >> > >> > >> name="contentDisposition">attachment;filename="fileABC.txt" > >> > >> > > >> > >> > Is there any way can set the filename dynamicly? > >> > >> > > >> > >> > BTW,is there some idea can avoid the step for storing the tmp > file > >> in > >> > >> the > >> > >> > disk? > >> > >> > > >> > >> > > >> > >> > >> > >> > >> > > > >> > > >> >
Re: change the filename to be downloaded
I am afraid you misundersatnd me. *I mean jus the "contentType"* Nomatter I set it to text/plain or application/vnd/ms-word,I can not see the difference. So I wonder if there is relly no difference. 2010/12/29 Dave Newton > http://struts.apache.org/2.x/docs/stream-result.html > > On Tue, Dec 28, 2010 at 7:35 PM, maven apache >wrote: > > > Hi jlmagc: > > > > How do you set the contenttype in the result of the action? > > > > 2010/12/27 maven apache > > > > > > > > > > > 2010/12/27 > > > > > >> That's right. I don't have access to the code now, but I will try to > > send > > >> it later. Check the syntax, I'm sure you will find some > > > > > > > > > No hurry. :) Thanks. > > > > > > > > >> examples > > >> Sent via BlackBerry from T-Mobile > > >> > > >> -Original Message- > > >> From: maven apache > > >> Date: Mon, 27 Dec 2010 20:42:15 > > >> To: Struts Users Mailing List > > >> Reply-To: "Struts Users Mailing List" > > >> Subject: Re: change the filename to be downloaded > > >> > > >> 2010/12/27 > > >> > > >> > I do the same, but with an excel, and I'm able to write the excel > > >> direclty > > >> > to an input stream. I don't know about word, but I suppouse it would > > be > > >> the > > >> > same. Also, I think you can set a getFileName method in the action, > > and > > >> it > > >> > can be used as follows > > >> > > > >> > > > >> write the excel direclty to an input stream > > >> > > >> ? How,the wirte method write(OutputStream out),isn't it? > > >> > > >> > > >> > > >> name="contentDisposition">attachment;filename="{fileName}" > > >> > > > >> * > >> name="contentDisposition">attachment;filename="{fileName}"* > > >> > > >> My god. It can be used in this way? I do not know before. Thanks.:) > > >> > > >> > Sent via BlackBerry from T-Mobile > > >> > > > >> > -Original Message- > > >> > From: maven apache > > >> > Date: Mon, 27 Dec 2010 19:26:16 > > >> > To: Struts Users Mailing List > > >> > Reply-To: "Struts Users Mailing List" > > >> > Subject: change the filename to be downloaded > > >> > > > >> > Hi: > > >> > In myapplication,I have to generate a ms-word file(I use the apache > > >> poi). > > >> > 1)first I save the generated file to disk. > > >> > 2)set the inputstream according to the file.Of course,the action > > result > > >> > type > > >> > is already set to stream. > > >> > > > >> > here is a exmapleI found about file downing: > > >> > http://www.mkyong.com/struts2/struts-2-download-file-example/ > > >> > > > >> > Now,my problem is how to set the filename? Since the filename is set > > in > > >> the > > >> > action in the struts.xml. > > >> > > > >> > > >> name="contentDisposition">attachment;filename="fileABC.txt" > > >> > > > >> > Is there any way can set the filename dynamicly? > > >> > > > >> > BTW,is there some idea can avoid the step for storing the tmp file > in > > >> the > > >> > disk? > > >> > > > >> > > > >> > > >> > > > > > >
Re: change the filename to be downloaded
Hi jlmagc: How do you set the contenttype in the result of the action? 2010/12/27 maven apache > > > 2010/12/27 > >> That's right. I don't have access to the code now, but I will try to send >> it later. Check the syntax, I'm sure you will find some > > > No hurry. :) Thanks. > > >> examples >> Sent via BlackBerry from T-Mobile >> >> -Original Message- >> From: maven apache >> Date: Mon, 27 Dec 2010 20:42:15 >> To: Struts Users Mailing List >> Reply-To: "Struts Users Mailing List" >> Subject: Re: change the filename to be downloaded >> >> 2010/12/27 >> >> > I do the same, but with an excel, and I'm able to write the excel >> direclty >> > to an input stream. I don't know about word, but I suppouse it would be >> the >> > same. Also, I think you can set a getFileName method in the action, and >> it >> > can be used as follows >> > >> > >> write the excel direclty to an input stream >> >> ? How,the wirte method write(OutputStream out),isn't it? >> >> >> > > name="contentDisposition">attachment;filename="{fileName}" >> > >> *> name="contentDisposition">attachment;filename="{fileName}"* >> >> My god. It can be used in this way? I do not know before. Thanks.:) >> >> > Sent via BlackBerry from T-Mobile >> > >> > -Original Message- >> > From: maven apache >> > Date: Mon, 27 Dec 2010 19:26:16 >> > To: Struts Users Mailing List >> > Reply-To: "Struts Users Mailing List" >> > Subject: change the filename to be downloaded >> > >> > Hi: >> > In myapplication,I have to generate a ms-word file(I use the apache >> poi). >> > 1)first I save the generated file to disk. >> > 2)set the inputstream according to the file.Of course,the action result >> > type >> > is already set to stream. >> > >> > here is a exmapleI found about file downing: >> > http://www.mkyong.com/struts2/struts-2-download-file-example/ >> > >> > Now,my problem is how to set the filename? Since the filename is set in >> the >> > action in the struts.xml. >> > >> > > name="contentDisposition">attachment;filename="fileABC.txt" >> > >> > Is there any way can set the filename dynamicly? >> > >> > BTW,is there some idea can avoid the step for storing the tmp file in >> the >> > disk? >> > >> > >> >> >
Re: change the filename to be downloaded
2010/12/27 > That's right. I don't have access to the code now, but I will try to send > it later. Check the syntax, I'm sure you will find some No hurry. :) Thanks. > examples > Sent via BlackBerry from T-Mobile > > -----Original Message- > From: maven apache > Date: Mon, 27 Dec 2010 20:42:15 > To: Struts Users Mailing List > Reply-To: "Struts Users Mailing List" > Subject: Re: change the filename to be downloaded > > 2010/12/27 > > > I do the same, but with an excel, and I'm able to write the excel > direclty > > to an input stream. I don't know about word, but I suppouse it would be > the > > same. Also, I think you can set a getFileName method in the action, and > it > > can be used as follows > > > > > write the excel direclty to an input stream > > ? How,the wirte method write(OutputStream out),isn't it? > > > > attachment;filename="{fileName}" > > > *attachment;filename="{fileName}"* > > My god. It can be used in this way? I do not know before. Thanks.:) > > > Sent via BlackBerry from T-Mobile > > > > -Original Message- > > From: maven apache > > Date: Mon, 27 Dec 2010 19:26:16 > > To: Struts Users Mailing List > > Reply-To: "Struts Users Mailing List" > > Subject: change the filename to be downloaded > > > > Hi: > > In myapplication,I have to generate a ms-word file(I use the apache poi). > > 1)first I save the generated file to disk. > > 2)set the inputstream according to the file.Of course,the action result > > type > > is already set to stream. > > > > here is a exmapleI found about file downing: > > http://www.mkyong.com/struts2/struts-2-download-file-example/ > > > > Now,my problem is how to set the filename? Since the filename is set in > the > > action in the struts.xml. > > > > name="contentDisposition">attachment;filename="fileABC.txt" > > > > Is there any way can set the filename dynamicly? > > > > BTW,is there some idea can avoid the step for storing the tmp file in the > > disk? > > > > > >
Re: change the filename to be downloaded
2010/12/27 > I do the same, but with an excel, and I'm able to write the excel direclty > to an input stream. I don't know about word, but I suppouse it would be the > same. Also, I think you can set a getFileName method in the action, and it > can be used as follows > > write the excel direclty to an input stream ? How,the wirte method write(OutputStream out),isn't it? > attachment;filename="{fileName}" > *attachment;filename="{fileName}"* My god. It can be used in this way? I do not know before. Thanks.:) > Sent via BlackBerry from T-Mobile > > -Original Message- > From: maven apache > Date: Mon, 27 Dec 2010 19:26:16 > To: Struts Users Mailing List > Reply-To: "Struts Users Mailing List" > Subject: change the filename to be downloaded > > Hi: > In myapplication,I have to generate a ms-word file(I use the apache poi). > 1)first I save the generated file to disk. > 2)set the inputstream according to the file.Of course,the action result > type > is already set to stream. > > here is a exmapleI found about file downing: > http://www.mkyong.com/struts2/struts-2-download-file-example/ > > Now,my problem is how to set the filename? Since the filename is set in the > action in the struts.xml. > > attachment;filename="fileABC.txt" > > Is there any way can set the filename dynamicly? > > BTW,is there some idea can avoid the step for storing the tmp file in the > disk? > >
change the filename to be downloaded
Hi: In myapplication,I have to generate a ms-word file(I use the apache poi). 1)first I save the generated file to disk. 2)set the inputstream according to the file.Of course,the action result type is already set to stream. here is a exmapleI found about file downing: http://www.mkyong.com/struts2/struts-2-download-file-example/ Now,my problem is how to set the filename? Since the filename is set in the action in the struts.xml. attachment;filename="fileABC.txt" Is there any way can set the filename dynamicly? BTW,is there some idea can avoid the step for storing the tmp file in the disk?
Re: any option parameter for populating parameters to my bean?
2010/12/9 Dave Newton > Strange, I believe this question was asked by someone else with no name-- > try > searching the archives. > How? Using the nabble? I can not access Nabble.com :( > > Dave > > On Thu, Dec 9, 2010 at 4:37 AM, maven apache > wrote: > > > My action: > > > > public class MyAction{ > > private MyBean bean; > > //getter setter. > > } > > > > public class MyBean{ > > private Date start; > > //setter getter > > } > > > > > > > > > If the value of start is '2010-12-12 12:00:00',the parmameter start can > be > > populated to my bean correctly,however if the format is '2010/12/12 > > 12:00:00',it will show me a error "can not parser the date',so I wonder > if > > there is any parameter can be set for populating parameter? > > >
Re: any option parameter for populating parameters to my bean?
2010/12/10 Li Ying > Can you show us the entire Exception stack? > > I guess, this may be a type conversion error. > > According to this struts2 documents: > > http://struts.apache.org/2.x/docs/type-conversion.html#TypeConversion-BuiltinTypeConversionSupport > > "XWork will automatically handle the most common type conversion for > you. This includes support for converting to and from Strings for each > of the following: " > > "dates - uses the SHORT format for the Locale associated with the > current request" > > > So, I think the following things should be checked first: > What the "Locale associated with the current request" is? > What the short format of this locale is? > Is your input string "2010/12/12 12:00:00" match this short format? > > The default date converter looks like depends on the "Locale > associated with the current request". > So, the format it takes will vary. > > If you want this, you need *create a new converter* which takes a fixed > date format. > Thanks,This is just what I need. > > I did this before, it's not difficult, if you following the document. > > > > 2010/12/9 maven apache : > > My action: > > > > public class MyAction{ > > private MyBean bean; > > //getter setter. > > } > > > > public class MyBean{ > > private Date start; > > //setter getter > > } > > > > > > > > > If the value of start is '2010-12-12 12:00:00',the parmameter start can > be > > populated to my bean correctly,however if the format is '2010/12/12 > > 12:00:00',it will show me a error "can not parser the date',so I wonder > if > > there is any parameter can be set for populating parameter? > > > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >
any option parameter for populating parameters to my bean?
My action: public class MyAction{ private MyBean bean; //getter setter. } public class MyBean{ private Date start; //setter getter } If the value of start is '2010-12-12 12:00:00',the parmameter start can be populated to my bean correctly,however if the format is '2010/12/12 12:00:00',it will show me a error "can not parser the date',so I wonder if there is any parameter can be set for populating parameter?
the result of the interceptor
Hi: I am reading the book Struts2InAction,it is rather powerful. And I thought someting funny when reading the interceptor chapter: Example: public String intercept(ActionInvocation invocation) throws Exception { long startTime = System.currentTimeMillis(); //1 String result = invocation.invoke(); //2 long executionTime = System.currentTimeMillis() - startTime; ... log the time ... return result; } The following is quoted from the book: >Either way, when invoke() >returns, a result has already been rendered. In other words, the response page has >already been sent back to the client Since the response page has been sent to client .So I wonder if I return null after calling the invocation.invoke()? BTW,I do not have the development environment for a test nowtime,so I ask here,hoping not distuirbing you guys. :)
Re: any ideas about handle user's relogin using interceptor?
Thanks! So the way I use the interceptor is right? Nothing have to be changed except saving the session id intead of sessin it self? 2010/12/3 Li Ying > I read your code, and noticed one thing. > > You saved the whole HttpSession instance in Map, this will waste memory. > > The information you really need is just the SessionID, but not the > whole Session. > > SessionID can be retrieved from HttpSession.getId(); > > > See: > > http://download.oracle.com/javaee/5/api/javax/servlet/http/HttpSession.html#getId%28%29 > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >
Re: any ideas about handle user's relogin using interceptor?
Hi: Thanks for Liying's answer,I have a try just now,and it works well(say the result,it meet my requirements). However I found that my codes are rathre ugly,have no logic. So I wonder any one can spare some time to have a check? Notice:I remove the jars in the WEB-INF/lib. You should add it yourself. BWT,I wonder if saving all the session information in the server side is a good idea,if too many user login,the memeory is a problem,but if save the session in the db or file system,it will slow down the response speed. :( However,thanks Li ying and other guys anyway. 2010/12/2 Li Ying > ActionContext is just a wrap class for convenience. > > > If you need the real HttpSession. > You should get the HttpRequest first, from > ServletActionContext.getRequest(). > > See: > > http://struts.apache.org/2.2.1/struts2-core/apidocs/org/apache/struts2/ServletActionContext.html > > And then, you can get the HttpSession from > HttpServletRequest.getSession(); > > See: > > http://download.oracle.com/javaee/5/api/javax/servlet/http/HttpServletRequest.html > > > > > 2010/12/2 maven apache : > > Thanks,your answer can not be detailed more. :) > > > > only a little confused. > > > > Map attibutes = ActionContext.getContext().getSession() > > > > I can get the session this manner,but it seems that it is a Map,not a > > HttpSession,so what is the id? > > > > I have debug the session yet,and I found there is a property in the Map: > > struts.troken,is this unique can be used as the session id? > > > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > > StrutsDemo.rar Description: application/rar - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: any ideas about handle user's relogin using interceptor?
Thanks,your answer can not be detailed more. :) only a little confused. Map attibutes = ActionContext.getContext().getSession() I can get the session this manner,but it seems that it is a Map,not a HttpSession,so what is the id? I have debug the session yet,and I found there is a property in the Map: struts.troken,is this unique can be used as the session id? 2010/12/2 Li Ying > The problem will be: > > (1)How to save the information about who is logged in from which session. > > and > > (2)How to check this information before every action execution > > > For problem 1, if you only have one app server, you can save this > information in global variable, if you need support multi app servers, > you can save it into DB. > The data structure should like > Map (in global variable) > > or > TABLE (UserID VARCHAR, SessionID VARCHAR) (in DB) > > > For problem 2, you are right, Interceptor will be a good choice. > > > > > I think the whole architecture should likes: > > (1)After user login, save the logged in status into global variable or > DB, and into current session. > > (2)Before every action execution, extract logged in user id from > current session, and then check the global variable or DB, see if this > user is logged in from the same session. > If the same user is logged in from some session else, this means > he/she has re-logged in from somewhere else, so you can remove the > logged in status from current session, and then force the user login > again. > > > > For example: > > (1)UserA, logged in from ComputerA. > Let's say the session is SessionA. > > So in SessionA, the logged in user ID will be UserA. > And in the global variable or DB, UserA will be marked "logged in from > SessionA" > > (2)When the same user login from ComputerB. > Let's say SessionB. > In SessionB, the logged in user ID will be UserA. > And in the global variable or DB, the logged in status of UserA will > be overwritten by "logged in from SessionB" > > (3)Request any page again from ComputerA. > The Interceptor can extract the logged in user id (which will be > UserA) from current Session (which will be SessionA). > And extract the logged in status from global variable or DB, > which will be "logged in from SessionB", and different from current > session. > > So the Interceptor can say, UserA has re-logged in from some where else. > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >
any ideas about handle user's relogin using interceptor?
Hi: In our application,if user logined in one browser or computer,then he/she login in another brower/computer,the first login information should be removed. For example. User login in computer A,then he did not logout and then login in computer B,then if he back to computer A do some Authorization required operation,then he should be informed for relogin in computer A, of course,the login information in computer B should be removed now. It seems that the Interceptor can be used here,since the Interceptor's scope is method(just my own understand),but I have no idea how to remove the old login information. Any ideas?
Re: binding paramters in struts2 without the form
Thank you very much. I found the ModelDriven is very useful. With it I donot have to add the parametes to the action as the fields. :) 2010/11/29 Maurizio Cucchiara > If you don't want dot notation, I should consider using ModelDriven > interface. Take a look at > > http://struts.apache.org/2.2.1/struts2-core/apidocs/com/opensymphony/xwork2/ModelDriven.html > > 2010/11/29 maven apache : > > > Maurizio Cucchiara's answer seems like a good idea excepting I have add > the > > personbean.name=xxx. (The personBean is required) > > > > I do not want to use the ParameterAware,I want to use a object save some > > default value of some parameters rather than the map. > > > > Also,if using the parameterAware,why not using the > > ActionContext.getcontext().getParameters() instead? > > > > > > > >> > >> Jason > >> > >> On Mon, Nov 29, 2010 at 5:25 AM, maven apache >> >wrote: > >> > >> > 2010/11/29 Maurizio Cucchiara > >> > > >> > > Frankly, even after I watched your question on stackoverflow, I > can't > >> > > figure out what you meant. > >> > > > >> > :( > >> > > >> > > You don't necessary need struts tag, you can pass parameter via http > >> > > request, so, for example, if you enter > >> > > http://your_url:your_port > >> > > /your_struts.action?personBean.firstName=your_name > >> > > in the address bar > >> > > > >> > Thanks. > >> > > >> > I use the http://xxx.action?firstName=name. So it does not work. > >> > > >> > > >> > http://your_url:your_port > >> > /your_struts.action?personBean.firstName=your_name > >> > > >> > I do not know the parameter can be sent this way!!! > >> > Thanks. > >> > > >> > > >> > > struts will try to inject value inside your bean. > >> > > > >> > > Does this answer your question? > >> > > > >> > > 2010/11/29 maven apache : > >> > > > BTW,this is a cross post at > >> > > > stackoverflow< > >> > > > >> > > >> > http://stackoverflow.com/questions/4300409/binding-paramters-in-struts2-without-the-form > >> > > > > >> > > > . > >> > > > > >> > > > 2010/11/29 maven apache > >> > > > > >> > > >> > >> > > >> > >> > > >> > >> > > >>/> > >> > > >> > >> > > >> > >> > > >> > >> > > >> > >> > > >> > >> > > >> public class Register extends ActionSupport { > >> > > >> > >> > > >> > >> > > >> private static final long serialVersionUID = 1L; > >> > > >> > >> > > >> > >> > > >> private Person personBean; > >> > > >> > >> > > >> > >> > > >> // > >> > > >> } > >> > > >> > >> > > >> > >> > > >> Using the s:form tag one can bind the parameter from the client > to a > >> > > java > >> > > >> object(the personBean in the Register action). > >> > > >> > >> > > >> However it seems that the struts tag is required,but my action is > >> not > >> > > >> called from the web form,so any way? > >> > > >> > >> > > >> And I tried this way: > >> > > >> > >> > > >> public class ParaWrapper(){ > >> > > >> > >> > > >> > >> > > >> private String firstName; > >> > > >> > >> > > >> > >> > > >> public void setFirstName(String ..){ > >> > > >> > >> > > >> > >> > > >> this.firstName=... > >> > > >> > >> > > >> > >> > > >> } > >> > > >> //the getter of firstName > >> > > >> > >> > > >> > >> > > >> public > >> > > >> > >> > > >> } > >> > > >> > >> > > >> > >> > > >> public MyAction extends ActionSupport{ > >> > > >> > >> > > >> > >> > > >> private ParaWrapper wrapper; > >> > > >> > >> > > >> > >> > > >> public void setXXX()... > >> > > >> > >> > > >> > >> > > >> public void getXXX()... > >> > > >> > >> > > >> > >> > > >> public void execute(){ > >> > > >> > >> > > >> > >> > > >> System.out.println(wrapper.getFirstName()); //here I can not > get > >> > the > >> > > parameters,it seems that the parameters are not populated to this > >> object. > >> > > >> > >> > > >> > >> > > >> } > >> > > >> } > >> > > >> > >> > > >> It does not work since struts does not know which object should > be > >> > used > >> > > to bind the parameter. > >> > > >> > >> > > >> > >> > > >> I wonder there is any way to using this manner? > >> > > >> > >> > > >> > >> > > > > >> > > > >> > > > >> > > > >> > > -- > >> > > Maurizio Cucchiara > >> > > > >> > > > - > >> > > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > >> > > For additional commands, e-mail: user-h...@struts.apache.org > >> > > > >> > > > >> > > >> > > > > > > -- > Maurizio Cucchiara > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >
Re: binding paramters in struts2 without the form
2010/11/29 Jason Ferguson > Struts will not automatically populate fields based on parameters passed > via > the URL. Your action will need to implement the ParameterAware interface, > and the setParameters(Map parameters) method. Then you > can > use the map to populate your fields. > Maurizio Cucchiara's answer seems like a good idea excepting I have add the personbean.name=xxx. (The personBean is required) I do not want to use the ParameterAware,I want to use a object save some default value of some parameters rather than the map. Also,if using the parameterAware,why not using the ActionContext.getcontext().getParameters() instead? > > Jason > > On Mon, Nov 29, 2010 at 5:25 AM, maven apache >wrote: > > > 2010/11/29 Maurizio Cucchiara > > > > > Frankly, even after I watched your question on stackoverflow, I can't > > > figure out what you meant. > > > > > :( > > > > > You don't necessary need struts tag, you can pass parameter via http > > > request, so, for example, if you enter > > > http://your_url:your_port > > > /your_struts.action?personBean.firstName=your_name > > > in the address bar > > > > > Thanks. > > > > I use the http://xxx.action?firstName=name. So it does not work. > > > > > > http://your_url:your_port > > /your_struts.action?personBean.firstName=your_name > > > > I do not know the parameter can be sent this way!!! > > Thanks. > > > > > > > struts will try to inject value inside your bean. > > > > > > Does this answer your question? > > > > > > 2010/11/29 maven apache : > > > > BTW,this is a cross post at > > > > stackoverflow< > > > > > > http://stackoverflow.com/questions/4300409/binding-paramters-in-struts2-without-the-form > > > > > > > > . > > > > > > > > 2010/11/29 maven apache > > > > > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> public class Register extends ActionSupport { > > > >> > > > >> > > > >> private static final long serialVersionUID = 1L; > > > >> > > > >> > > > >> private Person personBean; > > > >> > > > >> > > > >> // > > > >> } > > > >> > > > >> > > > >> Using the s:form tag one can bind the parameter from the client to a > > > java > > > >> object(the personBean in the Register action). > > > >> > > > >> However it seems that the struts tag is required,but my action is > not > > > >> called from the web form,so any way? > > > >> > > > >> And I tried this way: > > > >> > > > >> public class ParaWrapper(){ > > > >> > > > >> > > > >> private String firstName; > > > >> > > > >> > > > >> public void setFirstName(String ..){ > > > >> > > > >> > > > >> this.firstName=... > > > >> > > > >> > > > >> } > > > >> //the getter of firstName > > > >> > > > >> > > > >> public > > > >> > > > >> } > > > >> > > > >> > > > >> public MyAction extends ActionSupport{ > > > >> > > > >> > > > >> private ParaWrapper wrapper; > > > >> > > > >> > > > >> public void setXXX()... > > > >> > > > >> > > > >> public void getXXX()... > > > >> > > > >> > > > >> public void execute(){ > > > >> > > > >> > > > >> System.out.println(wrapper.getFirstName()); //here I can not get > > the > > > parameters,it seems that the parameters are not populated to this > object. > > > >> > > > >> > > > >> } > > > >> } > > > >> > > > >> It does not work since struts does not know which object should be > > used > > > to bind the parameter. > > > >> > > > >> > > > >> I wonder there is any way to using this manner? > > > >> > > > >> > > > > > > > > > > > > > > > > -- > > > Maurizio Cucchiara > > > > > > - > > > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > > > For additional commands, e-mail: user-h...@struts.apache.org > > > > > > > > >
Re: binding paramters in struts2 without the form
2010/11/29 Maurizio Cucchiara > Frankly, even after I watched your question on stackoverflow, I can't > figure out what you meant. > :( > You don't necessary need struts tag, you can pass parameter via http > request, so, for example, if you enter > http://your_url:your_port > /your_struts.action?personBean.firstName=your_name > in the address bar > Thanks. I use the http://xxx.action?firstName=name. So it does not work. http://your_url:your_port/your_struts.action?personBean.firstName=your_name I do not know the parameter can be sent this way!!! Thanks. > struts will try to inject value inside your bean. > > Does this answer your question? > > 2010/11/29 maven apache : > > BTW,this is a cross post at > > stackoverflow< > http://stackoverflow.com/questions/4300409/binding-paramters-in-struts2-without-the-form > > > > . > > > > 2010/11/29 maven apache > > > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> public class Register extends ActionSupport { > >> > >> > >> private static final long serialVersionUID = 1L; > >> > >> > >> private Person personBean; > >> > >> > >> // > >> } > >> > >> > >> Using the s:form tag one can bind the parameter from the client to a > java > >> object(the personBean in the Register action). > >> > >> However it seems that the struts tag is required,but my action is not > >> called from the web form,so any way? > >> > >> And I tried this way: > >> > >> public class ParaWrapper(){ > >> > >> > >> private String firstName; > >> > >> > >> public void setFirstName(String ..){ > >> > >> > >> this.firstName=... > >> > >> > >> } > >> //the getter of firstName > >> > >> > >> public > >> > >> } > >> > >> > >> public MyAction extends ActionSupport{ > >> > >> > >> private ParaWrapper wrapper; > >> > >> > >> public void setXXX()... > >> > >> > >> public void getXXX()... > >> > >> > >> public void execute(){ > >> > >> > >> System.out.println(wrapper.getFirstName()); //here I can not get the > parameters,it seems that the parameters are not populated to this object. > >> > >> > >> } > >> } > >> > >> It does not work since struts does not know which object should be used > to bind the parameter. > >> > >> > >> I wonder there is any way to using this manner? > >> > >> > > > > > > -- > Maurizio Cucchiara > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >
Re: binding paramters in struts2 without the form
BTW,this is a cross post at stackoverflow<http://stackoverflow.com/questions/4300409/binding-paramters-in-struts2-without-the-form> . 2010/11/29 maven apache > > > > > > > > > > public class Register extends ActionSupport { > > > private static final long serialVersionUID = 1L; > > > private Person personBean; > > > // > } > > > Using the s:form tag one can bind the parameter from the client to a java > object(the personBean in the Register action). > > However it seems that the struts tag is required,but my action is not > called from the web form,so any way? > > And I tried this way: > > public class ParaWrapper(){ > > > private String firstName; > > > public void setFirstName(String ..){ > > > this.firstName=... > > > } > //the getter of firstName > > > public > > } > > > public MyAction extends ActionSupport{ > > > private ParaWrapper wrapper; > > > public void setXXX()... > > > public void getXXX()... > > > public void execute(){ > > > System.out.println(wrapper.getFirstName()); //here I can not get the > parameters,it seems that the parameters are not populated to this object. > > > } > } > > It does not work since struts does not know which object should be used to > bind the parameter. > > > I wonder there is any way to using this manner? > >
binding paramters in struts2 without the form
public class Register extends ActionSupport { private static final long serialVersionUID = 1L; private Person personBean; // } Using the s:form tag one can bind the parameter from the client to a java object(the personBean in the Register action). However it seems that the struts tag is required,but my action is not called from the web form,so any way? And I tried this way: public class ParaWrapper(){ private String firstName; public void setFirstName(String ..){ this.firstName=... } //the getter of firstName public } public MyAction extends ActionSupport{ private ParaWrapper wrapper; public void setXXX()... public void getXXX()... public void execute(){ System.out.println(wrapper.getFirstName()); //here I can not get the parameters,it seems that the parameters are not populated to this object. } } It does not work since struts does not know which object should be used to bind the parameter. I wonder there is any way to using this manner?
Re: how does the namespace work in struts
2010/11/5 Maurizio Cucchiara > Note that without S2 tag you will not appreciate S2 potential. > So I wonder if the web ui are built by some javascript framework for exmaple the ext -we used to build a form by the exe library: var form=new *Ext*.*form*.FormPanel({}); And the form are submitted by a ajax request,so how about the s2 tag at this moment? > Furthermore they are not hard to learn (take a look at > http://struts.apache.org/2.2.1/docs/tag-reference.html) > > 2010/11/5 maven apache : > > :) > > > > In fact the reason I do not want to use tag now is that I do not want > > everything done by the framework,since I am new in struts2,so I want to > > learn struts step by step,I always thought that unless we know how the > > framework work we can not take the most advantage of it. > > > > When I know the work mechanism of the action mapping,then I will use the > tag > > :) > > 2010/11/5 Maurizio Cucchiara > > > >> Struts tags are not mandatory in order to deploy an application, but > >> as Li suggested make your life easier :) > >> > >> 2010/11/5 maven apache : > >> > Thanks for all your guys reply. > >> > > >> > That's to say I have no choice but using the struts tag if I decide to > >> use > >> > the struts?? > >> > > >> > >> -- > >> Maurizio Cucchiara > >> > >> - > >> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > >> For additional commands, e-mail: user-h...@struts.apache.org > >> > >> > > > > > > -- > Maurizio Cucchiara > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >
Re: how does the namespace work in struts
:) In fact the reason I do not want to use tag now is that I do not want everything done by the framework,since I am new in struts2,so I want to learn struts step by step,I always thought that unless we know how the framework work we can not take the most advantage of it. When I know the work mechanism of the action mapping,then I will use the tag :) 2010/11/5 Maurizio Cucchiara > Struts tags are not mandatory in order to deploy an application, but > as Li suggested make your life easier :) > > 2010/11/5 maven apache : > > Thanks for all your guys reply. > > > > That's to say I have no choice but using the struts tag if I decide to > use > > the struts?? > > > > -- > Maurizio Cucchiara > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >
Re: how does the namespace work in struts
Thanks for all your guys reply. That's to say I have no choice but using the struts tag if I decide to use the struts?? 2010/11/5 Li Ying > >> > > This HTML code, will post your form to the RELATIVE path [space/register]. > So, the ABSOLUTE path which is requested will depend on the current > URL of this page. > > If ABSOLUTE path is not right, no doubt struts2 can not map it to a > right namespace/action. > > > > >> I will get a 404 error if I set the action to "/space/register" > > This HTML code, will post your form to the ABSOLUTE path [/space/register]. > But your web app is running under the [context path]. > So the valid URL should be something like > [/contextPath/space/register.action] > > My suggestion is: > (1)Use the Struts2 tag lib, get it works. > (2)Read the HTML code generated by tag lib, study how it works > > - > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org > >
how does the namespace work in struts
I meet some problem when I try to learn the namespace of struts2,I am using struts-2.2.1. After read the docs at: http://struts.apache.org/2.2.1/docs/namespace-configuration.html I am confused for the following reason: The example: greeting.jsp bar1.jsp moo.jsp bar2.jsp This is the explanation: *If a request is made to /barspace/foo.action, the namespace /barspace will be checked for action foo. If a local action is not found, the default namespace is checked. In the Namespace Example, there is no action foo in the namespace /barspace, therefore the default will be checked and /foo.action will be executed.* I wonder why it is '/foo.action' rather than 'foo.action",it said that it will find the foo.action at the default namespace,and the default namespace is "",so it should be foo.action,why there is a '/'?? ALso problem 2: *Namespace are not hierarchical like a file system path. There is one namespace level. For example if the URL /barspace/myspace/bar.action is requested, the framework will first look for namespace /barspace/myspace.* For the request url "/barspace/myspace/bar.action", the '/barspace/myspace' will be splitted as a namespace,so what is the action now? is it the "/bar.action" or "bar.action",since the "/" may stand for a root namespace. I am really confused,anyone can give me a detailed suggestion?? so I do some test: This is the struture of my test project: Struts_TestProject WebContent js(floder) jsp() reg.jsp thank.jsp WEB-INF web.xml lib() index.jsp 1)Default namespace test First I did not define the namespace in the struts.xml: /jsp/thank.jsp This is the HTML form(I am not intend to use the tag now): It works well, the page will jump to thank.jsp,the only problem is I have not found any way to pass some parameters to the thank.jsp and render them in the page.However this is not the main problem, I think I will make it clear oneday. 2)set a namespace Then I tried to test the namespace, I add a namespace to the package: ...Other configuration are same as it in the above. Then I call it by this manner: Then the struts show me the exception: **There is no Action mapped for action name register** (The following parameter is I get from debugging step by step at the IDE :(:( String servletPath = request.getServletPath()=== /jsp/space/register String requestUri = request.getRequestURI() /Struts_Test/jsp/space/register Then the "/jsp/space/register" is used to parsed the namespace and action name,at last the namespace is set to "" since there is not a mached namespace named "/jsp/space".And the name is set to "register". Obviously, it is wrong. Since the brower add the "jsp" prefix in the action. ) To avoid the browser add a "jsp" prefix in the action, I tried to set the action in form like: The exception is the same as before. Then I se the namespace from "space" to "/space",I also get the same excetpion as before if I use the action to "space/register" in the HTML form,however I will get a 404 error if I set the action to "/space/register". I am crazying!!! How the hell does the namespace work BTW, how does the "result" element in the "action" location the page?That's to say ,for exmaple /jsp/thank.jsp how to locat the thank.jsp? Is it based the base path of the web context? Is the first "/" required?