I'm trying to output a key to a localized message in a jsp template in the following way:
<c:set var="logo-tooltip-title">
<fmt:message key="logo.tooltip.title"/>
</c:set>
<c:out value="${logo-tooltip-title}"/>
With the following in my messages.properties file:
logo.tooltip.title=Test
Does anyone know what I'm doing wrong here? Why does it return 0 instead of Test?
My goal is to output that message as title of the following link:
<a class="logo" href="/site/" title="${logo-tooltip-title}">
<img src="<hst:link path="/img/logo.png"/>" alt="logo" class="headlogo" width="80" height="100" />
</a>
Any thoughts on the best approach to do this?
Thanks!
EDIT:
yes I have set the context param in web.xml:
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>messages</param-value>
</context-param>
resource
Update:
This seems to work:
<fmt:message key="logo.tooltip.title" var="tooltip"/>
<c:out value="${tooltip}"/>
I don't think your problem is specific to HippoCMS.
I tried your syntax and I think you're missing a bundle declaration. If I add an org/ecausarano/Example.properties file to the war resources and:
<fmt:setBundle basename="org.ecausarano.Example" />
<c:set var="message">
<fmt:message key="message.message" />
</c:set>
<c:out value="${message}" />
it works for me.
JSTL tries to do math for "logo - tooltip - title" which results in 0. You've already found out that replacing the - by . solved the issue.
Related
There are two image files in my webcontent/images folder the_logo.jpg and logo.png
I am able to access the .png file
<img alt="Powerpay1" src="./images/logo.png" width="250" height="50" />
but unable to access the .jpg file
<img alt="Powerpay" src="./images/the_logo.jpg" width="250" height="50" />
How should I solve this?
Feel free to ask if any other information is needed.
NOTE : I am using Apache tomcat.
use
<img alt="Powerpay1" src="../images/logo.png" width="250" height="50" />
<img alt="Powerpay1" src="../images/the_logo.jpg" width="250" height="50" />
This code will take the cursor to the previous folder.
If you have two nested folder, use ../../ or three nested folders, use ../../../and so on to go to the root of the directory and browse respectly.
instead of
<img alt="Powerpay1" src="./images/logo.png" width="250" height="50" />
<img alt="Powerpay1" src="./images/the_logo.jpg" width="250" height="50" />
One more best way to doing it by using scriptlets
Ex:
<%
String base = request.getContextPath() + "/";
if (base == null || base.isEmpty()) {
base = "/";
}
%>
<img alt="Powerpay1" src="<%=base%>images/logo.png" width="250" height="50" />
Apache configuration can allow specific suffixes. see mod_suffix
File in linux should be in a path as /etc/httpd/conf/httpd.conf
Try changing your files match patterns to add jpg:
<FilesMatch "\.(png|**jpg**|gif|css|php|html|js)$">
allow from all
</FilesMatch>
In my apache tiles config file, I have a section like this:
<definition name="admin/*/*" extends="adminLayout">
<put-attribute name="key" cascade="true" value="{1}" />
</definition>
Then, in my JSP, I am would like to do some logic on the tile attribute.
Something like:
<c:if test="${key == 'value'}">
// do something
</c:if>
where key comes from the tile attribute.
How can I access this tile attribute inside the expression language?
I have tried
<c:set value="<tiles:insertAttribute name='key'/>" var="theKey"></c:set>
and
<c:if test="${<tiles:insertAttribute name='key'/> == 'value'}">
and both times the raw tiles xml is used as the comparing string - it doesn't get replaced by the attribute.
Use Tiles extras:
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tiles="http://tiles.apache.org/tags-tiles"
xmlns:tilesx="http://tiles.apache.org/tags-tiles-extras"
version="2.0">
<tilesx:useAttribute id="keyJspVariable" name="key" classname="java.lang.String" />
<c:if test="${keyJspVariable== 'value'}">
// do something
</c:if>
Documentation example: https://tiles.apache.org/framework/tutorial/advanced/list-attributes.html
This question is very similar (if not the same as):
"Can't find bundle for base name messages" error
ResourceBundle [messages] not found for MessageSource: Can't find bundle for base name messages
Basically, i have this code:
<body>
<f:view>
<f:loadBundle basename="de.vogella.jsf.starter.messages" var="msg" />
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="#{msg.user}"></h:outputLabel>
<h:inputText value="#{user.name}">
<f:validator
validatorId="de.vogella.jsf.starter.validator.LoginValidator" />
</h:inputText>
<h:outputLabel value="#{msg.password}"></h:outputLabel>
<h:inputSecret value="#{user.password}">
</h:inputSecret>
</h:panelGrid>
<h:commandButton action="#{user.login}" value="#{msg.login}"></h:commandButton>
<h:messages layout="table"></h:messages>
</h:form>
</f:view>
And when I try to run, I get
An exception occurred processing JSP page /LoginView.jsp at line 13
10: </head>
11: <body>
12: <f:view>
13: <f:loadBundle basename="de.vogella.jsf.starter.messages" var="msg" />
14: <h:form>
15: <h:panelGrid columns="2">
16: <h:outputLabel value="#{msg.user}"></h:outputLabel> Stacktrace:
Caused by:
java.util.MissingResourceException - Can't find bundle for base name de.vogella.jsf.starter.messages, locale en`
I tried to change file name, change file name in code, adding resource folder (but I think it was already properly included), and putting messages.properties file in all possible folders. Curiously, eclipse itself shows this error, it also has empty suggestion boxes for basename (no default proposals).
In case it helps, my project structure:
http://imgur.com/3eAxWo3
Can you confirm if you have message.properties file in the directory de.vogella.jsf.starter?
If not please add the message.properties in this directory and then compile all. Check if you still get the exception?
I too faced the same issue.
But finally, if you keep the messages.properties file under any package(de.vogella.jsf.starter.model) and include this as follows:
< f:loadBundle basename="de.vogella.jsf.starter.model.messages" var="msg" />
It is Working.
I'm trying to solve the following problem:
Let's say that I have a settings.xml file that looks as follows:
<SETTINGS>
<username fieldType="TextField" possibleValues="*">username_value</username>
<roletype fieldType="DropDownList" possibleValues="normal,admin,agent">admin</roletype>
<active fieldType="RadioButtons" possibleValues="true,false">true</active>
<SETTINGS>
What I'm trying to achieve is the following:
1- When my page first loads, it will parse this xml file, and layout the UI components based on the fieldType and the possibleValues.
2- When my UI components are loaded, I should be able to configure the value of my fields, which will end up persisting in my settings.xml file.
Is there a ready library that does this? Or do I need to write the code for this myself?
Note: I'm restricted to using JSF 1.x
Thanks in advance.
First of all , i will recommend to change the structure of your XML file as:
<SETTINGS>
<controls>
<control label="username" fieldType="TextField">
<values></values>
<selvalue></selvalue>
</control>
<control label="roletype" fieldType="DropDownList">
<values>
<value>normal</value>
<value>admin</value>
<value>agent</value>
</values>
<selvalue></selvalue>
</control>
<control label="active" fieldType="RadioButtons">
<values>
<value>true</value>
<value>false</value>
</values>
<selvalue></selvalue>
</control>
Now use JAXB to parase this XML file to the different classed, where each xml tab will be act as one independent class.
like :
Settings :
private List<Control> controls;
Control :
String label; // Attribute
String fieldType; // Attribute
Values values; //Property
String selValue; //Property
Values :
List<Value> values; ////Property
Value :
String value; //Property
DynaCritSearchBean : A Bean Class
Settings settings;
Once the data is loaded in to the corresponding class, use the following logic to dynamically create the screen in your XHTML file :
<h:panelGrid>
<c:forEach var="control"
items="#{dynaCritSearchBean.settings.controls}">
<h:panelGroup>
<h:outputText value="#{control.label}" />
</h:panelGroup>
<h:panelGroup>
<c:choose>
<c:when test="#{control.fieldType eq 'TextField'}">
<h:inputText value="#{control.selvalue}" />
</c:when>
<c:when test="#{control.fieldType eq 'DropDownList'}">
<h:selectOneMenu value="#{control.selvalue}">
<f:selectItem itemValue="" itemLabel="--select--" />
<c:forEach var="selOneValue" items="#{control.values.values}">
<f:selectItem itemValue="#{selOneValue}"
itemLabel="#{selOneValue}" />
</c:forEach>
</h:selectOneMenu>
</c:when>
<!-- Same as above logic for Radio button -->
</c:choose>
</h:panelGroup>
</c:forEach>
</h:panelGrid>
Once you submit the form, all selected/entered values are set to corresponding selValue of each Control.
Now, in order to get the XML back, you can use same JAXB concept which is very simple.
I am defining a tagx file called "version.tagx". The responsibility of this tag is to emit an anchor tag whose display text is the version number of the application. Currently, the definition of the file looks like this:
<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:spring="http://www.springframework.org/tags" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:output omit-xml-declaration="yes" />
<jsp:directive.attribute name="render" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicate if the contents of this tag and all enclosed tags should be rendered (default 'true')" />
<c:if test="${empty render or render}">
<spring:message code="global_version" />
<spring:url var="changelog" value="/resources/changelog.txt" />
<c:out value=": " />
${application_version}
</c:if>
</jsp:root>
My application is a Spring MVC application running in a Tomcat 7x container. I have the following line in my applicationContext.xml
<context:property-placeholder location="classpath*:META-INF/spring/*_${spring.profiles.active}.properties,classpath:app-info.properties"/>
I have confirmed through following the DEBUG log message the app-info.properties file is discovered by Spring and (presumably) the property values within that file have been loaded into my runtime.
Here is the log message
2012-05-09 23:45:24,237 [main] INFO org.springframework.context.support.PropertySourcesPlaceholderConfigurer - Loading properties file from class path resource [app-info.properties]
2012-05-09 23:45:24,237 [main] DEBUG org.springframework.core.env.MutablePropertySources - Adding [localProperties] PropertySource with lowest search precedence
And here are the contents of my app-info.properties file:
application_version=1.0
application_buildTime=05-04-2012 00:00:00
application_builtBy=me
application_buildNumber=55
What I want is for my tagx to emit
Version: 1.0
And currently what I get is:
Version:
Does anyone know of a way to accomplish this? Should I be trying a completely different approach that forgoes properties files all togher?
In webmvc-config.xml add util:properties where /WEB-INF/spring/application.properties is the path to the properties file:
<util:properties id="applicationProps" location="/WEB-INF/spring/application.properties"/>
Then, simply add this before your anchor tag:
<spring:eval expression="#applicationProps['application_builtBy']" var="application_builtBy"/>
<spring:eval expression="#applicationProps['application_buildTime']" var="application_buildTime"/>
<spring:eval expression="#applicationProps['application_version']" var="application_version"/>
Hope it helps.
What you can also do that doesn't tie you to looking up properties in a single property placeholder, or if you are using java config and just instantiating a PropertySourcesPlaceholderConfigurer is use the environment object:
<spring:eval expression="#environment.getProperty('application_builtBy')" />