Adding name and id properties to textarea (struts) - java

i mostly do CSS and php so i'm kind'a lost here, so no idea if this is possible the way i want it anyway, this is it:
I have this code
<html:textarea rows="10" cols="70" property="thankYouMessage" />
And i want this textarea to render an id of "textareaID" and a name like "textareaname"
how can i go about this?... if i use styleID, the page just won't load anymore... i need to apply some css to that markup so that's the thing.
Thanks in advance!

styleId attribute should work (perhaps you mispelled it ? case is sensitive)
<html:textarea styleId="textareaID" property="thankYouMessage" ... />
IIRC (long time since Struts 1...) the generated name atribute in the HTML tag will coincide with the property attribute (ref). So in your example the generated HTML (you should check this, looking at the HTML source) should result in something like this:
<textarea id="textareaID" name="thankYouMessage" ...>
Normally you should'nt rely on name for accessing the element (e.g., in Javascript), prefer the id

Related

Set several tag attributes at once using a variable in Thymeleaf

I am migrating some JSP files to Thymeleaf and I have found the following problem. In the original JSP code there is a file that is included in lots of other JSP files that has a line like the following:
<c:set var="myVar" value="data-x=50 data-y=37" />
In the files which include this one the variable myVar is used like this:
<div class="myClass" ${myVar}>
setting several attributes that are used everywhere all at once. The main point here is that you set up myVar in one file and its values are used in all other files. If you need to change the value of the attributes you only need to change one file.
Trying to replicate this in Thymeleaf, I tried using the th:attr attribute in the following way. First, I set a variable in the model like this:
model.addAttribute("myVar", "data-x=50, data-y=37");
and then in Thymeleaf I do:
<div class="myClass" th:attr="${myVar}" >
but it does not work, it throws
TemplateProcessingException: Could not parse as assignation sequence: "${myVar}"
I've also have thought of using Javascript to add the attributes dynamically using JQuery, but I would prefer to do it in other way, since I did not built the application, it has a lot of scripting and I fear doing it through Javascript can have side effects.
Is there any way I can write directly in the HTML output using Thymeleaf?
One way you can accomplish this with preprocessing. Something like this will work with your example:
<div class="myClass" th:attr="__${myVar}__" />
(This does rely on ${myVar} being a valid string for the th:attr property, so you'll have to be careful with it.)

Are there any larger data types for strings in Alfresco?

I'm working with a custom content model and I want to have a custom text field that serves the purpose of a description for the document. I've run into a problem with this field, because it seems I can't have a d:text property with more than 1024 characters.
Is there another property type that allows me to go over this limit? I'm using the content model to describe PDF documents, and these do not always have OCR performed on them, so I need the description field to make them searchable by Alfresco.
d:text length depends on your database table. So try to increase that and you should be fine.
It is very simple, to set a bigger limit, than 1024 characters, to a attribute which is from the type "d:text". You must modify the file custom-config-model.xml which you can find in folder ALFRESCO_HOME/tomcat/shared/classes/alfresco/web-extensions.
In the config from your node-type you must write something like in the following example:
<config evaluator="node-type" condition="your:model">
<forms>
<form>
<field-visibility>
...
<show id="your:attribute" />
...
</field-visibility>
<appearance>
...
<field id="your:attribute">
<control template="/org/alfresco/components/form/controls/textarea.ftl">
<control-param name="maxLength">40000</control-param>
</control>
</field>
...
</appearance>
</form>
</forms>
</config>
The fist thing you do with that code is:
You show the attribute
You make the textfield to a template which is called textarea (much better for a text or something)
you set the maximal length of the attribute to 40.000 characters (which should be enough)
If you don't want the textfield as textarea delete the template attribute from the control section.
After this manipulation you can save strings with up to 40.000 characters in this attribute.
Hope I could help you!

How to pass output of an <s:action> to a <s:url> value parameter in a JSP view?

I haven't touched Struts2 in a couple of years and have to do some maintenance on some JSP pages. But I can't figure out the proper syntax to pass the output from an <s:Action> tag to an <s:url> tag.
I'd like to do the following:
<s:action name="loadPath" namespace="/files" flush="false" var="filePath" />
<s:url value="#filePath.path"/>
But that does not work. However, I can see that my path property is properly set by doing:
<s:property value="#filePath.path" />
I've played around with %, # and $, but can't seem to find the right combination to get the value off the stack and into the s:url tag.
AHA!
After some more digging around, and trial and error, I finally found the right combination:
<s:url value="%{ #filePath.path }"/>
But I do not understand why this works. Can anyone provide an explanation why this syntax works and not just value="#filePath.path"?
I am not quite sure about what you are trying to achieve but perhaps these documents will help you:
Struts2 Action Tag Example
Struts2 URL Tag Example

html:text how to set placeholder attribute

I mostly do HTML/CSS/JS so i'm kind'a lost here, so no idea if this is possible the way i want it anyway, this is it:
I have this code
<html:text styleClass="span4" title="No spaces or dashes" />
I want this input to render with the attribute "placeholder". How can i go about this?
Thanks in advance!
If struts doesn't provide then you could inject it using jQuery if you need it
$("#idOfInputText").attr('placeholder', 'some text')
you can supply id using styleId attribute of struts's tag

In JSP, what do the path and value attribute do within the input tag, and how does the form prefix affect them?

Just wanted a clear answer for a direct question -- google results have been all over the place or don't address the combos you'll see below.
I'm generally a JSP newbie and have been screwing around with the following code.
<form:input id="theId" path="path.copied.directly.fromSomewhereElse"
cssClass="contentTextInput" cssStyle="width: 229px" />
When I put that into my JSP page and load my website, it works fine and looks as my cssClass defines it. Then I start messing with it because I want it to display a default value.
<form:input id="theId" path="path.copied.directly.fromSomewhereElse"
value="blah" cssClass="contentTextInput" cssStyle="width: 229px" />
Suddenly, HTTP 500, an org.apache.jasper.JasperException! So I decide to remove the path altogether, while leaving in the value. This is just step 1 in something I know works because of prior experience. The code is now:
<form:input id="theId" value="someClass.valueIWantAsDefault"
cssClass="contentTextInput" cssStyle="width: 229px" />
That actually throws an exception, too -- but then I remove the form prefix and it works-- mostly. You see, the cssClass's effects are now gone; it looks like a regular, unaffected input textbox. Here's the code so far.
<input id="theId" value="someClass.valueIWantAsDefault"
cssClass="contentTextInput" cssStyle="width: 229px" />
What exactly do these attributes (and prefix) do that makes this mix-and-match work?
I'm guessing you're dealing with a jsp page that relies on a JSP custom tag library that's part of the Spring Framework. Here are the docs for the <form:input> tag. value is not a valid attribute for this custom tag as you can see in the docs link I provided above. When you remove the form:, you're turning the tag into a plain old HTML <input> tag which is why your error is going away at that point. It's also why your css stops working. cssClass is not the correct attribute for the HTML <input> tag. It's simply class. They called it cssClass in the jsp custom tag lib most likely to avoid a lower level collision with the Object.getClass() method (long story, just take my word for it).

Categories

Resources