I have following code in my tiles.xml file.
I have a Struts2 Action which gets data from database and populate in sidebar.jsp in show definition I again hit another method of same action for another work and this time I populate list view definition but my previous data of siderbar.jsp does not retain its value.
I am stuck on this for a week please help me out.
<definition name="baseLayout" template="/jsp/baseLayout.jsp">
<put-attribute name="header" value="/jsp/header.jsp"/>
<put-attribute name="menu" value="/jsp/menu.jsp"/>
<put-attribute name="body" value="/jsp/body.jsp"/>
<put-attribute name="sidebar" value="/jsp/sidebar.jsp"/>
<put-attribute name="footer" value="/jsp/footer.jsp"/>
</definition>
<definition name="show" extends="baseLayout">
<put-attribute name="body" value="/jsp/body.jsp"/>
</definition>
<definition name="listview" extends="baseLayout">
<put-attribute name="body" value="/jsp/listview.jsp"/>
</definition>
As per my understanding, sidebar.jsp is the JSP that holds the data for the sidebar. Check for the value of object which is used to populate the JSP.
I again hit another method of same action for another work and this time
I populate list view definition but my previous data of siderbar.jsp does not
retain its value.
When you hit another action all the variables of the action are initialized again which might be the reason why your sidebar.jsp cannot retain the previous data.
One simple solution would be to store the data related to sidebar.jsp in session
Hope this helps :)
Related
I'm a new member of stackoverflow but since this is the first problem I really can't seem to fix.
I know the question probably is unclear but here is my problem. For our backend application we use JSF.
Now there is a p:selectOneMenu with selectItems that are automatically filled (DatabaseServers) but we've added a new attribute (boolean full) and my question now is if it is possible to edit the background-color of the full databases in red and the not full databases in green.
<p:outputLabel for="emrDatabaseServer"
value="#{msg['tenants.label.emrDatabase']}" />
<p:selectOneMenu id="emrDatabaseServer" style="width:250px;"
value="#{tenantController.entity.emrDatabaseServer}"
effect="fade" required="true"
converter="#{databaseServerConverter}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{tenantController.emrDatabaseServers}"
var="emrDB"
itemLabel="#{emrDB.name} (#{emrDB.host}:#{emrDB.port}) (#{emrDB.nbDatabases} dbs)"
itemValue="#{emrDB}" />
<p:ajax event="change"
listener="#{tenantController.onValueChange}" update="save" />
</p:selectOneMenu>
I've tried countless things but it just doesn't seem to work.
I would also like to mention that I don't have the option of using code from other packages and so.
Styling options of a select-element is not possible in a clean and cross-browser-compatible way, as described here.
But if you would use some hack that satisfied your styling-requirement, there is no style or styleClass attribute for <f:selectItem> resp. <f:selectItems>. For this problem you could try using a pass-through-attribute as described by this anser (which uses the title-attribute instead of style, but you got the idea).
But all in all, what you are trying to do would result in a big hack and should be avoided.
Is it possible to create a new node inside tree dynamically.
<p:tree value="#{treeBasicView.root}" var="node" dynamic="true">
<p:treeNode>
<h:outputText value="#{node}" />
</p:treeNode>
</p:tree>
If it possible, how to do it. Kindly help. Thank you.
Yes, it is possible to do.
You should see examples from this link.
In the example, Recursion is used for demonstration.
The problem can be reproduced in PrimeFaces showcase:
http://www.primefaces.org/showcase/ui/data/dataexporter/basic.xhtml
<f:facet name="{Exporters}">
<h:commandLink>
<p:graphicImage name="/demo/images/excel.png" width="24"/>
<p:dataExporter type="xls" target="tbl" fileName="cars" />
</h:commandLink>
</f:facet>
I have no idea from where the export gets the sorting that it is using.
Is there any way to make p:dataExporter to keep the same order as in p:dataTable?
Edit: My client noticed that if you click a column to sort the datatable then export keeps the sorting. That's good but how to keep the initial sorting?
am usign jsf 2.0 + primefaces 3.2. i have a problem with filterBy when the data is a date but it works with other types of data.
<p:column sortBy="#{item.dateNaissance}" filterBy="#{item.dateNaissance}">
<f:facet name="header">
<h:outputText value="#{bundle.ListEtudiantTitle_dateNaissance}"/>
</f:facet>
<h:outputText value="#{item.dateNaissance}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
default filtering doesn't work for date field, though you can use advanced filtering option and provide a filter server side method which does the filtering from the data set for you.
Basically you will specify your metho on key up event and filter record as per your need, default assumes everything to be String.
I have created a project using struts2 and spring frameworks. Now I am trying to separate my dynamic content using tiles framework.
The layout consists of a header and body. The header in turn contains Welcome xyz (name of the logged user) and body part contains a tabular listing of people, populated from my database on startup.
Following is my Tiles layout code
Layout.jsp
<body>
<tiles:insertAttribute name="header"/>
<tiles:insertAttribute name="body"/>
</body>
tiles.xml
<tiles-definitions>
<definition name="baseLayout" template="layout.jsp">
<put-attribute name="header" value="welcome.jsp"/>
<put-attribute name="body" value=""/>
</definition>
<definition name="addToListLayout" extends="baseLayout">
<put-attribute name="body" value="addEmployee.jsp"/>
</definition>
</tiles-definitions>
But after the login Iam getting the following output on jsp :-
welcome.jsp addEmployee.jsp
Can any one let me know why I am getting the names of jsp rather than the content?
The issue is that tiles is not interpreting your attributes as templates, it is interpreting them as strings.
From the tiles doc:
This tag can be flexibly used to insert the value of an attribute into a page. As in other usages in Tiles, every attribute can be determined to have a "type", either set explicitly when it was defined, or "computed". If the type is not explicit, then if the attribute value is a valid definition, it will be inserted as such. Otherwise, if it begins with a "/" character, it will be treated as a "template". Finally, if it has not otherwise been assigned a type, it will be treated as a String and included without any special handling.
So you can change your tag in tiles.xml to either this:
<put-attribute name="header" value="/welcome.jsp"/>
or this:
<put-attribute name="header" type="template" value="welcome.jsp"/>