struts.ui.theme disables the label of s:select - struts2

I am using struts.ui.theme = simple and it appears to disable the label attribute of s:select tag.
Is there any way to use the struts theme without disabling the label attribute?

For perticular page try this
<s:set name="theme" value="'simple'" scope="page" />

You can use theme for that particular element.
<s:select theme="xhtml" .../>

Related

How to set maxlength for <s:textarea> tag in Struts2?

I am developing an application using Struts2 and jquery and would like to set maxlength for struts2 s:textarea tag. Unlike Struts2 s:textfield, the s:textarea tag does not seem to be supporting maxlength attribute. Any help/guidance will be appreciated.
Use it, this must work:-
<s:textarea name="someName" maxlength="100" class="form-control" rows="5"></s:textarea>
maxlength works with textarea in struts2
here, rows indicates default height of textarea i.e equal to 5 rows. if characters are more, it shows vertical-scroll bar on it.
Since <s:textarea/> is one of those Struts UI Tags that allow dynamic attributes, your problem turns into:
How to set maxlength for <textarea> tag in HTML?
And the solution is: use Javascript, checking the length during key / mouse events.
You can find a kick off example here.
try this
<s:textfield maxlength="300">
</s:textfield>
Okay. When you want to set the size of the textarea in struts2 follow bellow patter it may work
<s:textarea cols="5" rows="6"></s:textarea>
define size of it as you wish.

Struts 2 text box arrangment

I want to create a form that contains text boxes as follow. I am using Struts2.
User Name
|Text Box for user name|
mail id
|Text box for mail id|
<s:textarea name="username" id="username" label="User Name"/>
This is showing:
User name |Text Box for user name|
But I want the above format. When I am using validation framework label is shown in italic, I want normal text.
That is because of default struts2 theme factor xhtml which is showing the output html in table structure
Change the theme to simple ans use your own css/HTML way to customize the output
crate a struts.properties file and add the following entry
struts.ui.theme=simple
this will change the theme for whole application as struts2 tags will no longer generates HTML/table code for you
else u can override the theme per page basis
like
<s:set name="theme" value="'simple'" scope="page" />
alternate way can be what "Steven" suggested
You're in luck. Just add the labelposition="top" attribute to your Struts2 input tags. e.g.,
<s:textfield name="subject"
label="Subject"
size="30"
maxlength="50"
labelposition="top"
required="true"/>
As for the italic label, that should be controlled by CSS.

How to set SelectManyCheckbox title dynamically JSF2

Is there any way to set selectManyCheckbox title dynamically ? In title I want to show Item name .
<h:selectManyCheckbox id="sType" value="#{studentBean.optionalsubjects}" converter="subjectConverter" required="true">
<f:selectItems value="#{subjectBean.oplist}" var="sType" itemLabel="#{sType.detail}" itemDescription="#{sType.detail}" />
</h:selectManyCheckbox>
I think this won't work with h:selectManyCheckbox since the title attribute is the same for all select items.
You could try javascript like the jquery tooltip plugin in order to attach tooltips on client side.

struts 2 text tag with dynamic expression , how?

I need to supply the key dynamically from the action to the text tag
<s:text name="<%=talkToUsInfo.messageKey%>" />
but the name attribute on text tag is declared as false ( not sure why ? )
How do i get something like this working without changing the tld in the jar file ?
Take a look at OGNL
It might look like this
<s:text name="%{talkToUsInfo.messageKey}" />
Struts documentation says:
Instead, you should use the getText() method that you inherit when your Action extends XWork's ActionSupport:
<s:textfield name="lastName" label="getText('person.lastName')" />
So I used e.g.
<s:property value="getText('status' + #someObject.currentStatus)" />
instead of "s:text" and it worked.
I prefer to use OGNL and s:text and do not make a call to getText manually.
You usually define a fixed prefix while add the dynamic part to it, so some thing like this could be used:
<s:text name="%{'student.types.'+currencyType}" />
The only time which I used getText inside the s:property was something like this (which needs some if/else if you wanted to use s:text ):
<s:property value="shouldCancelIt.equals(\"0\") ?
getText('label.yes'):getText('label.no')" />

Preselect radio button in Struts2

Using Struts2, I have a very simple radio tag like following
<s:radio label="correctOption" name="correctAnswer" list="
#{'1':'1','2':'2','3':'3','4':'4'}" value="questionVo.correctAnswer"/>
questionVo.correctAnswer returns 2. So I want the second radio button to be preselected but it is not happening. I even tried:
<s:radio label="correctOption" name="correctAnswer" list="
#{'1':'1','2':'2','3':'3','4':'4'}" value="%{1}"/>
But that does not work either.
What am I doing wrong?
Remove the value attribute from the jsp. Then in your Java code make sure that the "correctAnswer" variable has the value you want.
This has also the added effect that works in postbacks (when the user has selected something
on the radio and the form is shown again)
It works for me for the following:
<s:radio
label="correctOption"
name="correctAnswer"
list="#{'1':'1','2':'2','3':'3','4':'4'}"
value="%{1}"/>
I believe that the issue is that the value needs to be escaped properly eg:
value="%{'1'}"
and match the declaration exactly.
Here's the solution:
<s:radio label="correctOption" name="correctAnswer" list="
#{'1':'1','2':'2','3':'3','4':'4'}" value="1"/>
another one in case of strings in the static list:
<s:radio label="Gender" name="gender" list="
#{'male':'Male','female':'Female'}" value="'male'"/>

Resources