Display table tag in struts 2 - struts2

<display:table export="true" id="data" name="${sessionScope.forbesList}"requestURI="">
<a href="#" rel="tooltip" content="<span>
Name:<s:property value="#data.rank" /><br/>
Email: <a><s:property value="#data.name" /></a><br/>
Phone:<s:property value="#data.age" /> </span>"> <display:column property="rank" title="Rank" sortable="true" /></a>
<display:column property="name" title="Name" sortable="true" />
<display:column property="age" title="Age" sortable="true" />
</display:table>
In Struts 2 I'm trying to use <s:property> tag inside <display :column> tag but I can only see the <display:column> values and not the values that I access with <s:property>. How to do it?

#1: Anchor (<A>) Tag does not have any content attribute.
Please refer to the documentation to see which attributes it supports and how to use them.
#2: in HTML, when putting the character " into an attribute of a Tag, you can:
substitute " with ', like in
myAttribute="this is 'right'" or
myAttribute='this is "right" too', or
encode the " with the html entity ", like in
myAttribute="this is "right""
You must encode the < and > too, with < (Less Than) or > (Greater Than).
#3: that said, you could put your HTML inside the Anchor Tag, in the place where it is supposed to be inserted, like :
<a href="#" rel="tooltip">
Name:<s:property value="#data.rank" />
</a>
but, in your case, you are injecting a lot of HTML, including another Anchor, that is not possible. I think you should simply use a div or something similar as a container, like:
<div rel="tooltip" >
<span>
Name:<s:property value="#data.rank" /><br/>
Email: <a><s:property value="#data.name" /></a><br/>
Phone:<s:property value="#data.age" />
</span>
</div>
Resolve this before worrying about DisplayTag
EDIT
#4
Change
<s:property value="#data.rank" />
(and all the other tags) to
<s:property value="#attr.data.rank" />
#attr is the OGNL used to access the pageContext,
if it is available, otherwise it searches request, session and application scopes.

Related

Get anchor tag value when anchor tag is inside for each loop

<c:forEach items="${customer.iscutomer}">
<div>
<i>${customer.customerNumber}. </i>
<li>
${customer.customerName}
</li>
</div>
</c:forEach>
i don't know how to get customer name in Struts2 when user selects any hyerlink(customer name come from customer object).
You can use Struts anchor tag and add parameter to the URL.
<s:a href="url"><s:param name="customerName">${customer.customerName}</s:param>CustomerName</s:a>
Note, that you can use EL in the body of the tag.
May be this can help you to start:
<c:forEach items="${customer.iscutomer}">
<div>
<i>${customer.customerNumber}. </i>
<li>
<s:a name="foo" namespace="bar">
<s:param name="customerName">${customer.customerName}</s:param>
<s:param name="customerNubmber">${customer.customerNumber}</s:param>
</s:a>
</li>
</div>
Please consider I find that the s:a url does not add parameters to link. Now your generated link will be /foo/bar/action?customerName=joe&customerNumber=1
No in your JS you can have:
$('a').bind('click',function(){
var url = ($(this).attr('href'));
var customerName= getURLParameter(url, 'customerName');
var customerNumber= getURLParameter(url, 'customerNumber');
//calling the ajax function
pop(cat, typ)
});
If you want to have ajax calls please have a look at struts 2 jquery plugin.

How to use if, else condition in jsf to display image

