Posts

Showing posts from January, 2011

How to customize struts tabbedpanel style

Image
Having problem to change the tabs created by using struts 2 tabbedpanel tag? If you want to change the color and style of s:tabbedpanel in your accord,just override the CSS by creating your own CSS file and including it in your page. Suppose we have a page which looks something like: If you view the generated source using the Firefox plugin or IE developer tool you will see something like this html: The class attributes are the parts of interest. If you look at the embedded CSS you'll see these: .dojoTab { position : relative; float : left; padding-left : 9px; border-bottom : 1px solid #6290d2; background : url(/struts2-showcase/struts/dojo/src/widget/templates/images/tab_left.gif) no-repeat left top; cursor: pointer; white-space: nowrap; z-index: 3; } .dojoTab div { display : block; padding : 4px 15px 4px 6px; background : url(/struts2-showcase/struts/dojo/src/widget/templates/images/tab_top_right.gif) no-repeat right top; color : #3

Working with cookies in Struts 2

It appears that struts only supports reading cookies, you have to go to the servlet response to actually set a cookie. So it is better to go directly to the servlet request/response objects for both reading and writing: For this your action class should implement two interfaces namely: ServletResponseAware and ServletRequestAware like this:   public class MyActionClass extends ActionSupport implements ServletResponseAware, ServletRequestAware { }   And following line of code should be included in action class.   protected HttpServletResponse servletResponse; @Override public void setServletResponse(HttpServletResponse servletResponse) { this.servletResponse = servletResponse; } protected HttpServletRequest servletRequest; @Override public void setServletRequest(HttpServletRequest servletRequest) { this.servletRequest = servletRequest; } Now you can set cookie something like this: public String execute(){ // Save to c