aspose file tools*
The moose likes Struts and the fly likes How to access to ValueStack from xml? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to access to ValueStack from xml?" Watch "How to access to ValueStack from xml?" New topic
Author

How to access to ValueStack from xml?

Daniele De Rossi
Greenhorn

Joined: Apr 05, 2010
Posts: 8
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Apr 05, 2010
Posts: 8
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Apr 05, 2010
Posts: 8


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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Apr 19, 2010
Posts: 5
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

Joined: Apr 05, 2010
Posts: 8
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

Joined: Apr 19, 2010
Posts: 5
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Apr 19, 2010
Posts: 5
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

Joined: Aug 03, 2008
Posts: 9293
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
venkata.reddy pammi
Greenhorn

Joined: Apr 19, 2010
Posts: 5
Hi David,

I have applied code tags. Thanks for your time.

Thanks
Venkata
venkata.reddy pammi
Greenhorn

Joined: Apr 19, 2010
Posts: 5
Hi Everyone,

Can you please help me on above problem?

I really appriciate your time.

Thanks
Venkata
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access to ValueStack from xml?