JSTL split Radio button into two lists - jstl

I am trying to split my Radio Button list into "n" number of columns based on number of Rows. This is what I was trying, here programs is my list which currently has 17 Radio Buttons. I am trying to divide (17/2) rows and 2 columns currently.
<c:set var="numRows" value="${fn:length(programs)/2-0.5}" />
<c:set var="totalRows" value="${fn:length(programs)}" />
<c:forEach begin="0" end="${numRows }" varStatus="i">
<c:out value="i=${i.index} " />
<c:set var="rowStart" value="${i.index * numColumns}" />
<fmt:formatNumber var="numColumns" value="${fn:length(programs) / numRows}"
maxFractionDigits="0" />
<c:forEach begin="0" end="${numColumns - 1}" varStatus="j" >
<c:set var="index" value="${rowStart + j.index}"/>
<c:out value="j=${j.index} " />
<c:choose>
<c:when test="${index lt fn:length(programs)}">
<c:forEach var="prgip" items="${programs}">
<c:forEach begin="0" end="${totalRows }" varStatus="k" var="prgip" items="${programs}">
<input type="radio" value="${prgip.program_id}" name="program"> ${prgip.program_name}
<c:out value="k=${k.count} " />
</c:forEach>
</c:forEach>
</c:when>
<c:otherwise> </c:otherwise>
</c:choose>
</c:forEach>
</c:forEach>
Thanks in Advance
-Mim Jones.

Related

To show the default value and maintain ordering in dropdown values

I am working on an application that needs to display a set of questions as a drop down(the user needs to answer 3 questions) in the jsp page.
It works fine, but the issue is for each time I display the drop down list(the questions are same), the questions selected by default are different - the actual question I set in the controller. I need to be able to just display the first or "Select" string as the default option.
My jsp:
<tr>
<br />
<form:label path="qs1">
<span class="">qs 1</span>
</form:label>
<br />
<form:select path="qs1" multiple="false">
<form:option value="${obj.qs0}" label="${obj.qs0}" />
<form:option value="${obj.qs1}" label="${obj.qs1}" />********In this instance this option is shown in the drop down
<form:option value="${obj.qs2}" label="${obj.qs2}" />
<form:option value="${obj.qs3}" label="${obj.qs3}" />
</form:select>
<br />
</tr>
<tr>
<br />
<form:label path="as1">
<span class="">as 1</span>
</form:label>
<br />
<form:input class="" path="as1" />
<br />
</tr>
<tr>
<br />
<form:label path="qs2">
<span class="">qs 2</span>
</form:label>
<br />
<form:select path="qs2" multiple="false">
<form:option value="${obj.qs0}" label="${obj.qs0}" />
<form:option value="${obj.qs1}" label="${obj.qs1}" />
<form:option value="${obj.qs2}" label="${obj.qs2}" />********In this instance this option is shown in the drop down
<form:option value="${obj.qs3}" label="${obj.qs3}" />
</form:select>
<br />
</tr>
<tr>
<br />
<form:label path="as2">
<span class="">as 2</span>
</form:label>
<br />
<form:input class="" path="as2" />
<br />
</tr>
I even tried selected="selected" for the right ones, but it did not work. Any suggestions would be helpful. Thanks.
EDIT: I should have been clear. I did try the option Amit suggested, as of now the obj.qs0 has the value instead of mentioning that in the JSP. I have just added that option along with the questions. The issue is I need to set the questions to the Questions object like below
Questions qs = new Questions();
qs.setQs0("----------Select-------------");
qs.setQs1("what is the name");
qs.setQs2("what is the color");
and so on.
So in the jsp I am setting the path
<form:select path="qs1" multiple="false">
<form:select path="qs2" multiple="false">
So those questions(q1, q2, and so on) are selected automatically and I cannot change the selection to always point to the qs0(where I have the default option). I also need to set the paths differently as I need to be able to capture the different questions & answers the users select.
1) To display "Select" as default, you can add below line :-
<form:select path="qs1" multiple="false">
**<form:option value="NONE" label="--- Select ---" />**
<form:option value="${obj.qs0}" label="${obj.qs0}" />
<form:option value="${obj.qs1}" label="${obj.qs1}" />
<form:option value="${obj.qs2}" label="${obj.qs2}" />
<form:option value="${obj.qs3}" label="${obj.qs3}" />
</form:select>
2) Use the LinkedHashMap or LinkedList to store the drop-down values in order to maintain ordering.

