• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to access to ValueStack from xml?

 
Daniele De Rossi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using struts2+tiles2 frameworks.

I want to push stuffs in ActionSupport class, and pop the value in tiles.xml(tiles definition xml).

I'm trying to access to ValueStack by using OGNL, but I keep failing..


<definition name="board.view" extends="layout">
<put-attribute name="title" value="%title />
<put-attribute name="body" value="/board/view.jsp" />
</definition>


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 make sure that I push the value in action class... please help me out.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not aware that Tiles knows anything about the value stack--it's framework-neutral. Do you have a link to the documentation that suggests otherwise?

That aside--there's no reason to do this in the Tiles configuration even if you could--just access the "title" property in the JSP.
 
Daniele De Rossi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to access to ValueStack because I want to make the web brouser title dynamically.

Same as this site, the title should display the subject of the article.

Is there another way to make title dynamic except pushing the value from action class?

(Sorry for my bad English. I hope you understand what I mean)
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniele De Rossi wrote:Is there another way to make title dynamic except pushing the value from action class?

But that's what you're trying to do now--access the value stack from the tile definition.
 
Daniele De Rossi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Dear David Newton, thank you so much!

Actually I couldn't understand what you mean and gave it up for a while...

But today I finnally make it work!

I just added ${title } to layout.jsp.
<title>
<tiles:getAsString name="title" ignore="true"/>${ title }
</title>

This is how I make it work, just as you advised me.

I can;t thank you enough, really.

Take care!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's great, glad you figured it out :) Feel free to ask me to explain further if I explain something poorly!
 
venkata.reddy pammi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Even i am tring to do the same for my application. can you please explain indetail?

I have tried with this:

in jsp:

<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>

<title>
<tiles:getAsString name="title" ignore="true"/>${ title }
</title>


in tiles:

<definition name="polls.by.cat" extends="vcTemplate">
<put-attribute name="title" value= "${title}" />
<put-attribute name="pageContent" value="/jsp/polls/pollsByCat.jsp" />
</definition>


When i tried it is giving me page title ${title}.
How to replace that title value dynamically?

Thanks
Venkata
 
Daniele De Rossi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm.. first make sure that you have the 'title' field in your action, and push the 'title' by setters.
And as far as I know, there's no way to access valuestack from xml.
So don't try it from tiles-config.xml, but from your layout.jsp.
That is what we got from the discussion above.




yourLayout.jsp



And this will show the title normally.
I think it's better not to use any EL in tiles.xml.
And each definition of tiles, you should put the value of title attribute which clearly explains what this page is about.
 
venkata.reddy pammi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
config:
<definition name="vcTemplate" page="yourLayout.jsp">
<put-attribute name="pageContent" value="/jsp/polls/pollsByCat.jsp" />
</definition>

pollsByCat.jsp:
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>

<title>
<tiles:getAsString name="title" ignore="true"/> ${ title }
</title>

action:
I am sure have the 'title' field in my action, and pushed the 'title' by setters.

pollByCatForm.setTitle(category + " Polls by Category.");


But still not getting displayed above title for my jsp.

Can you please suggest me still if i am missing?

Thanks
Venkata
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You either need an action property named "title" (with a public getter), or you need to get the title from your form variable-that "pollByCatForm", about which I know nothing. Are you implementing ModelDriven or something? Please TellTheDetails or it's difficult to help.
 
venkata.reddy pammi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

My sinceare Thanks for your reply and these are the details.

THis is url i am accessing through IE:
http://localhost/ContextName/pollsByCat.action?categoryName=Business

My struts.xml config:


My action class:


My form :



This is my tiles config:


This is my pollsByCat.jsp to display the "title":




Question:
I want to display the title inthe jsp by using tiles. As i discussed above. I have tried above ways i couldn'd display.

Can you please verify the above code and suggest me if i am missing anything?

Thanks
Venkata
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Venkata please Use Code Tags when you post a source code. That way your code looks formatted. Unformatted code is hard to read. You can add code tags by wrapping your code in [code] [/code] tags. You can edit your message using button and then add code tags to it...
 
venkata.reddy pammi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

I have applied code tags. Thanks for your time.

Thanks
Venkata
 
venkata.reddy pammi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

Can you please help me on above problem?

I really appriciate your time.

Thanks
Venkata
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic