JSF2 ignores empty alt attribute - jsf-2

I have a jsf snippet:
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets">
<!-- Yandex.Metrika -->
<img src="//mc.yandex.ru/watch/xxx" alt=""/>
<!-- /Yandex.Metrika -->
</ui:composition>
But when I use it, web-client get HTML page whithout empty alt attribute in img element:
<!-- Yandex.Metrika -->
<img src="//mc.yandex.ru/watch/xxx" />
<!-- /Yandex.Metrika -->
As result my document has validation error (
How can I solve this problem?

You could use the JSF graphicImage component, which does render the empty alt attribute.
For Example:
<h:graphicImage value="#{resource['images:image1.png']}" alt="" />
or
<h:graphicImage value="http://somedomain.com/somecontext/xxx/image1.png" alt="" />

Not sure if that is a bug in JSF2 (JSF1.2 preserves empty attributes).
To 'workaround' that in JSF2, wrap code by f:verbatim, like this:
<f:verbatim>
<img src="//mc.yandex.ru/watch/xxx" alt=""/>
</f:verbatim>

Related

Dynamic cc:insertChildren render

I got the problem when control to render cc:insertChildren dynamically.
<cc:implementation>
My text 1
<c:if test="#{testData}">
<cc:insertChildren /> <!-- My content will be loaded here-->
</c:if>
My text 2
<c:if test="#{!testData}">
<cc:insertChildren /> <!-- or other will be loaded here-->
</c:if>
</cc:implementation>
but the content rendered in both cc:insertChildren tags could not be rendered.
Do you have any ideas ?
Thank you.

How to define default content for facet in a composite component?

I am trying to write a composite component in JSF 2.2.
This is it.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:cc="http://xmlns.jcp.org/jsf/composite">
<!-- INTERFACE -->
<cc:interface>
<cc:facet name="content"/>
<cc:facet name="menubar"/>
</cc:interface>
<!-- IMPLEMENTATION -->
<cc:implementation>
Content header
<cc:renderFacet name="content">
This is the default content.
</cc:renderFacet>
Spacer
<cc:renderFacet name="menubar">
This is the default menubar.
</cc:renderFacet>
</cc:implementation>
</html>
This is how it is used.
<dd:dummy>Hello hello</dd:dummy>
This is what is rendered to the client.
Why is the default content and default menubar not rendered?
This should work
<cc:implementation>
<c:if test="#{empty component.facets.content}" >
This is the default content.
</c:if>
<c:if test="#{not empty component.facets.content}">
<cc:renderFacet name="content"/>
</c:if>
<c:if test="#{empty component.facets.menubar}" >
This is the default menubar.
</c:if>
<c:if test="#{not empty component.facets.menubar}">
<cc:renderFacet name="menubar"/>
</c:if>
</cc:implementation>

Unable to get values in JSP in Struts2 Liferay6.2 Portlet

Brief Overview: I am trying to port a webapp based on Struts2 ,into a Struts2 Liferay portlet.
Problem definition: The values are fetched as NULL/Blank even if if the action Class method is setting the values properly in my variables.
I have tried printing out the values when my method is returned in Action Class and also in my jsp. The values are getting properly set as I can see it from the loggers put in place just before returning SUCCESS, but in the jsp I can see all the required set variables are blank!!
Code snippet:
In jsp the code is fetching the values as below:
For instance
<br>
<s:if test="%{xyz!= null}">
<br />
<div style="margin-left:9em;">
<s:property value="xyz" escapeHtml="false"/> //never displayed as xyz is NULL
</div>
<br /><br />
</s:if>
<br>
on printing out xyz: <s:text name="%{xyz}"/> , I get blank values , this happens for all the required values in the jsp.
The options I have tried out:
I have tried using : %{#xyz}, %{xyz}, but didn't helped.
struts.xml
<action name="selectSite" class="com.abc.xyz.LandingPageAction"
method="selectSite">
<interceptor-ref name="abAjaxCallInterceptorStack" />
<result name="success" >/WEB-INF/jsp/portal/LandingContent.jsp</result>
</action>
liferay-portlet.xml:
<liferay-portlet-app>
<portlet>
<portlet-name>xyz-portlet</portlet-name>
<icon>/icon.png</icon>
<private-session-attributes>false</private-session-attributes>
<requires-namespaced-parameters>false</requires-namespaced-parameters>
<header-portlet-css>/css/main.css</header-portlet-css>
<footer-portlet-javascript>/js/main.js</footer-portlet-javascript>
<add-default-resource>true</add-default-resource>
</portlet>
</liferay-portlet-app>
jsp page:
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<br>
<s:if test="%{xyz!= null}">
<br />
<div style="margin-left:9em;">
<s:property value="xyz" escapeHtml="false"/>
</div>
<br /><br />
</s:if>
<br>
<br />
<sj:tabbedpanel id="billTab" >
<sj:tab id="overview" href="%{overviewURL}" label="Overview"
target="overviewDiv" indicator="loadingInd" />
<sj:tab id="invoices" href="%{invoiceURL}" label="Invoices"
target="invoicesDiv" indicator="loadingInd" />
<div id="overviewDiv" ></div>
<div id="invoicesDiv" ></div>
</sj:tabbedpanel>
try
<s:if test="xyz!= null">
if xyz is on the valuestack then you don't need to use %
You can also use Set tag to expose these values such as
<s:set var="varName" value="xyz"/>then just refer to it as varName instead of #varName
If you are accessing vars in a different portlet you will have set the value for the variable as at least request scope like this
<s:set var="varName" value="xyz" scope="request"/>
Then you can access them like this from another portlet in the same page
<s:if test="#request.xyz != null">

<h:commandButton> not working inside <ui:define>

I created a facelet template called loginRegisterTemplate.xhtml. When I use it in a template client and I place a in it, the method in the managed bean is not invoked. Without the template the button is working fine. Why is this happening?
<ui:composition template="resources/css/faceletsTemplates/loginRegisterTemplate.xhtml">
<ui:define name="top">
Login Page
</ui:define>
<ui:define name="content">
<div align="center">
<h:panelGrid columns="3" columnClasses="rightalign,leftalign,leftalign">
<h:outputLabel value="Username:" for="userName"/>
<h:inputText id="userName" label="Username" required="true" value="#{loginBean.userName}" />
<h:message for="userName" />
<h:outputLabel value="Password:" for="password"/>
<h:inputText id="password" label="Password" required="true" value="#{loginBean.password}" />
<h:message for="password" />
</h:panelGrid><br/>
<h:button value="Back to Home" outcome="home"/>
<h:commandButton id="login" value="Login" action="#{loginBean.doLogin}"/>
</div>
</ui:define>
</ui:composition>
</h:body>
The simple <h:button> next to it, on the other side, is working fine.
Here is the body of my template file:
<h:body>
<div id="top">
<ui:insert name="top">Top</ui:insert>
</div>
<div id="content" class="center_content">
<ui:insert name="content">Content</ui:insert>
</div>
</h:body>
I have looked here: h:commandLink / h:commandButton is not being invoked but I couldn't find which problem causes that.
Thanks!
Why is the h:commandButton not working?
Your problem is number 1 in the answer you have checked.
UICommand and UIInput components must be placed inside an UIForm
component, e.g. <h:form>.
Why is the h:button working then ?
from the h:button docs:
Render an HTML "input" element of type "button". The value of the
component is rendered as the button text and the outcome of the
component is used to determine the target URL which is activated by
onclick.
So ...
JSF will put your h:button outcome value in a javascript function that will be executed at an onclick event. But it will execute the action of the h:commandButton on the form submit with the POST method, so there should be a form to submit.

how to implement filter Search using Struts2 Jquery Plugin

I am trying to implement filter search for my Struts2 jquery grid. If I search any string (through jquery filter textbox) then it is calling my action class but i am unable to get the search string in my action class.
I tried to print this line inside my Action class but the Search String is not appearing in my Action class.
System.out.println("This line is getting printed But search textbox values is not printing."+searchString+""+searchField);
Please help me for this, i tried a lot ,and still am trying for it..
My Code:
Subjectinfo.jsp
<%# page contentType="text/html; charset=UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<%# taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<html>
<head>
<title>Hello World</title>
<style type="text/css">
#import
url(<%=request.getContextPath()%>/css/style1.css);
</style>
<sj:head jqueryui="true" jquerytheme="le-frog"/>
</head>
<body>
<div id="setpage"> <s:url id="editurl" action="nedit"/>
<s:url id="editurl" action="nedit"/>
<s:url id="remoteurl" action="ntable"/>
<sjg:grid
id="gridtable"
caption="Customer Examples"
dataType="json"
filter="true"
filterOptions="{ stringResult :true,
searchOnEnter : false,
enableClear : true,
gridModel="gridModel"
rowList="10,15,20"
navigatorDelete="true">
<sjg:gridColumn name="id" index="subjectId" title="ID" formatter="integer" sortable="true" key="true"
search="true" searchoptions="{sopt:['eq']}" editable="true" hidden="true" />
<sjg:gridColumn name="subjectName" index="subjectName" title="Subject Name" sortable="true" search="true"
editable="true"
edittype="text" />
</sjg:grid>
</div>
</body>
</html>
From http://www.trirand.com/jqgridwiki/doku.php?id=wiki:toolbar_searching
When the stringResult option is set to true the data posted to the server is a string and the structure of the posted data is the same as in Advanced Search.
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:advanced_searching#options
So I think your problem is that you are looking for searchString, but the jqgrid is sending a request variable called filters, which is a json string as described in the advanced search options link.

Resources