how to list the children of selected node in oracle webcenter portal

I need to add an additional navigation to my oracle webcenter portal project. This additional navigation should show the children of the selected node in navigation bar. Also, this additional navigation is should be in a left sidebar. How can i do this ?
<af:panelGroupLayout layout="vertical">
<c:forEach var="node" varStatus="vs" items="#{navigationContext.currentModel.listModel['startNode=/, includeStartNode=false']}">
<c:if test="${node.selected}">
<c:set value="${node.children}" var="childNodes" scope="session"/>
</c:if>
</c:forEach>
<c:if test="${childNodes ne null}">
<c:set var="childNodes" value="${navigationContext.currentModel.currentSelection.parent.children}"/>
</c:if>
<c:forEach items="#{childNodes}" var="node2">
<af:commandImageLink id="cil3" text="#{node2.title}"
actionListener="#{navigationContext.processAction}"
action="pprnav"
icon="#{node2.attributes[pageFlowScope.tnBean.iconKey]}"
disabled="#{not node2.navigable}"
inlineStyle="#{node2.onSelectedPath ? 'font-weight:bold;' : ''}">
<f:attribute name="node" value="#{node2}"/>
</af:commandImageLink>
</c:forEach>
</af:panelGroupLayout>

JSPX page breaks when script tag has src attribute

