Variable in an attribute in Struts custom tag - struts

I am trying to use a variable inside a custom Struts tag something like follows -
for(String currentMacro : (List<String>)(request.getAttribute("individualMacros"))) {
name = currentMacro.<some-operation>
<html:mce name = "hmtl_<%= name %>" />
Something like this. But <%=name%> is not replaced with the variable value. It works when I am using the variable with a pure HTML tags.
Is there any any way to accomplish this in this case?
Thanks.

Use JSP EL (assuming JSP 2.0, and you put "name" into scope). You could also check to the if the TLD allows rtexprs.
<html:mce name="html_${name}"/>
But why use scriptlets? There's rarely (ever?) a good reason.

Since we are taking about a custom tag, my guess is that in the TLD file there isn't the rtexprvalue option set to true for that particular tag attribute:
<attribute>
<name>name</name>
<rtexprvalue>true</rtexprvalue>
.......
</attribute>
The rtexprvalue specifies that the attribute value may be dynamically evaluated at runtime.
If set to "false" it means that the attribute has a static value which is evaluated at translation; if set to "true" it means the value can be determined dynamically at runtime. Default is "false".
If the scriptlet does not work, it most likely means rtexprvalue is false. If you don't have the liberty to change that, then expressions won't work on that particular attribute.

Related

Allow custom attribute to a script tag element?

I can't validate script tag with attribute nomodule.
I am using odoo framework which is a python backend. It is using lxml to validate xml views or pages. I am building a view with a script tag like:
<script src="src.js" nomodule></script>
It returns an error
lxml.etree.XMLSyntaxError: Specification mandate value for attribute nomodule
However this should be valid according to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
Is there a way so that I can make the parser ignore this new attribute or I can bypass such as special data or character.
That's possibly because XML != HTML. And as you can see in the error, it's an XML error.
Is an xml attribute without a value, valid? --> your attribute isn't valid.
You need to specify the attribute value always in xml. Odoo uses xml to produce html, so you need to comply with xml rules. You can do it in this case by specifying an empty value for xml attribute like this:
<script src="src.js" nomodule=””></script>

Reg: izPack dynamic variables

How to assign dynamic variable value from file in izPack.
Can you please post some code snippet?
I tried it with the following syntax:
<variable name="EXIST_IP_ADDRESS" file="${INSTALL_PATH}/test.properties"
type="options" key="IpAddress"/>
But am getting error says that value attribute is mandatory. If I assign value with some string then this cannot be loaded from file. Please check what mistakes am doing.
Dynamic variables have their own section, I guess you are trying to use it in "variables" section.
<dynamicvariables>
<variable name="previous.JAVA_HOME" escape="false" file="${INSTALL_PATH}/run.cmd" type="options" key="SET JRE" ignorefailure="true">
</dynamicvariables>

How to set boolean in xml-action script

I am trying to set a flag so I do something like this:
<set field="existingFound" value="false" type="Boolean"/>
but the following line prints "true" in the log:
<log message="storeProperty, existingFound (0): ${existingFound}"/>
What is the best way to set flags?
The set.#value attribute is interpreted as a Groovy String (GString) so any non-empty value will be interpreted as true. The set.#from attribute is interpreted as a Groovy expression, so simply using from="false" instead of value="false" will get the desired result.
To see the generated Groovy code from an XML actions block you can write code that will cause an error and then the script will be logged, or you can change the log4j.xml file to turn on "debug" level logging for the XmlActions class (the latest log4j.xml file in the GitHub repository has an example of this). Looking at the Groovy code generated from the XML elements is a good way to track down issues when what is happening just doesn't make sense.

struts form and JSTL

How to access a form variable using JSTL ?
e.g.
<html:text property="abc" ... />
<c:out value="${abc}"/>
abc is always blank, even though I have value set by action sending to this page.
If you refer with ActionForm, you can retrieve the value. "abc" is one of the property of ActionForm(you created) which will be available in request scope as it has been set in ActionServlet during processing request.
So get the value like this, suppose your ActionForm is 'TestForm', then retrieve as ${TestForm.abc} or <c:out value="${TestForm.abc}"/>

How to display data in a textarea using struts application

How do you display data in a 'textarea' using struts application,
This is my code:
<html:textarea property="comments" </html:textarea>
<bean:write name="FormBean" property="comments"/>
where FormBean is my beanclass and comment is a property in beanclass.
But I cannot get it too work.
Thanks in advance for your help.
If you use Struts action forms and you have the html:textarea tag inside your html:form tag (this tag is only valid when nested inside a form tag body) then the following code is all you need:
<html:textarea property="comments" />
Don't know what you are trying to do with bean:write but if you want to display that inside your html:textarea I'm not sure you can. The property attribute is mandatory for the html:textarea tag and will use that as the content.