How can I make title dynamically?
I'm developing BBS in struts2 and tiles(2) framework.
I want to push a value in ActionSupport class and pop the value in layout.jsp of tiles. but i just keep failing to access to the value.
I will explain my works step by step.
1) Users click a link to view an article at list page. And BoardView class will be called as defined in struts.xml
--list.jsp--
<a href="view_board?num=${num}"> ${ subject } </a>
--struts.xml--
<action name="View_board" class="board.BoardView">
<result type="tiles">board.view</result>
</action>
2)Action class will put title into the value stack... right?
--BoardView class--
public class BoardView extends ActionSupport
private String ti开发者_StackOverflow中文版tle;
public void Execute() throws Exception {
...
setTitle(board.getSubject());
return SUCCESS;
}
...
(setter and getter of title)
3) As ActionClass returns SUCCESS, it will go to tiles definition named board.view
--struts.xml--<action name="View_board" class="board.BoardView">
<result type="tiles">board.view</result>
</action>
4)Here's the tiles-def.xml and the problem. I think the value of 'title' can't be popped from value stack.
==tiles-def.xml==<definition name="board.view" extends="layout">
<put-attribute name="title" value="%title" />
<put-attribute name="body" value="/board/view.jsp" />
</definition>
(I can't indent with tags... sorry)
Here's the layout.jsp
==layout.jsp==
...
<title><tiles:getAsString name="title" /></title>
...
I tried to replace the value attribute to %{title}, $title and ${title}. But nothings worked out. Web Browser just shows the string itself($title).
I don't know what to do... please help me.
I hope you all understand my works despite my bad explanation.
As my solution on current Project.
- In template jsp: put
<c:out value="${pageTitle}" default="My Title"></c:out>
- So, in every actions class, you should create the variable pageTitle to DYNAMIC Title.
精彩评论