For some odd reason whenever I add a src element to the script tag at the end of this JSPX block, the first half of the page refuses to load. Cutting the HTML prior to the line out, and completely hosing the page. I've tried several different option here, including a CDATA block, making the script inline, and completely removing it from the page. For whatever reason, having anything that renders within that script block breaks the page.
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:spring="urn:jsptld:/WEB-INF/tlds/spring.tld"
xmlns:spring-form="urn:jsptld:/WEB-INF/tlds/spring-form.tld"
xmlns:intela-coreg="urn:jsptld:/WEB-INF/tlds/intela-coreg.tld"
xmlns:c="urn:jsptld:/WEB-INF/tlds/c.tld"
xmlns:x="urn:jsptld:/WEB-INF/tlds/x.tld"
xmlns:fmt="urn:jsptld:/WEB-INF/tlds/fmt.tld"
xmlns:fn="urn:jsptld:/WEB-INF/tlds/fn.tld"
xmlns:intela="urn:jsptagdir:/WEB-INF/tags/intela" version="2.0">
<jsp:directive.page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"/>
<c:set var = "myPath" value ="${sessionPath.regPath.pathName}" />
<c:set var = "pathParts" value="${fn:split(myPath, '_')}" />
<c:set var = "myPathPlacement" value = "${pathParts[0]}" />
<!-- Add the container code based on domain -->
<c:choose>
<!-- Australia -->
<c:when test ="${myPathPlacement == 'ap'}">
<c:set var ="gCode" value ="GTM-FR7W" />
</c:when>
<c:when test ="${myPathPlacement == 'as'}">
<c:set var ="gCode" value ="GTM-64GD" />
</c:when>
<c:when test ="${myPathPlacement == 'xaph'}">
<c:set var ="gCode" value ="GTM-TBNP" />
</c:when>
<!-- Canada -->
<c:when test ="${myPathPlacement == 'cp'}">
<c:set var ="gCode" value ="GTM-J578" />
</c:when>
<c:when test ="${myPathPlacement == 'xcph'}">
<c:set var ="gCode" value ="GTM-6WG2" />
</c:when>
<!-- Netherlands -->
<c:when test ="${myPathPlacement == 'nl2'}">
<c:choose>
<c:when test = "${pathParts[1] == 'voucher'}" >
<c:set var ="gCode" value ="GTM-6S7B" />
</c:when>
<c:when test = "${pathParts[1] == 'scooter'}">
<c:set var ="gCode" value = "GTM-8W4R" />
</c:when>
</c:choose>
</c:when>
<!-- Spain -->
<c:when test ="${myPathPlacement == 'es'}">
<c:choose>
<c:when test = "${fn:contains(pathParts[1], 'apple')}" >
<c:set var ="gCode" value ="GTM-JVG5" />
</c:when>
<c:when test = "${pathParts[1] == 'elcorteingles'}">
<c:set var ="gCode" value = "GTM-53L3" />
</c:when>
</c:choose>
</c:when>
<!-- France -->
<c:when test ="${myPathPlacement == 'fr'}">
<c:choose>
<c:when test = "${fn:contains(pathParts[1], 'peage')}" >
<c:set var ="gCode" value ="GTM-F5DR" />
</c:when>
</c:choose>
</c:when>
<c:when test ="${myPathPlacement == 'fr2'}">
<c:set var ="gCode" value ="GTM-ZG2J" />
</c:when>
<!-- UK -->
<c:when test ="${myPathPlacement == 'hp'}">
<c:choose>
<c:when test = "${pathParts[1] == 'uk'}" >
<c:set var ="gCode" value ="GTM-4LX8" />
</c:when>
</c:choose>
</c:when>
<c:when test ="${myPathPlacement == 'p2w'}">
<c:set var ="gCode" value ="GTM-S73N" />
</c:when>
<c:when test ="${myPathPlacement == 'pu'}">
<c:set var ="gCode" value ="GTM-7BRV" />
</c:when>
<c:when test ="${myPathPlacement == 'xurt'}">
<c:set var ="gCode" value ="GTM-TH5Q" />
</c:when>
<c:when test ="${myPathPlacement == 'TechRewardsUK'}">
<c:set var ="gCode" value ="GTM-Q3PL" />
</c:when>
<!-- USA -->
<c:when test ="${myPathPlacement == 'cd'}">
<c:set var ="gCode" value ="GTM-B4D5" />
</c:when>
<c:when test ="${myPathPlacement == 'uspr'}">
<c:set var ="gCode" value ="GTM-PZTJ" />
</c:when>
<c:when test ="${myPathPlacement == 'usrt'}">
<c:set var ="gCode" value ="GTM-QMZG" />
</c:when>
<c:when test ="${myPathPlacement == 'ussr'}">
<c:set var ="gCode" value ="GTM-GRJK" />
</c:when>
<c:when test ="${myPathPlacement == 'us'}">
<c:set var ="gCode" value ="GTM-W285" />
</c:when>
</c:choose>
<c:set var = "gCodeLength" value = "${fn:length(gCode)}" />
<!-- Test to see if this page needs the code or move along, these are not the droids we are looking for -->
<c:if test = "${gCodeLength > 0}" >
<script src="/media/common/js/googleTagManager.js"><!-- test --></script>
</c:if>

Spring Roo File Upload