I have a condition where I have an enrollment form in which if userid is 0 it should show the dummy image and when I edit user from any update, I check for if userid which is not equal to 0 then display the image corresponding to userid.
I used JSTL inside jsf page. But always it tries to go to else loop for showing image. The functionality is working fine. The only thing is I can't display the dummy image when I visit the page first. Here s my code.:
<c:if test="${'#{user.userId}' == '0'}">
<a href="Images/thumb_02.jpg" target="_blank" ></a>
<img src="Images/thumb_02.jpg" />
</c:if>
<c:otherwise>
<a href="/DisplayBlobExample?userId=#{user.userId}" target="_blank"</a>
<img src="/DisplayBlobExample?userId=#{user.userId}" />
</c:otherwise>
Can I use this JSTL tag or can I do it using jsf?
For those like I who just followed the code by skuntsel and received a cryptic stack trace, allow me to save you some time.
It seems c:if cannot by itself be followed by c:otherwise.
The correct solution is as follows:
<c:choose>
<c:when test="#{some.test}">
<p>some.test is true</p>
</c:when>
<c:otherwise>
<p>some.test is not true</p>
</c:otherwise>
</c:choose>
You can add additional c:when tests in as necessary.
It is illegal to nest EL expressions: you should inline them. Using JSTL is perfectly valid in your situation. Correcting the mistake, you'll make the code working:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core">
<c:if test="#{not empty user or user.userId eq 0}">
<a href="Images/thumb_02.jpg" target="_blank" ></a>
<img src="Images/thumb_02.jpg" />
</c:if>
<c:if test="#{empty user or user.userId eq 0}">
<img src="/DisplayBlobExample?userId=#{user.userId}" />
</c:if>
</html>
Another solution is to specify all the conditions you want inside an EL of one element. Though it could be heavier and less readable, here it is:
<img src="#{not empty user or user.userId eq 0 ? '/Images/thumb_02.jpg' : '/DisplayBlobExample?userId='}#{not empty user or user.userId eq 0 ? '' : user.userId}" target="_blank"></img>
Instead of using the "c" tags, you could also do the following:
<h:outputLink value="Images/thumb_02.jpg" target="_blank" rendered="#{not empty user or user.userId eq 0}" />
<h:graphicImage value="Images/thumb_02.jpg" rendered="#{not empty user or user.userId eq 0}" />
<h:outputLink value="/DisplayBlobExample?userId=#{user.userId}" target="_blank" rendered="#{not empty user and user.userId neq 0}" />
<h:graphicImage value="/DisplayBlobExample?userId=#{user.userId}" rendered="#{not empty user and user.userId neq 0}"/>
I think that's a little more readable alternative to skuntsel's alternative answer and is utilizing the JSF rendered attribute instead of nesting a ternary operator.
And off the answer, did you possibly mean to put your image in between the anchor tags so the image is clickable?

Multiline textbox in Formview with DynamicDataTemplatesCS

Using model binding with the above like so:
<asp:FormView runat="server" ID="ConversationForm" DefaultMode="Edit"
OnCallingDataMethods="ConversationForm_CallingDataMethods"
ItemType="MyApp.Model.Conversation"
DataKeyNames="ConversationID"
SelectMethod="GetConversation"
UpdateMethod="UpdateConversation"
OnItemUpdated="Conversation_ItemUpdated">
<EditItemTemplate>
<fieldset>
<legend>Conversation Notes:</legend>
<ol>
<asp:DynamicEntity runat="server" Mode="Edit" />
</ol>
</fieldset>
<asp:Button ID="btnUpdate" runat="server" Text="Save" CommandName="Update" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" OnClick="btnCancel_Click" />
</EditItemTemplate>
</asp:FormView>
The Conversation entity basically has one property, "Text", which should contain freeform text captured by the user.
The DynamicEntity control generates a simple textbox for this property as it has a datatype of string.
How do I tell it to create a multiline textbox instead?
Can I add some sort of data annotation to the Conversation class that will tell the Dynamic Templates to create a multiline textbox?
It does not seem to be possible so I had to revert to using a static asp:Textbox control with the TextMode="MultiLine" property set.

struts2 TreeMap: keys with spaces not appearing in action

