This question already has answers here:
JSP Unterminated <s:a> Tag With Nested OGNL
(2 answers)
Closed 6 years ago.
what is the reason behind the exception in struts2 jsp page? it throws following exception : Unterminated <s:textfield tag
<s:textfield name="createdDate" id="createdDate" cssClass="form-control width-xs" value="<s:property value="%{createdDate}"/>" />
You should not put one struts tag inside another which causes the exception
value="<s:property value="%{createdDate}"/>"
you can do it like this
value="%{createdDate}"
Related
This question already has an answer here:
According to TLD or attribute directive in tag file, attribute name does not accept any expressions
(1 answer)
Closed 5 years ago.
I am working on Struts 1.x to Struts 2.x migration and facing issues while assigning Scriptlet in textarea value.
The following code was written in Struts 1.x below :
<html:textarea name="shareFeedbackForm" style="height:50px;"
property="checkAllRemarks(${shrFeedbackHelperForm.groupId})" rows="1" cols="20"
value = '<%=(String)checkedMap.get(Long.parseLong((String)session.getAttribute("gId"))) %>' styleId="${shrFeedbackHelperForm.groupId}" onkeydown="limitRemarksText(this,500);" onkeyup="limitRemarksText(this,500);"></html:textarea>
I tried to re-write the same in Struts 2.x expression :
<s:textarea style="height:50px;"
name="webform.checkAllRemarks(%{#attr.shrFeedbackHelperForm.groupId})" rows="1" cols="20" value = '<%=(String)checkedMap.get(Long.parseLong((String)session.getAttribute("gId"))) %>' id="%{#attr.shrFeedbackHelperForm.groupId}" onkeydown="limitRemarksText(this,500);" onkeyup="limitRemarksText(this,500);"></s:textarea>
But, I am getting error in page where attribute value does not allow expressions. What is the correct way to assign the scriptlet in JSP page for Struts 2.x framework?
You Can Add Scriptlet in STRUTS 2 as follows
<%
String str=request.getAttribute("tDate").toString();
%>
<s:textfield value=<%=str %> name="toDate" id="toDate" />
Please try the following code
<s:textarea style="height:50px;"
name="webform.checkAllRemarks(%{#attr.shrFeedbackHelperForm.groupId})"
rows="1" cols="20" value = '<%=checkedMap.get(Long.parseLong(session.getAttribute("gId"))).toString() %>' id="%{#attr.shrFeedbackHelperForm.groupId}"
onkeydown="limitRemarksText(this,500);" onkeyup="limitRemarksText(this,500);"></s:textarea>
I have jsf validation on form where the invalid fields are highlighted based on
styleClass="#{component.valid ? 'reportInput' : 'reportInput_invalid'}"
and a tooltip is being used for displaying the error message as follows
<p:tooltip for="inputFieldId">
<p:message for="inputFieldId" />
</p:tooltip>
Everything works as expected but i want to improve user experience and want to introduce pure client side validation using
<p:clientValidator />
I tried this but it didnt work when onBlur event is fired on inputfield i got the following JS error
'null' is Null or no Object
in validation.js.jsf and the line code is
d.data("uiMessageId",b.attr("id"))
Is it possible to achieve?
An example of my input field is:
<p:inputText id="bic"
styleClass="#{component.valid ? 'reportInput' : 'reportInput_invalid'}"
value="#{bean.bic}"
required="true" requiredMessage="Field value is required" >
<p:watermark for="bic" value="CMHJKLIL" />
<pe:keyFilter regEx="/[a-z0-9]/i" />
<f:validateLength minimum="8" />
<p:clientValidator/>
</p:inputText>
I am using Primefaces 4 with the following maven dependency
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0</version>
</dependency>
Here as it looks in jsf page head section
Here is the validation.js file that is being used
validatuion.js here
i had the exact same error.
it seems that the validator.js code searches for a message container attached to the field, and, if cant find one, it searches one in the nearest form "e.findUIMessage(a,d.closest("form").find("div.ui-message"))"
what you need is to have an tag,
that is, a message assigned for the inputtext, so, when the validator generates an error, it can post the text in that message container.
I am trying to set the text in a button to either 'Enable' or 'Submit' depending on the value of a action class member(mode). But it is reporting an error which is saying 'equal symbol expected' on the first line. I searched and found that there are questions regarding 'equal symbol expected' error but nothing specific to Struts 2 tags. Neither I could spot any obvious error as missing closing quotes.
It would be nice if anyone can help.
<s:set name="submitButtonLabel" value="<s:if test="mode.equals('enable')">Enable</s:if> <s:else>Submit</s:else>" />
<s:submit value = "%{#submitButtonLabel}" cssClass="btn btn-gray" />
Try this:
<s:submit value="%{mode.equals('enable') ? 'Enable' : 'Submit'}" />
You cannot nest tags like that. Write your <s:if> inside <s:set> tag instead.
<s:set name="submitButtonLabel">
<s:if test="mode.equals('enable')">Enable</s:if>
<s:else>Submit</s:else>
</s:set>
I am using struts2 for my application.
<s:submit cssClass="button" key="btn.search" tabindex="12" />
in ApplicationResources.properties file i have
btn.search = Go
and i am getting error while submitting the page,
OgnlValueStac W com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
Error setting expression 'btn.search' with value '[Ljava.lang.String;#14f414f4'
ognl.OgnlException: target is null for setProperty(null, "search", [Ljava.lang.String;#14f414f4)
What's the problem?
The key attribute is a shorthand for both the name and value attributes.
Using key means you're assuming a property named btn.search.
While you may set a value to the results of a text property lookup, you can also use it directly:
<s:submit value="%{getText('btn.search')}" />
The key is being submitted as a parameter and OGNL is trying to get an object named btn from the ValueStack to set the parameter by calling getBtn().setSearch("");, but, since you have no btn object in the stack, the null target exception is occurring.
This should work:
<s:set name="buttonText"><s:text name="btn.search"/></s:set>
<s:submit cssClass="button" value="%{#buttonText}" tabindex="12"/>
Or, as Dave has pointed out in his answer, this should work as well if your action class extends ActionSupport:
<s:submit cssClass="button" value="%{getText('btn.search')}" tabindex="12"/>
I have configured global Exception mapping for java.lang.Exception and defined tiles results type.
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="exception" />
</global-exception-mappings>
Is there any way to get the Exception message using strut2 tags or any other jsp OR JSTL tags to find this exception message.
You can display information about the exception in the browser if you want by using s:property tags with a value of exception and exceptionStack. Something like
<h4>Exception Name: <s:property value="exception" /> </h4>
<h4>Exception Details: <s:property value="exceptionStack" /></h4>
When the exception interceptor is triggered it adds to the fields available for display the exception message and the exception's stack trace and its accessible to the S2tag using normal tag syntax.
For more information read the official S2 document page about Exception Handling
Exception-Handling
Define the property tag in global result page.
<s:property value="exception"/>
<s:property value="exceptionStack"/>