Q. How do I get the latest version of Webwork2 and XWork from CVS?
cvs -d :pserver:guest@cvs.dev.java.net:/cvs login
(Use an empty password, just hit enter..)
cvs -d :pserver:guest@cvs.dev.java.net:/cvs checkout webwork
cvs -d :pserver:guest@cvs.dev.java.net:/cvs checkout xwork
Q. How do I build Webwork2/Xwork
Just go into the xwork or webwork directory and run 'ant' (you must have ant installed and have the jars of junit and clover inside $ANT_HOME/lib)
Once you have built the xwork.jar copy it into the webwork/lib/core folder, and delete the old one.
Q. How do I use messages from within the validator?
Code Block | ||||
---|---|---|---|---|
| ||||
<validators> <field name="name"> <field-validator type="requiredstring"> <message key="template.name.errors.required">A default message in case the key is not found</message> </field-validator> </field> </validators> |
Q. How do I set a global resource bundle?
Java class (thanks Drew McAuliffe):
Code Block | ||||
---|---|---|---|---|
| ||||
public class WebworkGlobalMessagesListener implements ServletContextListener { private static Logger log = Logger.getLogger(WebworkGlobalMessagesListener.class); private static final String DEFAULT_RESOURCE = "global-messages"; /** * Uses the LocalizedTextUtil to load messages from the global message bundle. * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.Servle tContextEvent) */ public void contextInitialized(ServletContextEvent arg0) { log.info("Loading global messages from " + DEFAULT_RESOURCE); LocalizedTextUtil.addDefaultResourceBundle(DEFAULT_RESOURCE); log.info("Global messages loaded."); } /** * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent) */ public void contextDestroyed(ServletContextEvent arg0) { // do nothing } } |
web.xml:
(under listeners section)
Code Block | ||||
---|---|---|---|---|
| ||||
<listener> <listener-class>mypackagename.WebworkGlobalMessagesListener</listener-class> </listener> |
Q. How do I change the error message for invalid inputted fields?
A: You need to create a message for that field, for example if you have a user.dob field you would use this in your messages file (see above for example on setting a global messages file):
invalid.fieldvalue.user.dob=Please enter Date of Birth in the correct format.
Q. How do I get access to the Session?
A: ActionContext.getContext().getSession() (returns Map, works internally using a ThreadLocal)
Q. How can I see all parameters passed into the Action?
A: ActionContext.getParameters() (returns Map, works internally using a ThreadLocal)
Q. How can I get the HttpServletRequest?
A: ServletActionContext.getRequest() (works internally using a ThreadLocal)
Q. How do I decouple XWork LocalizedTextUtil global resource bundle loading from serlvets (ServletContextListener)?
Q. What i need to do to put values in a combobox. If I am using webwork2?
If i have :
Code Block |
---|
#tag(Select "label='xxx '" "name='xxx'" "list=?") or #tag(combobox "label='Prioridade'" "name='inavis.avisTpPrioridade'" "list=?") |
the values in this combobox, what i need to do?
Exemple:
Code Block |
---|
html tag i use to do: <select..> <otpion value="" selected>XXX</option> </selct> |
so...i need to do this using Webwork2 tags from Velocity...how can i do this??
Q. How do I add I18N to a WW2 Tag, like ww:textfield?
Code Block |
---|
<ww:textfield label="'i18n.label'" name="'label1'" value="''"> |
???
Code Block |
---|
<ww:textfield label="getText('i18n.label')" name="'label1'" value="''"> |
Q: Can I add I18N outside de Action's context? i.e. adding i18n to some JSP using the ww taglib.