JSP Code:
<s:iterator value="#currentRequisitionGroup.plFldWrap.allPFields" var="pMap" status="hStatus">
<s:iterator value="#pMap.value.paramMdlList" var="paramModel" status="fStat">
<li>
<label>
<s:property value="#paramModel.parameterName" />
</label>
<s:set var="cEdit" value="%{#paramModel.isEditable}"> </s:set>
<s:if test="%{#cEdit == true}">
<s:textfield id="paramId_%{#paramModel.parameterId}" name="rqPGPrmMdl.rqGrp[% {#cGStat.index}].plFldWrap.allPFields['%{(#pMap.key)}'].paramMdlList[%{#fStat.index}].prmValue"/>
</s:if>
<s:else>
<s:textfield id="paramId_%{#paramModel.parameterId}" name="rqPGPrmMdl.rqGrp[% {#cGStat.index}].plFldWrap.allPFields['%{(#pMap.key)}'].paramMdlList[%{#fStat.index}].prmValue" readonly="true"/>
</s:else>
</li>
<s:hidden id="prmId_%{#paramModel.parameterId}" name="rqPGPrmMdl.rqGrp[%{#cGStat.index}].plFldWrap.allPFields['%{(#pMap.key)}'].paramMdlList[%{#fStat.index}].parameterId"></s:hidden>
<s:hidden id="paramName_%{#paramModel.parameterId}" name="rqPGPrmMdl.rqGrp[%{#cGStat.index}].plFldWrap.allPFields['%{(#pMap.key)}'].paramMdlList[%{#fStat.index}].parameterName"></s:hidden>
<s:hidden id="pGId_%{#paramModel.parameterId}" name="rqPGPrmMdl.rqGrp[%{#cGStat.index}].plFldWrap.allPFields['%{(#pMap.key)}'].paramMdlList[%{#fStat.index}].parameterGroupId"></s:hidden>
<s:hidden id="seqNo_%{#paramModel.parameterId}" name="rqPGPrmMdl.rqGrp[%{#cGStat.index}].plFldWrap.allPFields['%{(#pMap.key)}'].paramMdlList[%{#fStat.index}].sequenceNumber"></s:hidden>
</s:iterator>
</s:iterator>
The problem is that some values do not appear in action.
Investigation till now indicates that, if the corresponding html input has space in the key of allPFields, that value doesn't appear in action.
<input id="prmId_30" type="hidden" value="30"
name="rqPGPrmMdl.rqGrp[1].plFldWrap.allPFields['Emp System'].paramMdlList[0].parameterId">
However, if the corresponding html input has no space in the key of allPFields, that value appears in action.
<input id="prmId_46" type="hidden" value="30" name="rqPGPrmMdl.rqGrp[1].plFldWrap.allPFields['Emp'].paramMdlList[0].parameterId">
Here is what the logs say:
xwork2.interceptor.ParametersInterceptor - Parameter [rqPGPrmMdl.rqGrp[1].plFldWrap.allPFields['Emp System'].paramMdlList[0].parameterId] **didn't match acceptedPattern pattern!**
This is happening because white spaces are not accepted in parameter names. You can change acceptParamNames parameter of the ParametersInterceptor, BUT as the documentation states
acceptParamNames - a comma delimited list of regular expressions to describe a whitelist of accepted parameter names. Don't change the default unless you know what you are doing in terms of security implications
So I suggest you to get rid of white spaces in parameters names.

Grails filterPane plugin to fit page layout

I would like to have the filterPane to be inserted in my own div in order to fit my page layout. Basically I want to get rid of the default pop-up behavior and harmonize filterPane with the other elements of the application.
this is my gsp
<div class="filter">
<p>
<filterpane:isFiltered>
<filterpane:currentCriteria domainBean="demoracer.Pilot" />
</filterpane:isFiltered>
</p>
<g:formRemote method="post" name="form_search" url="${[action:'list']}" update="listContainer" >
<filterpane:filterPane customForm="true" formName="form_search" domainBean="demoracer.Pilot"
filterProperties="name," id="filterpaneContainer" />
<g:actionSubmit value="Apply Filter From Outside Filter Pane" action="list" />
</g:formRemote>
</div>
but the pane do not show up.
Thanks
Since the filterpane generates its own div, can't you just use the div it generates and restyle it to fit your layout? You can specify the id, class, and style attributes of the container div it generates. That should be more than enough to restyle it any way you'd like.
it doesn't seems possible since the html is statically created by the taglib
def output = """\
<div id="${containerId}"
class="filterPane ${containerClass ?: ''}"
style="display:none;${containerStyle}">
<h2>${title}</h2>
${openFormTag}
<input type="hidden" name="filterProperties" value="${propsStr}" />
<table cellspacing="0" cellpadding="0" class="filterTable">
"""

Resources