Hy everyone!
Im trying to implement file upload with Spring roo. The files path will be persisted in the database, and the file will be saved on the file system.
According to informations found on the spring dveloper board, i modified the input.tagx and create.tagx files.(info: https://jira.springsource.org/browse/ROO-442)
input.tagx:
<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:form="http://www.springframework.org/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:output omit-xml-declaration="yes" />
<jsp:directive.attribute name="id" type="java.lang.String" required="true" rtexprvalue="true" description="The identifier for this tag (do not change!)" />
<jsp:directive.attribute name="field" type="java.lang.String" required="true" rtexprvalue="true" description="The field exposed from the form backing object" />
<jsp:directive.attribute name="label" type="java.lang.String" required="false" rtexprvalue="true" description="The label used for this field, will default to a message bundle if not supplied" />
<jsp:directive.attribute name="labelCode" type="java.lang.String" required="false" rtexprvalue="true" description="Key for label message bundle if label is not supplied" />
<jsp:directive.attribute name="required" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicates if this field is required (default false)" />
<jsp:directive.attribute name="disabled" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Specify if this field should be enabled" />
<jsp:directive.attribute name="validationRegex" type="java.lang.String" required="false" rtexprvalue="true" description="Specify regular expression to be used for the validation of the input contents" />
<jsp:directive.attribute name="validationMessageCode" type="java.lang.String" required="false" rtexprvalue="true" description="Specify the message (message property code) to be displayed if the regular expression validation fails" />
<jsp:directive.attribute name="validationMessage" type="java.lang.String" required="false" rtexprvalue="true" description="Specify the message to be displayed if the regular expression validation fails" />
<c:if test="${empty render or render}"
<c:when test="${disableFormBinding}">
<input id="_${field}_id" name="${field}" type="${type}"/>
</c:when>
<c:otherwise>
<!-- currently (spring 3.0.3), form:input doesn't support type attribute -->
<!-- <form:input id="_${field}_id" path="${field}" disabled="${disabled}"/> -->
<input id="_${field}_id" name="${field}" type="${type}"/>
<br/>
<form:errors cssClass="errors" id="_${field}_error_id" path="${field}"/>
</c:otherwise>
<c:if test="${empty disabled}">
<c:set value="false" var="disabled" />
</c:if>
<c:if test="${empty label}">
<c:if test="${empty labelCode}">
<c:set var="labelCode" value="${fn:substringAfter(id,'_')}" />
</c:if>
<spring:message code="label_${fn:toLowerCase(labelCode)}" var="label" htmlEscape="false" />
</c:if>
<c:if test="${empty validationMessage}">
<c:choose>
<c:when test="${empty validationMessageCode}">
<spring:message arguments="${fn:escapeXml(label)}" code="field_invalid" var="field_invalid" htmlEscape="false" />
</c:when>
<c:otherwise>
<spring:message arguments="${fn:escapeXml(label)}" code="${validationMessageCode}" var="field_invalid" htmlEscape="false" />
</c:otherwise>
</c:choose>
</c:if>
<c:if test="${empty required}">
<c:set value="false" var="required" />
</c:if>
<c:set var="sec_field">
<spring:escapeBody javaScriptEscape="true" >${field}</spring:escapeBody>
</c:set>
<div id="_${fn:escapeXml(id)}_id">
<label for="_${sec_field}_id">
<c:out value="${fn:escapeXml(label)}" />
:
</label>
<c:choose>
<c:when test="${disableFormBinding}">
<input id="_${sec_field}_id" name="${sec_field}" type="${fn:escapeXml(type)}" />
</c:when>
<c:otherwise>
<c:choose>
<c:when test="${type eq 'password'}">
<form:password id="_${sec_field}_id" path="${sec_field}" disabled="${disabled}" />
</c:when>
<c:otherwise>
<form:input id="_${sec_field}_id" path="${sec_field}" disabled="${disabled}" />
</c:otherwise>
</c:choose>
<br />
<form:errors cssClass="errors" id="_${sec_field}_error_id" path="${sec_field}" />
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${required}">
<spring:message code="field_required" var="field_required" htmlEscape="false" />
<spring:message argumentSeparator="," arguments="${label},(${field_required})" code="field_simple_validation" var="field_validation" htmlEscape="false" />
</c:when>
<c:otherwise>
<spring:message argumentSeparator="," arguments="${label}, " code="field_simple_validation" var="field_validation" htmlEscape="false" />
</c:otherwise>
</c:choose>
<c:set var="sec_field_validation">
<spring:escapeBody javaScriptEscape="true">${field_validation}</spring:escapeBody>
</c:set>
<c:set var="sec_field_invalid">
<spring:escapeBody javaScriptEscape="true" htmlEscape="true">${field_invalid}</spring:escapeBody>
</c:set>
<c:set var="sec_field_required">
<spring:escapeBody javaScriptEscape="true">${field_required}</spring:escapeBody>
</c:set>
<c:set var="sec_validation_regex" value="" />
<c:if test="${!empty validationRegex}">
<c:set var="sec_validation_regex" value="regExp : '${validationRegex}', " />
</c:if>
<script type="text/javascript">
Spring.addDecoration(new Spring.ElementDecoration({elementId : '_${sec_field}_id', widgetType : 'dijit.form.ValidationTextBox', widgetAttrs : {promptMessage: '${sec_field_validation}', invalidMessage: '${sec_field_invalid}', required : ${required}, ${sec_validation_regex} missingMessage : '${sec_field_required}' }}));
</script>
</div>
<br />
</c:if>
</jsp:root>
create.tagx:
<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:util="urn:jsptagdir:/WEB-INF/tags/util" xmlns:form="http://www.springframework.org/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:spring="http://www.springframework.org/tags" version="2.0">
<jsp:output omit-xml-declaration="yes"/>
<jsp:directive.attribute name="id" type="java.lang.String" required="true" rtexprvalue="true" description="The identifier for this tag (do not change!)"/>
<jsp:directive.attribute name="modelAttribute" type="java.lang.String" required="true" rtexprvalue="true" description="The name of the model attribute for form binding"/>
<jsp:directive.attribute name="path" type="java.lang.String" required="true" rtexprvalue="true" description="Specify the relative URL path (wit leading /)" />
<jsp:directive.attribute name="compositePkField" type="java.lang.String" required="false" rtexprvalue="true" description="The field name of the composite primary key (only used if a composite PK is present in the form backing object)" />
<jsp:directive.attribute name="multipart" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicate if this is a multipart form (default: false)" />
<jsp:directive.attribute name="label" type="java.lang.String" required="false" rtexprvalue="true" description="The label used for this object, will default to a message bundle if not supplied"/>
<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')" />
<jsp:directive.attribute name="openPane" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Control if the title pane is opened or closed by default (default: true)"/>
<jsp:directive.attribute name="z" type="java.lang.String" required="false" description="Used for checking if element has been modified (to recalculate simply provide empty string value)"/>
<jsp:directive.attribute name="enctype" type="java.lang.String" required="false" description="Used to set the enctype, e.g. multipart/form-data for file upload support. "/>
<c:if test="${empty render or render}">
<c:if test="${empty label}">
<spring:message code="label_${fn:toLowerCase(fn:substringAfter(id,'_'))}" var="label" htmlEscape="false" />
</c:if>
<!--<c:set var="enctype" value="application/x-www-form-urlencoded"/> -->
<form:form action="${form_url}" method="POST" modelAttribute="${modelAttribute}" enctype="${enctype}">
</form:form>
<c:if test="${multipart}">
<c:set var="enctype" value="multipart/form-data"/>
</c:if>
<spring:message arguments="${label}" code="entity_create" var="title_msg" htmlEscape="false" />
<util:panel id="${id}" title="${title_msg}" openPane="${openPane}">
<spring:url value="${path}" var="form_url"/>
<c:set var="jsCall" value=""/>
<c:if test="${not empty compositePkField}">
<c:set var="jsCall" value="encodePk()" />
</c:if>
<form:form action="${form_url}" method="POST" modelAttribute="${modelAttribute}" enctype="${enctype}" onsubmit="${jsCall}">
<form:errors cssClass="errors" delimiter="<p/>"/>
<c:if test="${not empty compositePkField}">
<form:hidden id="_${fn:escapeXml(compositePkField)}_id" path="${fn:escapeXml(compositePkField)}" />
<script type="text/javascript">
<![CDATA[
dojo.require("dojox.encoding.base64");
function encodePk() {
var obj = new Object();
dojo.query("input[name^=\"${compositePkField}.\"]").forEach(function(node, index, nodelist){
obj[node.name.substring('${compositePkField}'.length + 1)] = node.value;
});
var json = dojo.toJson(obj);
var tokArr = [];
for (var i = 0; i < json.length; i++) {
tokArr.push(json.charCodeAt(i));
}
var encoded = dojox.encoding.base64.encode(tokArr);
dojo.byId('_${fn:escapeXml(compositePkField)}_id').value = encoded;
}
]]>
</script>
</c:if>
<jsp:doBody />
<div class="submit" id="${fn:escapeXml(id)}_submit">
<spring:message code="button_save" var="save_button" htmlEscape="false" />
<script type="text/javascript">Spring.addDecoration(new Spring.ValidateAllDecoration({elementId:'proceed', event:'onclick'}));</script>
<input id="proceed" type="submit" value="${fn:escapeXml(save_button)}"/>
</div>
</form:form>
</util:panel>
</c:if>
</jsp:root>
My problem is i get the fallowing error:
javax.servlet.jsp.JspTagException: Illegal use of <when>-style tag without <choose> as its direct parent
at org.apache.taglibs.standard.tag.common.core.WhenTagSupport.doStartTag(WhenTagSupport.java:95)
at org.apache.jsp.tag.web.form.fields.input_tagx._jspx_meth_c_005fwhen_005f0(input_tagx.java:519)
at org.apache.jsp.tag.web.form.fields.input_tagx.doTag(input_tagx.java:325)
at org.apache.jsp.WEB_002dINF.views.pphotoes.create_jspx._jspx_meth_field_005finput_005f0(create_jspx.java:172)
at org.apache.jsp.WEB_002dINF.views.pphotoes.create_jspx.access$2(create_jspx.java:157)
What am i doing wrong? (My controller and entity files are good i think, if needed i can post them)
Thx for any help.
cheers.
As the error message clearly states, you need to have a <c:choose> as a direct parent tag before the <c:when> tag - possibly in the following first few lines of your input.tagx file. Additionally, the <c:if> tag is not closed properly.
<c:if test="${empty render or render}"
<c:when test="${disableFormBinding}">
Cheers.

Iterate over a collection and put results in a Variable?

I tried asking this question but may have worded it wrong. Im doing this:
<c:forEach var="cell" items="${row}" varStatus="rowStatus">
<td class="data_extract">
<c:choose>
<c:when test="${results.types[rowStatus.index].array}">
<c:forEach var="elem" items="${cell}" varStatus="cellStatus">
${elem}<c:if test="${!cellStatus.last}">, </c:if>
</c:forEach>
</c:when>
<c:otherwise>
${cell}
</c:otherwise>
</c:choose>
</td>
For example ${elem} will loop a couple times and will have this in the cell: "10GT, 137S" after the loop is done. I want to maybe concatenante a variable so "10GT, 137S" is assigned a variable so that I might pass into:
<span class="mouseover_text" title="${NEW VARIABLE HERE!!!!!!!}"></span>
Please help a brother...
EDIT:
This seems to work!!
<td class="data_extract">
<c:choose>
<c:when test="${results.types[rowStatus.index].array}">
<c:set var="comma" value="," />
<c:forEach var="elem" items="${cell}" varStatus="cellStatus">
<c:set var="myVar" value="${cellStatus.first ? '' : myVar} ${elem} ${cellStatus.last ? '' : comma}" />
</c:forEach>
<span class="mouseover_text" title="${myVar}">${myVar}</span>
</c:when>
<c:otherwise>
${cell}
</c:otherwise>
</c:choose>
</td>
<td class="data_extract">
<c:choose>
<c:when test="${results.types[rowStatus.index].array}">
<c:set var="comma" value="," />
<c:forEach var="elem" items="${cell}" varStatus="cellStatus">
<c:set var="myVar" value="${cellStatus.first ? '' : myVar} ${elem} ${cellStatus.last ? '' : comma}" />
</c:forEach>
<span class="mouseover_text" title="${myVar}">${myVar}</span>
</c:when>
<c:otherwise>
${cell}
</c:otherwise>
</c:choose>
</td>

Resources