[S2] How to get the requested path from an interceptor
Is it possible to get the requested path from inside an interceptor? For instance, the following url was requested: http://myhost:8080/mywebapp/private/admin/json/companies.action So, from the interceptor, how can I get the /private/admin/json/companies.action part from that url? I searched across the ActionInvocation object but could not come with a solution. Regards, Célio - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to use the s:param tag with s:textfield?
I have the same problem, but as far as I could see, formatting support in S2 is nasty. You can format something with s:text using the format defined in your resource bundle, but you can't do that with s:textfield. WTF?! Man, so far I've spent 3 hours trying to do make that work, but just couldn't. I'm going crazy! Serious... Célio 2007/6/19, Luiz Henrique Rossetti [EMAIL PROTECTED]: Hi guys, How can I use the s: param with s:textfield? I need to format a Timestamp property of my Action using the mask dd/MM/. MyAction public BlablaAction extens ActionSupport{ private Employee employee; getters and setters } public class Employee{ private Timestamp finalDate; getters and setters } My jsp page s:textfield cssClass=textfield name=emp.finalDate maxlength=10 s:param name=value value=employee.finalDate/ /s:textfield My package.properties emp.finalDate = {dd/MM/} - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: S2: Formatting s:textfield values
I'm having the same problem. I consider this an important issue, so why this thread got no response? Célio 2007/4/11, Sauli Ketola [EMAIL PROTECTED]: Hi, Is there a way to format the value of a s:textfield like it possible with s:text? For example what would be the equivalent of s:text name=format.moneys:param name=value value=myMoneyValue//s:text for s:textfield/s:textarea? S. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[S2] Incorrect validation behaviour
I have a couple of actions with validation configuration. The validation works fine for most of them, except for one in which case all the fields are always invalidated even when I fill them correctly. Also, I noticed that, after submitting the form, the values of the fields are not preserved. I can't understand why it doesn't work right, because I simply copied and pasted from existing files of another action. I've already spent hours trying to fix that, but can't figure out what's wrong. alteracao-senha-form.jsp --- %@ taglib prefix=s uri=/struts-tags% html head titles:property value=%{getText('alteracao-senha')}//title /head body s:actionerror/ s:actionmessage/ s:fielderror/ br s:form action=alteracaoDeSenha!salvar s:token/ s:textfield name=senhaAtual label=%{getText('alteracao-senha.senha-atual')}/ s:textfield name=novaSenha label=%{getText('alteracao-senha.nova-senha')}/ s:textfield name=confirmacaoDaSenha label=%{getText('alteracao-senha.confirmacao-senha')}/ s:submit value=%{getText('registro.salvar')}/ /s:form a href=javascript:void(null); onclick=history.go(-1);/s:text name=navegacao.voltar//a /body /html AlteracaoDeSenhaAction.java -- package br.com.radice.labore.web.actions; import br.com.radice.labore.Usuario; import br.com.radice.labore.dao.UsuarioDao; import br.com.radice.labore.web.SessionKeys; import br.com.radice.web.struts2.actions.SessionProvidedAction; public class AlteracaoDeSenhaAction extends SessionProvidedAction { private static final long serialVersionUID = 1L; private UsuarioDao usuarioDao; private String senhaAtual, novaSenha, confirmacaoDaSenha; public AlteracaoDeSenhaAction() { } public void setConfirmacaoDaSenha(String confirmacaoDaSenha) { this.confirmacaoDaSenha = confirmacaoDaSenha; } public void setNovaSenha(String novaSenha) { this.novaSenha = novaSenha; } public void setUsuarioDao(UsuarioDao usuarioDao) { this.usuarioDao = usuarioDao; } public void setSenhaAtual(String senha) { this.senhaAtual = senha; } public String salvar() throws Exception { Usuario usuarioLogado = getUsuarioLogado(); if (!usuarioLogado.possuiEstaSenha(senhaAtual)) { addActionError(getText(alteracao-senha.senha-atual-incorreta)); return INPUT; } if (!novaSenha.equals(confirmacaoDaSenha)) { addActionError(getText(alteracao-senha.nova-senha-nao-confere)); return INPUT; } usuarioLogado.setSenha(novaSenha); usuarioDao.save(usuarioLogado); addActionMessage(getText(alteracao-senha.alterada-com-sucesso)); return SUCCESS; } private Usuario getUsuarioLogado() { Usuario usuarioLogado = (Usuario) getSession().get(SessionKeys.USUARIO); return usuarioDao.get(usuarioLogado.getId()); } } AlteracaoDeSenhaAction-validation.xml ?xml version=1.0 encoding=utf-8 ? !DOCTYPE validators PUBLIC -//OpenSymphony Group//XWork Validator 1.0.2//EN http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd; validators field name=senhaAtual field-validator type=requiredstring message key=alteracao-senha.campo-obrigatorio.senha-atual/ /field-validator /field field name=novaSenha field-validator type=requiredstring message key=alteracao-senha.campo-obrigatorio.nova-senha/ /field-validator /field field name=confirmacaoDaSenha field-validator type=requiredstring message key=alteracao-senha.campo-obrigatorio.confirmacao-senha/ /field-validator /field /validators spring.actions.xml -- ?xml version=1.0 encoding=UTF-8? beans xmlns=http://www.springframework.org/schema/beans; xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance; xsi:schemaLocation=http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd; !-- other stuff omitted -- bean id=alteracaoDeSenhaAction class=br.com.radice.labore.web.actions.AlteracaoDeSenhaAction scope=prototype property name=usuarioDao ref=usuarioDao/ /bean /beans struts.xml -- ?xml version=1.0 encoding=utf-8 ?
[S2] How to get an object from Spring inside an interceptor
Hi, I want to implement an OpenInView pattern interceptor involving Hibernate, but there's a problem. My SessionFactory is both created and managed by Spring, and my interceptor should have access to that SessionFactory, however I don't know how to do that. I have already searched a lot the web and the docs but couldn't find an answer. Does anybody know if that's possible (and how)?. Regards, Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [S2] How to get an object from Spring inside an interceptor
2007/5/23, Guillaume Carré [EMAIL PROTECTED]: if your SessionFactory is injected in your action, and all your actions extend AbstractAction for example, that has a getSessionFactory() method, you can do this: public String intercept(ActionInvocation invocation) throws Exception { Action action = (Action) invocation.getAction(); if (action instanceof AbstractAction) { sessionFactory = ((AbstractAction) action).getSessionFactory(); ... } The actions are unaware of any Hibernate type. This is mandatory since I don't want my actions to depend on a specific persistence mechanism. They only see DAO interfaces (which are also not dependent on any persistence mechanism). Thanks, Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[S2] Validation error messages are not being cleared
An action has this validation config: validators field name=nome field-validator type=requiredstring messageCampo obrigatório/message /field-validator /field field name=identificacao field-validator type=requiredstring messageCampo obrigatório/message /field-validator field-validator type=regex param name=expression[a-z]+/param message Digite apenas letras minúsculas. Não são permitidos espaços, números, nem caracteres acentuados. /message /field-validator /field /validators The validation works fine, except that the field error messages are not getting cleared when the user fills the fields correctly in the second submit. The procedure is: 1. Submit the form with all fields empty; (Struts shows the validation error messages correctly.) 2. Fill all fields with good values and submit again. (Struts duplicates the messages right above the previous ones.) And as you submit the form over and over again, Struts keeps invalidating the fields, duplicating the error messages. I'm using Struts 2.0.6. -8-- struts.xml (excerpt for that action) -8-- action name=usuario class=usuario-form-action !-- the action object comes from Spring -- result name=input/jsp/private/usuario-form.jsp/result result name=success type=redirect-actionlistaDeUsuarios/result /action -8-- the action -8-- public class UsuarioFormAction extends PrevaylerAction { private static final long serialVersionUID = 1L; private int id = 0; private String nome; private Perfil perfil; private String identificacao; private String senha; private String confirmacaoDeSenha; public SetPerfil getPerfis() { return contexto().getPerfis(); } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getNome() { return nome; } public void setNome(String nome) { this.nome = nome; } public int getPerfil() { return perfil.getId(); } public void setPerfil(int id) throws Exception { PesquisaDePerfilPorIdQuery pesquisa = new PesquisaDePerfilPorIdQuery(); pesquisa.setId(id); perfil = (Perfil) prevayler().execute(pesquisa); } public String getIdentificacao() { return identificacao; } public void setIdentificacao(String identificacao) { this.identificacao = identificacao; } public void setSenha(String senha) { this.senha = senha; } public void setConfirmacaoDeSenha(String confirmacaoDeSenha) { this.confirmacaoDeSenha = confirmacaoDeSenha; } public String input() throws Exception { if (id != 0) { PesquisaDeUsuarioPorIdQuery pesquisa = new PesquisaDeUsuarioPorIdQuery(); pesquisa.setId(id); Usuario usuario = (Usuario) prevayler().execute(pesquisa); if (usuario == null) return ERROR; nome = usuario.getNome(); perfil = usuario.getPerfil(); identificacao = usuario.getIdentificacao(); } return INPUT; } public String salvar() throws Exception { if (senha.compareTo(confirmacaoDeSenha) == 0) { if (id == 0) { if (senha.length() 0) criar(); else { addActionMessage(Digite uma senha para o novo usuário.); return INPUT; } } else modificar(); } else { addActionMessage(As senhas não conferem. Digite-as novamente.); return INPUT; } return SUCCESS; } private void modificar() { ModificacaoDeUsuarioTransaction modificacao = new ModificacaoDeUsuarioTransaction();
Re: [S2] Validation error messages are not being cleared
2007/3/25, Dave Newton [EMAIL PROTECTED]: --- Célio Cidral Junior wrote: Is it declared with scope=prototype? Oh noes! I fotgot about the scope! :-( MY APOLOGIES! MY APOLOGIES! Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[S2] Client-side code for custom validators
How do I implement client-side validation code for a custom validator? I have developed a custom validator that should generate client-side validation Javascript code, but I can't figure out where the implementation should lie. The actual official validators implementations don't host such code themselves, and I was not able to find out where it is. Regards, Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
How to dinamically load a select field
Well, perhaps dinamically is not the best way to describe it, but anyway what I need is to load a select field based on the value selected on another select field. Let's say you have a State field and also a City field. The user selects a state and the cities of that state are loaded in the City field. What's the best way to do that without having a page refresh? Regards, Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to dinamically load a select field
2007/3/7, Musachy Barroso [EMAIL PROTECTED]: If you are using S2, ... Oh yeah, I'm sorry, I forgot to mark my post as [S2]. Thanks for the replies. Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to dinamically load a select field
2007/3/7, Musachy Barroso [EMAIL PROTECTED]: If you are using S2, the autocompleter tag does that The bad documentation get on my nerves. It's sad the fact that fantastic pieces of software like Struts2 doesn't have decent documentation. Anyway I'm gonna hack around to see if I can find out how it works. Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to dinamically load a select field
2007/3/7, Dave Newton [EMAIL PROTECTED]: What does the documentation not tell you? I will update it if there's something missing, but it was more than enough to get my use of it going. I'm having difficult to understand how the autocompleter works ... http://struts.apache.org/2.x/docs/autocompleter.html ... more specifically, how it can help me on the problem I posted in this thread. However, as far as I understood, I think that tag can't help me. Perhaps Musachy got me wrong. Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to dinamically load a select field
2007/3/7, Dave Newton [EMAIL PROTECTED]: The next-to-last example specifically shows how to use the autocompleter tag to update one select when another one is changed; I thought that was what you were asking about. Thanks! Again, I or somebody else will be happy to change the documentation if you have specific issues. If nothing else I will add links to the different tags covered on that page. I will try to help you in that matter whenever I can instead of only complain about it. :-) By the way, the Freemarker documentation is pretty neat! What about taking it as a model for Struts2 docs? Best regards, Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Make Struts set form data onto the action in same order as the form's fields
Struts don't set the form data onto the Action in the same order in which the fields appear in the form. For instance, suppose you have a form like this: s:form action=customer!save s:token/ s:hidden name=id value=%{id}/ s:textfield name=customer.name label=Name size=30 maxlength=200/ s:textfield name=customer.phoneNumber label=Phone size=14 maxlength=14/ !-- ... and whatever a zillion fields more -- /s:form And its corresponding Action, which is something like: public class CustomerAction extends ActionSupport { private int id = 0; private Customer customer; private CustomerDao dao; public int getId() { return id; } public void setId(int id) { this.id = id; } public Customer getCustomer() { if (customer == null) customer = id != 0 ? dao.get(id) : new Customer(); return customer; } public String input() throws Exception { if (getCustomer() == null) return ERROR; return INPUT; } public String save() throws Exception { if (getCustomer() == null) return ERROR; dao.save(getCustomer()); return SUCCESS; } } You could expected that Struts, when submitting the form, would first set the id, then customer.name, then finally custumer.phoneNumber. However, it does not follow that order; actually, it does set the data in random order. In this case, the order is important because, if the user is altering an existing customer, its id must be set before getCustomer() gets invoked. Otherwise, the action will create a new customer with zeroed id. The way I built both the action and the view prevents me from writing a lot of extra code (like getters and setters for each of the form's field), and that's why I would like to know whether there's a way to make Struts follow the fields' ordering when submitting the data into the action. And if there's not, may the Struts dev team implement that, if possible. Regards, Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Make Struts set form data onto the action in same order as the form's fields
2007/1/25, Dave Newton [EMAIL PROTECTED]: From my point of view it seems like your implementation is broken: if you need to create a Customer from an ID passed via a form or URL then you either need to implement Preparable or do the DAO operations in the (in your case) input or save methods. The DAO operations already do that. The problem happens when the user is *altering* an existing customer (creating a new customer works fine), more specifically when the user is submitting changes from the form to an existing customer object (alongside with an existing id); in that case, the id must be set before getCustomer() is called, otherwise a new customer will be created with zero id. Loading the form with an existing customer works fine. Submitting changes to it is where the problem resides. The idea behind getCustomer() is to abstract the retrieving of the customer object wherever it's called along the action's code so that I don't have to care about whether it's an existing customer or not. Implementing Preparable does not seem to solve the problem because the parameters are set before the prepare() method is invoked. Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Make Struts set form data onto the action in same order as the form's fields
2007/1/25, Dale Newfield [EMAIL PROTECTED]: Célio Cidral Junior wrote: Implementing Preparable does not seem to solve the problem because the parameters are set before the prepare() method is invoked. Which is needed in order to know which object to retrieve from the DB. I think you have not read the code I included in the first email. Please, read it carefully and you will understand why Preparable doesn't solve my problem. This model usually includes including the parameters interceptor twice: Once before prepare and once after. I can't figure out how that would be useful in my case. Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Make Struts set form data onto the action in same order as the form's fields
2007/1/25, Tom Schneider [EMAIL PROTECTED]: This is an issue with the typical edit/save scenario. The problem we are discussing is that the domain model is needed in some form before the parameter can be repopulated from the form save. The technique you are using is to reread the data from the database before the parameters are set. An alternative technique would be to put the domain model into a place in the session--so on the save, you can retrieve the the model from the session and then allow the parameters interceptor to populate the new data. (This is referred to as detached objects in the Hibernate world) The advantage of putting the model in the session is that if some else modifies the data before you reread the data, but after you have displayed the edit page, you will not have the original model. This particularly a problem with a model where you are dealing with lists of domain objects. In this case, the edit will fail because you will be trying to set parameters on items that might not exist anymore. (Or you've pulled in data that the user doesn't know about) Therefore the safer technique is to save off the model. If you're concerned about putting too much into the session, you can store the data in a cache, such as ehcache, that will store items to disk if there are too many things in memory. (This is the technique that we used--we called it a model repository and we created a couple different implementations) I would love to see something like this out-of-the-box with struts2, but nothing currently exists. Thanks, I really appreciate your suggestions. However, I prefer a stateless approach because (I think) it helps to keep things simple in this case. Using some kind of cache between page requests is more like a stateful approach that I would like to avoid here for simplicity reasons. Well, having Struts passing parameters in the order defined by the html form would solve my problem. :-) Regards, Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Make Struts set form data onto the action in same order as the form's fields
2007/1/25, Tom Schneider [EMAIL PROTECTED]: Unfortunately I don't think that's possible. The parameters get put into a map structure, so the original parameter order is lost by the time it gets to the servlet API. We've run into several instances where something will work on one app server, but break on another because we had duplicate parameters on the url--so depending on how the app server handled it, we would get one or the other value. I can't imagine that any java web framework could do this successfully. That's sad! :-( Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: preInvokeJS does not work for a tag
Hi Musachy, 2007/1/2, Musachy Barroso [EMAIL PROTECTED]: What version are you using? using head svn , I modified showcase's remote link first example to this: s:a theme=ajax href=%{ajaxTest} indicator=indicator targets=t1,t2 notifyTopics=/after preInvokeJS=alert('test')Update 'Div 1' and 'Div 2', publish topic '/after', use indicator/s:a and it shows test. preInvokeJS is deprecated. If you are using head svn, use notifyTopics instead. See showcase for examples, or this link: http://struts.apache.org/2.x/docs/ajax-tags.html I don't know much about ajax (well, almost nothing), but using the ajax theme in my case is not a kludge? Regards, Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
preInvokeJS does not work for a tag
Hi, The preInvokeJS attribute does not work for the a tag as described in the example from http://struts.apache.org/2.x/docs/a.html. That feature seems to be originated from the issue http://issues.apache.org/struts/browse/WW-912. Below is a snippet of my source JSP code. s:a href=%{delete} preInvokeJS=confirm('%{getText('confirm-delete')}') s:text name=record.delete/ /s:a The anchor works properly, except that it does not call the confirm() method. The generated HTML gives me this code: a href=/sed/listUsers!delete.do?id=1Deletar/a And there's no occurrence of the word confirm in the whole HTML code nor there's any reference to an external JS file. I presume I'm not missing anything. Any guess whether this feature is actually working or not? Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Values of multiple select tag are not being selected
Given the following code: myPage.jsp: s:select name=selectedRoles list=allRoles listKey=id listValue=name multiple=true label=%{getText('roles')}/s:select MyAction.java: public SetString getSelectedRoles() { SetString ids = new HashSetString(); for (Role role : selectedRoles) ids.add(Integer.toString(role.getId())); return ids; } public ListRole getAllRoles() { return roleDao.list(); } All the available roles are properly loaded to the list but the ones returned by getSelectedRoles() are not appearing selected in the list. I have compared my code against the Employees Manager's (from struts2-showcase-2.0.1) and my code seems to be correct. In addition, I debugged getSelectedRoles() to check if the selected role ids are being correctly returned, and they actually are. I can't catch anything wrong in my code. Could anybody help me on this? Regards, Célio. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]